Skip to content

Commit

Permalink
Merge pull request #511 from brianmckenna/m112_add_km_radius
Browse files Browse the repository at this point in the history
CIDEVSTC-99 - M112 - support search radius in meters
  • Loading branch information
Michael Meisinger committed May 21, 2014
2 parents b3debd2 + 16c4395 commit 5323efe
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pyon/datastore/postgresql/pg_query.py
Expand Up @@ -84,7 +84,13 @@ def _build_where(self, expr):
geom_from_wkt = 'ST_GeomFromEWKT(\'SRID=4326;%s\')' % (wkt)
# if buffer specified, wrap geometry in buffer http://postgis.net/docs/ST_Buffer.html
if buf:
geom_from_wkt = 'ST_Buffer(%s, %f)' % (geom_from_wkt,float(buf))
postgis_cast = '' # we may need to cast PostGIS geography back to PostGIS geometry
if isinstance(buf,str):
if buf.lower().endswith('m'):
geom_from_wkt = '%s::geography' % geom_from_wkt # in meters instead of CRS units
buf = buf[:-1] # remove trailing 'm'
postgis_cast = '::geometry' # must be converted to PostGIS geometry for search/comparison
geom_from_wkt = 'ST_Buffer(%s, %f)%s' % (geom_from_wkt,float(buf),postgis_cast)
return self.OP_STR[op] % (colname, geom_from_wkt)
else:
colname, x1, y1, x2, y2 = args
Expand Down

0 comments on commit 5323efe

Please sign in to comment.