Convert to multipolygon and return isolines

This commit is contained in:
Rafa de la Torre
2016-07-06 13:18:54 +02:00
parent 6810dc0ff0
commit eb906fae35
+16 -18
View File
@@ -79,7 +79,7 @@ RETURNS SETOF cdb_dataservices_server.isoline AS $$
# plpy.error('You have reached the limit of your quota') # plpy.error('You have reached the limit of your quota')
try: try:
# TODO: encapsulate or refactor this ugly code # --TODO: encapsulate or refactor this ugly code
mapzen_conf_str = plpy.execute("SELECT * FROM CDB_Conf_Getconf('mapzen_conf') AS mapzen_conf")[0]['mapzen_conf'] mapzen_conf_str = plpy.execute("SELECT * FROM CDB_Conf_Getconf('mapzen_conf') AS mapzen_conf")[0]['mapzen_conf']
mapzen_conf = json.loads(mapzen_conf_str) mapzen_conf = json.loads(mapzen_conf_str)
@@ -95,7 +95,7 @@ RETURNS SETOF cdb_dataservices_server.isoline AS $$
raise Exception('source is NULL') raise Exception('source is NULL')
# -- TODO Support options properly # -- TODO Support options properly
isolines = [] isolines = {}
if isotype == 'isodistance': if isotype == 'isodistance':
# -- TODO implement # -- TODO implement
raise 'not implemented' raise 'not implemented'
@@ -103,24 +103,22 @@ RETURNS SETOF cdb_dataservices_server.isoline AS $$
elif isotype == 'isochrone': elif isotype == 'isochrone':
for r in data_range: for r in data_range:
isoline = mapzen_isolines.calculate_isochrone(origin, mode, r) isoline = mapzen_isolines.calculate_isochrone(origin, mode, r)
isolines.append(isoline) isolines[r] = (isoline)
return [] # -- TODO delete this result = []
for r in data_range:
# -- TODO rewrite this block # -- TODO encapsulate this block into a func/method
if isolines: locations = isolines[r] + [ isolines[r][0] ] # close the polygon repeating the first point
result = [] wkt_coordinates = ','.join(["%f %f" % (l['lon'], l['lat']) for l in locations])
for isoline in isolines: sql = "SELECT ST_MPolyFromText('MULTIPOLYGON((({0})))', 4326) as geom".format(wkt_coordinates)
data_range_n = isoline['range'] multipolygon = plpy.execute(sql, 1)[0]['geom']
polyline = isoline['geom']
multipolygon = geo_polyline_to_multipolygon(polyline) result.append([source, r, multipolygon])
result.append([source, data_range_n, multipolygon]) # --TODO take care of this quota/usage stuff
#quota_service.increment_success_service_use() #quota_service.increment_success_service_use()
#quota_service.increment_isolines_service_use(len(resp)) #quota_service.increment_isolines_service_use(len(resp))
return result return result
else:
#quota_service.increment_empty_service_use()
return []
except BaseException as e: except BaseException as e:
import sys, traceback import sys, traceback
type_, value_, traceback_ = sys.exc_info() type_, value_, traceback_ = sys.exc_info()