diff --git a/server/extension/cdb_dataservices_server--0.13.1--0.13.2.sql b/server/extension/cdb_dataservices_server--0.13.1--0.13.2.sql new file mode 100644 index 0000000..2c8a874 --- /dev/null +++ b/server/extension/cdb_dataservices_server--0.13.1--0.13.2.sql @@ -0,0 +1,37 @@ +--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES +-- Complain if script is sourced in psql, rather than via CREATE EXTENSION +\echo Use "ALTER EXTENSION cdb_dataservices_server UPDATE TO '0.13.2'" to load this file. \quit + +-- HERE goes your code to upgrade/downgrade +CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_isodistance(username TEXT, orgname TEXT, source geometry(Geometry, 4326), mode TEXT, range integer[], options text[] DEFAULT array[]::text[]) +RETURNS SETOF cdb_dataservices_server.isoline AS $$ + plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username)) + redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection'] + plpy.execute("SELECT cdb_dataservices_server._get_isolines_routing_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname))) + user_isolines_config = GD["user_isolines_routing_config_{0}".format(username)] + type = 'isodistance' + + if user_isolines_config.google_services_user: + plpy.error('This service is not available for google service users.') + + here_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_here_routing_isolines($1, $2, $3, $4, $5, $6, $7) as isoline; ", ["text", "text", "text", "geometry(Geometry, 4326)", "text", "integer[]", "text[]"]) + result = plpy.execute(here_plan, [username, orgname, type, source, mode, range, options]) + + return result +$$ LANGUAGE plpythonu; + +CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_isochrone(username TEXT, orgname TEXT, source geometry(Geometry, 4326), mode TEXT, range integer[], options text[] DEFAULT array[]::text[]) +RETURNS SETOF cdb_dataservices_server.isoline AS $$ + plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username)) + redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection'] + plpy.execute("SELECT cdb_dataservices_server._get_isolines_routing_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname))) + user_isolines_config = GD["user_isolines_routing_config_{0}".format(username)] + type = 'isochrone' + + if user_isolines_config.google_services_user: + plpy.error('This service is not available for google service users.') + + here_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_here_routing_isolines($1, $2, $3, $4, $5, $6, $7) as isoline; ", ["text", "text", "text", "geometry(Geometry, 4326)", "text", "integer[]", "text[]"]) + result = plpy.execute(here_plan, [username, orgname, type, source, mode, range, options]) + return result +$$ LANGUAGE plpythonu; \ No newline at end of file diff --git a/server/extension/cdb_dataservices_server--0.13.2--0.13.1.sql b/server/extension/cdb_dataservices_server--0.13.2--0.13.1.sql new file mode 100644 index 0000000..6e45169 --- /dev/null +++ b/server/extension/cdb_dataservices_server--0.13.2--0.13.1.sql @@ -0,0 +1,48 @@ +--DO NOT MODIFY THIS FILE, IT IS GENERATED AUTOMATICALLY FROM SOURCES +-- Complain if script is sourced in psql, rather than via CREATE EXTENSION +\echo Use "ALTER EXTENSION cdb_dataservices_server UPDATE TO '0.13.1'" to load this file. \quit + +-- HERE goes your code to upgrade/downgrade +CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_isodistance(username TEXT, orgname TEXT, source geometry(Geometry, 4326), mode TEXT, range integer[], options text[] DEFAULT array[]::text[]) +RETURNS SETOF cdb_dataservices_server.isoline AS $$ + plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username)) + redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection'] + plpy.execute("SELECT cdb_dataservices_server._get_isolines_routing_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname))) + user_isolines_config = GD["user_isolines_routing_config_{0}".format(username)] + type = 'isodistance' + + if user_isolines_config.google_services_user: + plpy.error('This service is not available for google service users.') + + here_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_here_routing_isolines($1, $2, $3, $4, $5, $6, $7) as isoline; ", ["text", "text", "text", "geometry(Geometry, 4326)", "text", "integer[]", "text[]"]) + result = plpy.execute(here_plan, [username, orgname, type, source, mode, range, options]) + isolines = [] + for element in result: + isoline = element['isoline'] + isoline = isoline.translate(None, "()").split(',') + isolines.append(isoline) + + return isolines +$$ LANGUAGE plpythonu; + +CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_isochrone(username TEXT, orgname TEXT, source geometry(Geometry, 4326), mode TEXT, range integer[], options text[] DEFAULT array[]::text[]) +RETURNS SETOF cdb_dataservices_server.isoline AS $$ + plpy.execute("SELECT cdb_dataservices_server._connect_to_redis('{0}')".format(username)) + redis_conn = GD["redis_connection_{0}".format(username)]['redis_metrics_connection'] + plpy.execute("SELECT cdb_dataservices_server._get_isolines_routing_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname))) + user_isolines_config = GD["user_isolines_routing_config_{0}".format(username)] + type = 'isochrone' + + if user_isolines_config.google_services_user: + plpy.error('This service is not available for google service users.') + + here_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_here_routing_isolines($1, $2, $3, $4, $5, $6, $7) as isoline; ", ["text", "text", "text", "geometry(Geometry, 4326)", "text", "integer[]", "text[]"]) + result = plpy.execute(here_plan, [username, orgname, type, source, mode, range, options]) + isolines = [] + for element in result: + isoline = element['isoline'] + isoline = isoline.translate(None, "()").split(',') + isolines.append(isoline) + + return isolines +$$ LANGUAGE plpythonu; \ No newline at end of file diff --git a/server/extension/cdb_dataservices_server.control b/server/extension/cdb_dataservices_server.control index bfc3498..a390bba 100644 --- a/server/extension/cdb_dataservices_server.control +++ b/server/extension/cdb_dataservices_server.control @@ -1,5 +1,5 @@ comment = 'CartoDB dataservices server extension' -default_version = '0.13.1' +default_version = '0.13.2' requires = 'plpythonu, plproxy, postgis, cdb_geocoder' superuser = true schema = cdb_dataservices_server diff --git a/server/extension/cdb_dataservices_server--0.13.0--0.13.1.sql b/server/extension/old_versions/cdb_dataservices_server--0.13.0--0.13.1.sql similarity index 100% rename from server/extension/cdb_dataservices_server--0.13.0--0.13.1.sql rename to server/extension/old_versions/cdb_dataservices_server--0.13.0--0.13.1.sql diff --git a/server/extension/cdb_dataservices_server--0.13.1--0.13.0.sql b/server/extension/old_versions/cdb_dataservices_server--0.13.1--0.13.0.sql similarity index 100% rename from server/extension/cdb_dataservices_server--0.13.1--0.13.0.sql rename to server/extension/old_versions/cdb_dataservices_server--0.13.1--0.13.0.sql diff --git a/server/extension/cdb_dataservices_server--0.13.1.sql b/server/extension/old_versions/cdb_dataservices_server--0.13.1.sql similarity index 100% rename from server/extension/cdb_dataservices_server--0.13.1.sql rename to server/extension/old_versions/cdb_dataservices_server--0.13.1.sql diff --git a/server/extension/sql/85_isodistance.sql b/server/extension/sql/85_isodistance.sql index ea5ab59..15dd9f4 100644 --- a/server/extension/sql/85_isodistance.sql +++ b/server/extension/sql/85_isodistance.sql @@ -9,15 +9,10 @@ RETURNS SETOF cdb_dataservices_server.isoline AS $$ if user_isolines_config.google_services_user: plpy.error('This service is not available for google service users.') - here_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_here_routing_isolines($1, $2, $3, $4, $5, $6, $7) as isoline; ", ["text", "text", "text", "geometry(Geometry, 4326)", "text", "integer[]", "text[]"]) + here_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_here_routing_isolines($1, $2, $3, $4, $5, $6, $7) as isoline; ", ["text", "text", "text", "geometry(Geometry, 4326)", "text", "integer[]", "text[]"]) result = plpy.execute(here_plan, [username, orgname, type, source, mode, range, options]) - isolines = [] - for element in result: - isoline = element['isoline'] - isoline = isoline.translate(None, "()").split(',') - isolines.append(isoline) - return isolines + return result $$ LANGUAGE plpythonu; -- mapzen isodistance diff --git a/server/extension/sql/90_isochrone.sql b/server/extension/sql/90_isochrone.sql index 1cb5738..d4c78d4 100644 --- a/server/extension/sql/90_isochrone.sql +++ b/server/extension/sql/90_isochrone.sql @@ -9,15 +9,9 @@ RETURNS SETOF cdb_dataservices_server.isoline AS $$ if user_isolines_config.google_services_user: plpy.error('This service is not available for google service users.') - here_plan = plpy.prepare("SELECT cdb_dataservices_server._cdb_here_routing_isolines($1, $2, $3, $4, $5, $6, $7) as isoline; ", ["text", "text", "text", "geometry(Geometry, 4326)", "text", "integer[]", "text[]"]) + here_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_here_routing_isolines($1, $2, $3, $4, $5, $6, $7) as isoline; ", ["text", "text", "text", "geometry(Geometry, 4326)", "text", "integer[]", "text[]"]) result = plpy.execute(here_plan, [username, orgname, type, source, mode, range, options]) - isolines = [] - for element in result: - isoline = element['isoline'] - isoline = isoline.translate(None, "()").split(',') - isolines.append(isoline) - - return isolines + return result $$ LANGUAGE plpythonu; diff --git a/server/lib/python/cartodb_services/cartodb_services/here/routing.py b/server/lib/python/cartodb_services/cartodb_services/here/routing.py index 63623b2..71d9cc9 100644 --- a/server/lib/python/cartodb_services/cartodb_services/here/routing.py +++ b/server/lib/python/cartodb_services/cartodb_services/here/routing.py @@ -77,8 +77,12 @@ class HereMapsRoutingIsoline: isolines_response = parsed_response['response']['isoline'] isolines = [] for isoline in isolines_response: + if not isoline['component']: + geom_value = [] + else: + geom_value = isoline['component'][0]['shape'] isolines.append({'range': isoline['range'], - 'geom': isoline['component'][0]['shape']}) + 'geom': geom_value}) return isolines diff --git a/server/lib/python/cartodb_services/cartodb_services/here/types.py b/server/lib/python/cartodb_services/cartodb_services/here/types.py index 90e1d9e..fa7f612 100644 --- a/server/lib/python/cartodb_services/cartodb_services/here/types.py +++ b/server/lib/python/cartodb_services/cartodb_services/here/types.py @@ -4,13 +4,18 @@ import plpy def geo_polyline_to_multipolygon(polyline): """Convert a HERE polyline shape to a PostGIS multipolygon""" - coordinates = [] - for point in polyline: - lat, lon = point.split(',') - coordinates.append("%s %s" % (lon, lat)) - wkt_coordinates = ','.join(coordinates) + # In case we receive an empty polyline from here and we don't want to + # change this kind of thing in the extension sql + if not polyline: + sql = "SELECT ST_MPolyFromText(NULL, 4326) as geom" + else: + coordinates = [] + for point in polyline: + lat, lon = point.split(',') + coordinates.append("%s %s" % (lon, lat)) + wkt_coordinates = ','.join(coordinates) + + sql = "SELECT ST_MPolyFromText('MULTIPOLYGON((({0})))', 4326) as geom".format(wkt_coordinates) - sql = "SELECT ST_MPolyFromText('MULTIPOLYGON((({0})))', 4326) as geom".format(wkt_coordinates) geometry = plpy.execute(sql, 1)[0]['geom'] - return geometry diff --git a/server/lib/python/cartodb_services/setup.py b/server/lib/python/cartodb_services/setup.py index a0a3f66..4834058 100644 --- a/server/lib/python/cartodb_services/setup.py +++ b/server/lib/python/cartodb_services/setup.py @@ -10,7 +10,7 @@ from setuptools import setup, find_packages setup( name='cartodb_services', - version='0.7.0', + version='0.7.1', description='CartoDB Services API Python Library',