distance is now optional in 'near' search (defaults to 1m)

This commit is contained in:
Christian Quest 2016-05-09 16:11:17 +02:00
parent a2125a74ba
commit 08bee9d947
2 changed files with 6 additions and 2 deletions

View file

@ -77,7 +77,11 @@ class EventResource(object):
event_dist = ""
elif 'near' in req.params:
# limit search with location+distance (long, lat, distance in meters)
event_bbox = cur.mogrify(" AND ST_Intersects(geom, ST_Buffer(st_setsrid(st_makepoint(%s,%s),4326)::geography,%s)::geometry) ",tuple(req.params['near'])).decode("utf-8")
if len(req.params['near'])<3:
dist = 1
else:
dist = req.params['near'][2]
event_bbox = cur.mogrify(" AND ST_Intersects(geom, ST_Buffer(st_setsrid(st_makepoint(%s,%s),4326)::geography,%s)::geometry) ",(req.params['near'][0], req.params['near'][1], dist)).decode("utf-8")
event_dist = cur.mogrify(", 'distance', ST_Length(ST_ShortestLine(geom, st_setsrid(st_makepoint(%s,%s),4326))::geography) ",(req.params['near'][0], req.params['near'][1])).decode("utf-8")
else:
event_bbox = ""

View file

@ -84,7 +84,7 @@
{
"name": "near",
"in": "query",
"description": "Event search by distance (long, lat, distance in meters)",
"description": "Event search by distance (long, lat, optional distance in meters)",
"required": false,
"type": "string",
"x-example": "2.5,48.8,500"