39 lines
2.2 KiB
MySQL
39 lines
2.2 KiB
MySQL
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_route_point_to_point(
|
||
|
username TEXT,
|
||
|
orgname TEXT,
|
||
|
origin geometry(Point, 4326),
|
||
|
destination geometry(Point, 4326),
|
||
|
mode TEXT,
|
||
|
options text[] DEFAULT ARRAY[]::text[],
|
||
|
units text DEFAULT 'kilometers')
|
||
|
RETURNS cdb_dataservices_server.simple_route 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_routing_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||
|
user_routing_config = GD["user_routing_config_{0}".format(username)]
|
||
|
|
||
|
waypoints = [origin, destination]
|
||
|
mapzen_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_mapzen_route_with_waypoints($1, $2, $3, $4, $5, $6) as route;", ["text", "text", "geometry(Point, 4326)[]", "text", "text[]", "text"])
|
||
|
result = plpy.execute(mapzen_plan, [username, orgname, waypoints, mode, options, units])
|
||
|
return [result[0]['shape'],result[0]['length'], result[0]['duration']]
|
||
|
$$ LANGUAGE plpythonu;
|
||
|
|
||
|
|
||
|
CREATE OR REPLACE FUNCTION cdb_dataservices_server.cdb_route_with_waypoints(
|
||
|
username TEXT,
|
||
|
orgname TEXT,
|
||
|
waypoints geometry(Point, 4326)[],
|
||
|
mode TEXT,
|
||
|
options text[] DEFAULT ARRAY[]::text[],
|
||
|
units text DEFAULT 'kilometers')
|
||
|
RETURNS cdb_dataservices_server.simple_route 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_routing_config({0}, {1})".format(plpy.quote_nullable(username), plpy.quote_nullable(orgname)))
|
||
|
user_routing_config = GD["user_routing_config_{0}".format(username)]
|
||
|
|
||
|
mapzen_plan = plpy.prepare("SELECT * FROM cdb_dataservices_server._cdb_mapzen_route_with_waypoints($1, $2, $3, $4, $5, $6) as route;", ["text", "text", "geometry(Point, 4326)[]", "text", "text[]", "text"])
|
||
|
result = plpy.execute(mapzen_plan, [username, orgname, waypoints, mode, options, units])
|
||
|
return [result[0]['shape'],result[0]['length'], result[0]['duration']]
|
||
|
$$ LANGUAGE plpythonu;
|