How can I leverage Geo Queries provided by the PostGIS extension in the typesystem?

#1

I want to query and return data based on euclidian 2D distance:

  1. what types are required to use this functionality,
  2. Can you provide some example usage?
  3. What DB engine functions can I use to operate on this data?
0 Likes

#2
  1. You need to use types that mixin Geo, find them with Geo.mixersIn()

  2. Example usage
    Type Def

entity type TestTypeWithGeogCoords schema name 'TTWGEO' { 
  address1 : string 
  geog1 : GeoPoint 
  address2 : string 
  geog2 : GeoPoint 
} 

Usage:

// 2 Geom fields within 200 feet 
TestTypeWithGeoCoords.fetch({filter : "withinDistance(geog1, geog2, 200 * .3048)"}); 

// Distance between 2 geom fields <= 200 feet 
TestTypeWithGeoCoords.fetch({filter : "distance(geog1, geog2) <= 200 * .3048"}); 

// 2 Geom fields within 2000 miles 
TestTypeWithGeoCoords.fetch({filter : "withinDistance(geog1, geog2, 2000 * 1609)"}); 

// Distance between 2 geom fields <= 2000 miles 
TestTypeWithGeoCoords.fetch({filter : "distance(geog1, geog2) <= 2000 * 1609"}); 

// 2 Geom fields within 3500 miles 
TestTypeWithGeoCoords.fetch({filter : "withinDistance(geog1, geog2, 3500 * 1609)"}); 

// Distance between 2 geom fields <= 3500 miles 
TestTypeWithGeoCoords.fetch({filter : "distance(geog1, geog2) <= 3500 * 1609"}); 

// Geom field and geomFromText() within 3500 
TestTypeWithGeoCoords.fetch({filter : "withinDistance(geog2, geogFromText('point(-121.9028091 37.2228127)'), 2000 * 1609)))"}); 

// Geom field and makePoint() within 3500 miles (note transformGeom and conversion of meters to miles) 
TestTypeWithGeoCoords.fetch({filter : "withinDistance(geog2, makePoint(-121.9028091, 37.2228127), 2000 * 1609)"}); 

// Geom field within 100 miles of LineString using makePoint/makeLineString 
TestTypeWithGeoCoords.fetch({filter : "withinDistance(geog2, makeLineString([makePoint(-121.9028091, 37.2228127), makePoint(-75.1326523, 40.1984825)]), 100 * 1609)"}); 

// Geom field within 1000 miles of LineString using makePoint/makeLineString 
TestTypeWithGeoCoords.fetch({filter : "withinDistance(geog2, makeLineString([makePoint(-121.9028091, 37.2228127), makePoint(-75.1326523, 40.1984825)]), 1000 * 1609)"}); 

// Geom field within 100 miles of LineString using geomFromText 
TestTypeWithGeoCoords.fetch({filter : "withinDistance(geog2, geogFromText('linestring(-121.9028091 37.2228127, -75.1326523 40.1984825)'), 100 * 1609)"});
  1. See above
  • withinDistance
  • distance
  • anything else @trothwein?
0 Likes