From 2a47000f320e089afe19dcca97729a8cd97dc34b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Ignacio=20S=C3=A1nchez=20Lara?= Date: Fri, 23 Mar 2018 12:46:51 +0100 Subject: [PATCH] coordinates_to_polygon should always return multipolygon to avoid inconsistencies --- server/extension/sql/80_isolines_helper.sql | 2 +- .../python/cartodb_services/cartodb_services/mapzen/types.py | 2 +- .../cartodb_services/cartodb_services/tools/coordinates.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/server/extension/sql/80_isolines_helper.sql b/server/extension/sql/80_isolines_helper.sql index e8043fe..953be10 100644 --- a/server/extension/sql/80_isolines_helper.sql +++ b/server/extension/sql/80_isolines_helper.sql @@ -169,7 +169,7 @@ RETURNS SETOF cdb_dataservices_server.isoline AS $$ # -- TODO encapsulate this block into a func/method locations = isolines[r] + [ isolines[r][0] ] # close the polygon repeating the first point wkt_coordinates = ','.join(["%f %f" % (l.longitude, l.latitude) for l in locations]) - sql = "SELECT ST_CollectionExtract(ST_MakeValid(ST_MPolyFromText('MULTIPOLYGON((({0})))', 4326)),3) as geom".format(wkt_coordinates) + sql = "SELECT st_multi(ST_CollectionExtract(ST_MakeValid(ST_MPolyFromText('MULTIPOLYGON((({0})))', 4326)),3)) as geom".format(wkt_coordinates) multipolygon = plpy.execute(sql, 1)[0]['geom'] else: multipolygon = None diff --git a/server/lib/python/cartodb_services/cartodb_services/mapzen/types.py b/server/lib/python/cartodb_services/cartodb_services/mapzen/types.py index 986eb91..f5ad462 100644 --- a/server/lib/python/cartodb_services/cartodb_services/mapzen/types.py +++ b/server/lib/python/cartodb_services/cartodb_services/mapzen/types.py @@ -28,7 +28,7 @@ def coordinates_to_polygon(coordinates): wkt_coordinates = ','.join(result_coordinates) try: - sql = "SELECT ST_CollectionExtract(ST_MakeValid(ST_MakePolygon(ST_GeomFromText('LINESTRING({0})', 4326))),3) as geom".format(wkt_coordinates) + sql = "SELECT st_multi(ST_CollectionExtract(ST_MakeValid(ST_MakePolygon(ST_GeomFromText('LINESTRING({0})', 4326))),3)) as geom".format(wkt_coordinates) geometry = plpy.execute(sql, 1)[0]['geom'] except BaseException as e: plpy.warning("Can't generate POLYGON from coordinates: {0}".format(e)) diff --git a/server/lib/python/cartodb_services/cartodb_services/tools/coordinates.py b/server/lib/python/cartodb_services/cartodb_services/tools/coordinates.py index b02e801..6688970 100644 --- a/server/lib/python/cartodb_services/cartodb_services/tools/coordinates.py +++ b/server/lib/python/cartodb_services/cartodb_services/tools/coordinates.py @@ -55,7 +55,7 @@ def coordinates_to_polygon(coordinates): wkt_coordinates = ','.join(result_coordinates) try: - sql = "SELECT ST_CollectionExtract(ST_MakeValid(ST_MakePolygon(ST_GeomFromText('LINESTRING({0})', 4326))),3) as geom".format(wkt_coordinates) + sql = "SELECT st_multi(ST_CollectionExtract(ST_MakeValid(ST_MakePolygon(ST_GeomFromText('LINESTRING({0})', 4326))),3)) as geom".format(wkt_coordinates) geometry = plpy.execute(sql, 1)[0]['geom'] except BaseException as e: plpy.warning("Can't generate POLYGON from coordinates: {0}".format(e))