2018-06-11 22:12:29 +08:00
|
|
|
-- TODO: could cartodb_id be replaced by rowid, maybe needing extra care for offset?
|
|
|
|
CREATE TYPE cdb_dataservices_server.geocoding AS (
|
|
|
|
cartodb_id integer,
|
2018-12-25 00:19:13 +08:00
|
|
|
the_geom geometry(Point,4326),
|
2018-06-11 22:12:29 +08:00
|
|
|
metadata jsonb
|
|
|
|
);
|
|
|
|
|
2018-09-10 18:54:37 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_bulk_geocode_street_point(username TEXT, orgname TEXT, searches jsonb)
|
2018-06-11 22:12:29 +08:00
|
|
|
RETURNS SETOF cdb_dataservices_server.geocoding AS $$
|
|
|
|
from cartodb_services.metrics import metrics
|
|
|
|
from cartodb_services.tools import Logger
|
2018-11-06 00:06:52 +08:00
|
|
|
import json
|
2018-06-11 22:12:29 +08:00
|
|
|
|
|
|
|
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_geocoder_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
|
|
|
user_geocoder_config = GD["user_geocoder_config_{0}".format(username)]
|
|
|
|
|
|
|
|
plpy.execute("SELECT cdb_dataservices_server._get_logger_config()")
|
|
|
|
logger_config = GD["logger_config"]
|
|
|
|
logger = Logger(logger_config)
|
|
|
|
|
2018-11-06 00:06:52 +08:00
|
|
|
params = {'username': username, 'orgname': orgname, 'searches': json.loads(searches)}
|
2018-06-11 22:12:29 +08:00
|
|
|
|
|
|
|
with metrics('cdb_bulk_geocode_street_point', user_geocoder_config, logger, params):
|
|
|
|
if user_geocoder_config.google_geocoder:
|
2018-07-05 23:12:22 +08:00
|
|
|
provider_function = "_cdb_bulk_google_geocode_street_point";
|
2018-06-29 20:59:07 +08:00
|
|
|
elif user_geocoder_config.heremaps_geocoder:
|
2018-07-05 23:12:22 +08:00
|
|
|
provider_function = "_cdb_bulk_heremaps_geocode_street_point";
|
|
|
|
elif user_geocoder_config.tomtom_geocoder:
|
|
|
|
provider_function = "_cdb_bulk_tomtom_geocode_street_point";
|
2018-07-07 18:14:33 +08:00
|
|
|
elif user_geocoder_config.mapbox_geocoder:
|
|
|
|
provider_function = "_cdb_bulk_mapbox_geocode_street_point";
|
2020-01-14 20:27:16 +08:00
|
|
|
elif user_geocoder_config.geocodio_geocoder:
|
|
|
|
provider_function = "_cdb_bulk_geocodio_geocode_street_point";
|
2018-06-11 22:12:29 +08:00
|
|
|
else:
|
|
|
|
raise Exception('Requested geocoder is not available')
|
|
|
|
|
2018-07-05 23:12:22 +08:00
|
|
|
plan = plpy.prepare("SELECT * FROM cdb_dataservices_server.{}($1, $2, $3); ".format(provider_function), ["text", "text", "jsonb"])
|
2018-07-18 20:29:50 +08:00
|
|
|
return plpy.execute(plan, [username, orgname, searches])
|
2018-06-29 20:59:07 +08:00
|
|
|
|
2020-02-24 23:12:27 +08:00
|
|
|
$$ LANGUAGE @@plpythonu@@ STABLE PARALLEL RESTRICTED;
|
2018-06-11 22:12:29 +08:00
|
|
|
|
2018-06-22 18:19:51 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_bulk_google_geocode_street_point(username TEXT, orgname TEXT, searches jsonb)
|
2018-06-11 22:12:29 +08:00
|
|
|
RETURNS SETOF cdb_dataservices_server.geocoding AS $$
|
2018-06-29 20:59:07 +08:00
|
|
|
from cartodb_services import run_street_point_geocoder
|
|
|
|
from cartodb_services.tools import LegacyServiceManager
|
2018-07-10 19:25:40 +08:00
|
|
|
from cartodb_services.google import GoogleMapsBulkGeocoder
|
2018-06-11 22:12:29 +08:00
|
|
|
|
|
|
|
service_manager = LegacyServiceManager('geocoder', username, orgname, GD)
|
2018-07-10 19:25:40 +08:00
|
|
|
geocoder = GoogleMapsBulkGeocoder(service_manager.config.google_client_id, service_manager.config.google_api_key, service_manager.logger)
|
2018-06-29 20:59:07 +08:00
|
|
|
return run_street_point_geocoder(plpy, GD, geocoder, service_manager, username, orgname, searches)
|
2020-02-24 23:12:27 +08:00
|
|
|
$$ LANGUAGE @@plpythonu@@ STABLE PARALLEL RESTRICTED;
|
2018-06-11 22:12:29 +08:00
|
|
|
|
2018-06-29 20:59:07 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_bulk_heremaps_geocode_street_point(username TEXT, orgname TEXT, searches jsonb)
|
|
|
|
RETURNS SETOF cdb_dataservices_server.geocoding AS $$
|
|
|
|
from cartodb_services import run_street_point_geocoder
|
|
|
|
from cartodb_services.tools import LegacyServiceManager
|
2021-05-17 21:11:04 +08:00
|
|
|
from cartodb_services.here import get_bulk_geocoder
|
2018-06-29 20:59:07 +08:00
|
|
|
|
|
|
|
service_manager = LegacyServiceManager('geocoder', username, orgname, GD)
|
2021-05-17 21:11:04 +08:00
|
|
|
geocoder = get_bulk_geocoder(app_id=service_manager.config.heremaps_app_id or None, app_code=service_manager.config.heremaps_app_code or None, logger=service_manager.logger, service_params=service_manager.config.heremaps_service_params, apikey=service_manager.config.apikey or None, use_apikey=service_manager.config.use_apikey or False)
|
2018-06-29 20:59:07 +08:00
|
|
|
return run_street_point_geocoder(plpy, GD, geocoder, service_manager, username, orgname, searches)
|
2020-02-24 23:12:27 +08:00
|
|
|
$$ LANGUAGE @@plpythonu@@ STABLE PARALLEL RESTRICTED;
|
2018-06-11 22:12:29 +08:00
|
|
|
|
2018-07-05 23:12:22 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_bulk_tomtom_geocode_street_point(username TEXT, orgname TEXT, searches jsonb)
|
|
|
|
RETURNS SETOF cdb_dataservices_server.geocoding AS $$
|
|
|
|
from cartodb_services import run_street_point_geocoder
|
|
|
|
from cartodb_services.tools import ServiceManager
|
|
|
|
from cartodb_services.refactor.service.tomtom_geocoder_config import TomTomGeocoderConfigBuilder
|
|
|
|
from cartodb_services.tomtom import TomTomBulkGeocoder
|
|
|
|
from cartodb_services.tools import Logger
|
|
|
|
import cartodb_services
|
|
|
|
cartodb_services.init(plpy, GD)
|
|
|
|
|
|
|
|
logger_config = GD["logger_config"]
|
|
|
|
logger = Logger(logger_config)
|
|
|
|
service_manager = ServiceManager('geocoder', TomTomGeocoderConfigBuilder, username, orgname, GD)
|
|
|
|
geocoder = TomTomBulkGeocoder(service_manager.config.tomtom_api_key, service_manager.logger, service_manager.config.service_params)
|
|
|
|
return run_street_point_geocoder(plpy, GD, geocoder, service_manager, username, orgname, searches)
|
2020-02-24 23:12:27 +08:00
|
|
|
$$ LANGUAGE @@plpythonu@@ STABLE PARALLEL RESTRICTED;
|
2018-07-05 23:12:22 +08:00
|
|
|
|
2018-07-07 18:14:33 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_bulk_mapbox_geocode_street_point(username TEXT, orgname TEXT, searches jsonb)
|
|
|
|
RETURNS SETOF cdb_dataservices_server.geocoding AS $$
|
|
|
|
from cartodb_services import run_street_point_geocoder
|
|
|
|
from cartodb_services.tools import ServiceManager
|
|
|
|
from cartodb_services.refactor.service.mapbox_geocoder_config import MapboxGeocoderConfigBuilder
|
|
|
|
from cartodb_services.mapbox import MapboxBulkGeocoder
|
|
|
|
from cartodb_services.tools import Logger
|
|
|
|
import cartodb_services
|
|
|
|
cartodb_services.init(plpy, GD)
|
|
|
|
|
|
|
|
logger_config = GD["logger_config"]
|
|
|
|
logger = Logger(logger_config)
|
|
|
|
service_manager = ServiceManager('geocoder', MapboxGeocoderConfigBuilder, username, orgname, GD)
|
|
|
|
geocoder = MapboxBulkGeocoder(service_manager.config.mapbox_api_key, service_manager.logger, service_manager.config.service_params)
|
|
|
|
return run_street_point_geocoder(plpy, GD, geocoder, service_manager, username, orgname, searches)
|
2020-02-24 23:12:27 +08:00
|
|
|
$$ LANGUAGE @@plpythonu@@ STABLE PARALLEL RESTRICTED;
|
2018-07-07 18:14:33 +08:00
|
|
|
|
2020-01-14 20:27:16 +08:00
|
|
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server._cdb_bulk_geocodio_geocode_street_point(username TEXT, orgname TEXT, searches jsonb)
|
|
|
|
RETURNS SETOF cdb_dataservices_server.geocoding AS $$
|
|
|
|
from cartodb_services import run_street_point_geocoder
|
|
|
|
from cartodb_services.tools import ServiceManager
|
|
|
|
from cartodb_services.refactor.service.geocodio_geocoder_config import GeocodioGeocoderConfigBuilder
|
|
|
|
from cartodb_services.geocodio import GeocodioBulkGeocoder
|
|
|
|
from cartodb_services.tools import Logger
|
|
|
|
import cartodb_services
|
|
|
|
cartodb_services.init(plpy, GD)
|
|
|
|
|
|
|
|
logger_config = GD["logger_config"]
|
|
|
|
logger = Logger(logger_config)
|
|
|
|
service_manager = ServiceManager('geocoder', GeocodioGeocoderConfigBuilder, username, orgname, GD)
|
|
|
|
geocoder = GeocodioBulkGeocoder(service_manager.config.geocodio_api_key, service_manager.logger, service_manager.config.service_params)
|
|
|
|
return run_street_point_geocoder(plpy, GD, geocoder, service_manager, username, orgname, searches)
|
2020-02-24 23:12:27 +08:00
|
|
|
$$ LANGUAGE @@plpythonu@@ STABLE PARALLEL RESTRICTED;
|