Skip to content

Instantly share code, notes, and snippets.

@ramiroaznar
Created October 4, 2017 14:48
Show Gist options
  • Save ramiroaznar/c461a399eb20ae7392ff77badfea3ce2 to your computer and use it in GitHub Desktop.
Save ramiroaznar/c461a399eb20ae7392ff77badfea3ce2 to your computer and use it in GitHub Desktop.
Routing with CARTO functions
WITH
origin as (
SELECT cartodb_id, name, the_geom FROM populated_places WHERE name ilike 'madrid'
),
destiny as (
SELECT cartodb_id, name, the_geom FROM populated_places WHERE adm0name ilike 'spain'
)
SELECT destiny.cartodb_id, origin.name || '-' || destiny.name as route, r.shape as the_geom, r.length, r.duration/60 as minutes
FROM origin, destiny, cdb_route_point_to_point(origin.the_geom, destiny.the_geom, 'car') r
WHERE origin.cartodb_id <> destiny.cartodb_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment