From 9921f0f394a49d1faad797a8146eac242f2d1a1b Mon Sep 17 00:00:00 2001 From: Antonio Date: Tue, 16 Jan 2018 17:25:12 +0100 Subject: [PATCH] Added iso3166 import --- .../extension/cdb_dataservices_server--0.29.0--0.30.0.sql | 8 ++++---- server/extension/cdb_dataservices_server--0.30.0.sql | 8 ++++---- server/extension/sql/20_geocode_street.sql | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/server/extension/cdb_dataservices_server--0.29.0--0.30.0.sql b/server/extension/cdb_dataservices_server--0.29.0--0.30.0.sql index c1b3c3b..0fc7486 100644 --- a/server/extension/cdb_dataservices_server--0.29.0--0.30.0.sql +++ b/server/extension/cdb_dataservices_server--0.29.0--0.30.0.sql @@ -214,9 +214,9 @@ $$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_mapbox_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL) RETURNS Geometry AS $$ + from iso3166 import countries from cartodb_services.tools import ServiceManager from cartodb_services.mapbox import MapboxGeocoder - from cartodb_services.tools.country import country_to_iso3 from cartodb_services.refactor.service.mapbox_geocoder_config import MapboxGeocoderConfigBuilder import cartodb_services @@ -228,13 +228,13 @@ RETURNS Geometry AS $$ try: geocoder = MapboxGeocoder(service_manager.config.mapbox_api_key, service_manager.logger, service_manager.config.service_params) - country_iso3 = None + country_iso3166 = None if country: - country_iso3 = country_to_iso3(country) + country_iso3166 = countries.get(country).alpha2.lower() coordinates = geocoder.geocode(searchtext=searchtext, city=city, state_province=state_province, - country=country_iso3) + country=country_iso3166) if coordinates: service_manager.quota_service.increment_success_service_use() plan = plpy.prepare("SELECT ST_SetSRID(ST_MakePoint($1, $2), 4326); ", ["double precision", "double precision"]) diff --git a/server/extension/cdb_dataservices_server--0.30.0.sql b/server/extension/cdb_dataservices_server--0.30.0.sql index 5d58cda..4af7fd2 100644 --- a/server/extension/cdb_dataservices_server--0.30.0.sql +++ b/server/extension/cdb_dataservices_server--0.30.0.sql @@ -2056,9 +2056,9 @@ $$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_mapbox_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL) RETURNS Geometry AS $$ + from iso3166 import countries from cartodb_services.tools import ServiceManager from cartodb_services.mapbox import MapboxGeocoder - from cartodb_services.tools.country import country_to_iso3 from cartodb_services.refactor.service.mapbox_geocoder_config import MapboxGeocoderConfigBuilder import cartodb_services @@ -2070,13 +2070,13 @@ RETURNS Geometry AS $$ try: geocoder = MapboxGeocoder(service_manager.config.mapbox_api_key, service_manager.logger, service_manager.config.service_params) - country_iso3 = None + country_iso3166 = None if country: - country_iso3 = country_to_iso3(country) + country_iso3166 = countries.get(country).alpha2.lower() coordinates = geocoder.geocode(searchtext=searchtext, city=city, state_province=state_province, - country=country_iso3) + country=country_iso3166) if coordinates: service_manager.quota_service.increment_success_service_use() plan = plpy.prepare("SELECT ST_SetSRID(ST_MakePoint($1, $2), 4326); ", ["double precision", "double precision"]) diff --git a/server/extension/sql/20_geocode_street.sql b/server/extension/sql/20_geocode_street.sql index 8fa38c8..5ae7dd5 100644 --- a/server/extension/sql/20_geocode_street.sql +++ b/server/extension/sql/20_geocode_street.sql @@ -185,9 +185,9 @@ $$ LANGUAGE plpythonu STABLE PARALLEL RESTRICTED; CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_mapbox_geocode_street_point(username TEXT, orgname TEXT, searchtext TEXT, city TEXT DEFAULT NULL, state_province TEXT DEFAULT NULL, country TEXT DEFAULT NULL) RETURNS Geometry AS $$ + from iso3166 import countries from cartodb_services.tools import ServiceManager from cartodb_services.mapbox import MapboxGeocoder - from cartodb_services.tools.country import country_to_iso3 from cartodb_services.refactor.service.mapbox_geocoder_config import MapboxGeocoderConfigBuilder import cartodb_services @@ -199,13 +199,13 @@ RETURNS Geometry AS $$ try: geocoder = MapboxGeocoder(service_manager.config.mapbox_api_key, service_manager.logger, service_manager.config.service_params) - country_iso3 = None + country_iso3166 = None if country: - country_iso3 = country_to_iso3(country) + country_iso3166 = countries.get(country).alpha2.lower() coordinates = geocoder.geocode(searchtext=searchtext, city=city, state_province=state_province, - country=country_iso3) + country=country_iso3166) if coordinates: service_manager.quota_service.increment_success_service_use() plan = plpy.prepare("SELECT ST_SetSRID(ST_MakePoint($1, $2), 4326); ", ["double precision", "double precision"])