Merge pull request #428 from CartoDB/427-Fixed_country_codes_for_Mapbox
Added iso3166 import
This commit is contained in:
commit
41916eed18
@ -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)
|
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 $$
|
RETURNS Geometry AS $$
|
||||||
|
from iso3166 import countries
|
||||||
from cartodb_services.tools import ServiceManager
|
from cartodb_services.tools import ServiceManager
|
||||||
from cartodb_services.mapbox import MapboxGeocoder
|
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
|
from cartodb_services.refactor.service.mapbox_geocoder_config import MapboxGeocoderConfigBuilder
|
||||||
|
|
||||||
import cartodb_services
|
import cartodb_services
|
||||||
@ -228,13 +228,13 @@ RETURNS Geometry AS $$
|
|||||||
try:
|
try:
|
||||||
geocoder = MapboxGeocoder(service_manager.config.mapbox_api_key, service_manager.logger, service_manager.config.service_params)
|
geocoder = MapboxGeocoder(service_manager.config.mapbox_api_key, service_manager.logger, service_manager.config.service_params)
|
||||||
|
|
||||||
country_iso3 = None
|
country_iso3166 = None
|
||||||
if country:
|
if country:
|
||||||
country_iso3 = country_to_iso3(country)
|
country_iso3166 = countries.get(country).alpha2.lower()
|
||||||
|
|
||||||
coordinates = geocoder.geocode(searchtext=searchtext, city=city,
|
coordinates = geocoder.geocode(searchtext=searchtext, city=city,
|
||||||
state_province=state_province,
|
state_province=state_province,
|
||||||
country=country_iso3)
|
country=country_iso3166)
|
||||||
if coordinates:
|
if coordinates:
|
||||||
service_manager.quota_service.increment_success_service_use()
|
service_manager.quota_service.increment_success_service_use()
|
||||||
plan = plpy.prepare("SELECT ST_SetSRID(ST_MakePoint($1, $2), 4326); ", ["double precision", "double precision"])
|
plan = plpy.prepare("SELECT ST_SetSRID(ST_MakePoint($1, $2), 4326); ", ["double precision", "double precision"])
|
||||||
|
@ -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)
|
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 $$
|
RETURNS Geometry AS $$
|
||||||
|
from iso3166 import countries
|
||||||
from cartodb_services.tools import ServiceManager
|
from cartodb_services.tools import ServiceManager
|
||||||
from cartodb_services.mapbox import MapboxGeocoder
|
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
|
from cartodb_services.refactor.service.mapbox_geocoder_config import MapboxGeocoderConfigBuilder
|
||||||
|
|
||||||
import cartodb_services
|
import cartodb_services
|
||||||
@ -2070,13 +2070,13 @@ RETURNS Geometry AS $$
|
|||||||
try:
|
try:
|
||||||
geocoder = MapboxGeocoder(service_manager.config.mapbox_api_key, service_manager.logger, service_manager.config.service_params)
|
geocoder = MapboxGeocoder(service_manager.config.mapbox_api_key, service_manager.logger, service_manager.config.service_params)
|
||||||
|
|
||||||
country_iso3 = None
|
country_iso3166 = None
|
||||||
if country:
|
if country:
|
||||||
country_iso3 = country_to_iso3(country)
|
country_iso3166 = countries.get(country).alpha2.lower()
|
||||||
|
|
||||||
coordinates = geocoder.geocode(searchtext=searchtext, city=city,
|
coordinates = geocoder.geocode(searchtext=searchtext, city=city,
|
||||||
state_province=state_province,
|
state_province=state_province,
|
||||||
country=country_iso3)
|
country=country_iso3166)
|
||||||
if coordinates:
|
if coordinates:
|
||||||
service_manager.quota_service.increment_success_service_use()
|
service_manager.quota_service.increment_success_service_use()
|
||||||
plan = plpy.prepare("SELECT ST_SetSRID(ST_MakePoint($1, $2), 4326); ", ["double precision", "double precision"])
|
plan = plpy.prepare("SELECT ST_SetSRID(ST_MakePoint($1, $2), 4326); ", ["double precision", "double precision"])
|
||||||
|
@ -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)
|
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 $$
|
RETURNS Geometry AS $$
|
||||||
|
from iso3166 import countries
|
||||||
from cartodb_services.tools import ServiceManager
|
from cartodb_services.tools import ServiceManager
|
||||||
from cartodb_services.mapbox import MapboxGeocoder
|
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
|
from cartodb_services.refactor.service.mapbox_geocoder_config import MapboxGeocoderConfigBuilder
|
||||||
|
|
||||||
import cartodb_services
|
import cartodb_services
|
||||||
@ -199,13 +199,13 @@ RETURNS Geometry AS $$
|
|||||||
try:
|
try:
|
||||||
geocoder = MapboxGeocoder(service_manager.config.mapbox_api_key, service_manager.logger, service_manager.config.service_params)
|
geocoder = MapboxGeocoder(service_manager.config.mapbox_api_key, service_manager.logger, service_manager.config.service_params)
|
||||||
|
|
||||||
country_iso3 = None
|
country_iso3166 = None
|
||||||
if country:
|
if country:
|
||||||
country_iso3 = country_to_iso3(country)
|
country_iso3166 = countries.get(country).alpha2.lower()
|
||||||
|
|
||||||
coordinates = geocoder.geocode(searchtext=searchtext, city=city,
|
coordinates = geocoder.geocode(searchtext=searchtext, city=city,
|
||||||
state_province=state_province,
|
state_province=state_province,
|
||||||
country=country_iso3)
|
country=country_iso3166)
|
||||||
if coordinates:
|
if coordinates:
|
||||||
service_manager.quota_service.increment_success_service_use()
|
service_manager.quota_service.increment_success_service_use()
|
||||||
plan = plpy.prepare("SELECT ST_SetSRID(ST_MakePoint($1, $2), 4326); ", ["double precision", "double precision"])
|
plan = plpy.prepare("SELECT ST_SetSRID(ST_MakePoint($1, $2), 4326); ", ["double precision", "double precision"])
|
||||||
|
Loading…
Reference in New Issue
Block a user