SHARE
TWEET

Untitled

a guest Aug 19th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CREATE or REPLACE FUNCTION GetNearest(NUMERIC, NUMERIC)
  2.   RETURNS BIGINT AS
  3.   $$
  4.   SELECT id FROM ways_vertices_pgr AS vertices
  5.   ORDER BY vertices.the_geom <-> ST_SetSrid(ST_MakePoint($1, $2), 4326) LIMIT 1;
  6.   $$
  7. LANGUAGE SQL;
  8.      
  9. INSERT INTO "UserTravelTime" ("FromLat", "FromLng", "ToLat", "ToLng", "Duration", "CreatedOn", "UpdatedOn")
  10. SELECT C1."Lat" AS "FromLat", C1."Lng" AS "FromLng", C2."Lat" AS "ToLat", C2."Lng" "ToLng",
  11.   (SELECT ROUND(SUM(cost)) AS Cost FROM pgr_dijkstra(
  12.     'SELECT gid AS id,
  13.          source,
  14.          target,
  15.          cost_s as cost
  16.         FROM ways',
  17.     (SELECT GetNearest(C1."Lng", C1."Lat")), (SELECT GetNearest(C2."Lng", C2."Lat")),
  18.     directed := true)),
  19.     NOW(),
  20.     NOW()
  21.   FROM
  22.   "UserCoordinate" C1,
  23.   "UserCoordinate" C2;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top