bytes to string after morgrify
This commit is contained in:
parent
304250fa7c
commit
bdb1a9d3dc
1 changed files with 7 additions and 6 deletions
13
backend.py
13
backend.py
|
@ -59,34 +59,35 @@ class EventResource(object):
|
|||
|
||||
if 'bbox' in req.params:
|
||||
# limit search with bbox (E,S,W,N)
|
||||
event_bbox = str(cur.mogrify(" AND geom && ST_SetSRID(ST_MakeBox2D(ST_Point(%s,%s),ST_Point(%s,%s)),4326) ",tuple(req.params['bbox'])))
|
||||
event_bbox = str(cur.mogrify(" AND geom && ST_SetSRID(ST_MakeBox2D(ST_Point(%s,%s),ST_Point(%s,%s)),4326) ",tuple(req.params['bbox']))).decode("utf-8")
|
||||
elif 'near' in req.params:
|
||||
# limit search with location+distance (long, lat, distance in meters)
|
||||
event_bbox = str(cur.mogrify(" AND geom && st_expand(st_buffer(st_setsrid(st_makepoint(%s,%s),4326)::geography,%s)::geometry,0) ",tuple(req.params['near'])))
|
||||
event_bbox = str(cur.mogrify(" AND geom && st_expand(st_buffer(st_setsrid(st_makepoint(%s,%s),4326)::geography,%s)::geometry,0) ",tuple(req.params['near']))).decode("utf-8")
|
||||
else:
|
||||
event_bbox = ""
|
||||
|
||||
if 'when' in req.params:
|
||||
# limit search with fixed time
|
||||
event_when = str(cur.mogrify("tstzrange(%s,%s,'[]')",(req.params['when'],req.params['when'])))
|
||||
event_when = cur.mogrify("tstzrange(%s,%s,'[]')",(req.params['when'],req.params['when'])).decode("utf-8")
|
||||
elif 'start' in req.params and 'stop' in req.params:
|
||||
# limit search with fixed time
|
||||
event_when = str(cur.mogrify("tstzrange(%s,%s,'[]')",(req.params['start'],req.params['stop'])))
|
||||
event_when = cur.mogrify("tstzrange(%s,%s,'[]')",(req.params['start'],req.params['stop'])).decode("utf-8")
|
||||
else:
|
||||
event_when = """tstzrange(now(),now(),'[]')"""
|
||||
|
||||
if 'what' in req.params:
|
||||
# limit search based on "what"
|
||||
event_what = str(cur.mogrify(" AND events_what LIKE %s ",(req.params['what']+"%",)))
|
||||
event_what = cur.mogrify(" AND events_what LIKE %s ",(req.params['what']+"%",)).decode("utf-8")
|
||||
else:
|
||||
event_what = ""
|
||||
|
||||
if 'type' in req.params:
|
||||
# limit search based on type (scheduled, forecast, unscheduled)
|
||||
event_type = cur.mogrify(" AND events_type = %s ",(req.params['type'],))
|
||||
event_type = cur.mogrify(" AND events_type = %s ",(req.params['type'],)).decode("utf-8")
|
||||
else:
|
||||
event_type = ""
|
||||
|
||||
print(event_when + event_what + event_type)
|
||||
# search recent active events
|
||||
cur.execute("""
|
||||
SELECT '{"type":"Feature", "properties": '|| (events_tags::jsonb || jsonb_build_object('id',events_id,'createdate',createdate,'lastupdate',lastupdate))::text ||', "geometry":'|| st_asgeojson(st_centroid(geom)) ||' }' as feature
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue