-- Find the source ID closest to the starting point
with start as (
select
source
from
ways
order by
the_geom <-> st_setsrid(
st_geomfromtext('point (-74.244391 40.498995)'),
4326
)
limit
1
),
-- Find the source ID closest to the end point
destination as (
select
source
from
ways
order by
the_geom <-> st_setsrid(
st_geomfromtext('point (-73.902630 40.912329)'),
4326
)
limit
1
)
-- Run our pgRouting query
select
st_union(the_geom) as route
from
pgr_dijkstra(
'select gid as id, source, target, cost,
reverse_cost, st_length(st_transform(the_geom, 3857))
as cost from ways',
(
select
source
from
start
),
(
select
source
from
destination
),
true
) as di
join ways as pt on di.edge = pt.gid;
update
car_config
set
penalty = -1.0
where
tag_value in ('steps', 'footway', 'pedestrian');
update
car_config
set
penalty = 5
where
tag_value in ('unclassified');
update
car_config
set
penalty = 0.5
where
tag_value in ('tertiary');
update
car_config
set
penalty = 0.3
where
tag_value in (
'primary',
'primary_link',
'trunk',
'trunk_link',
'motorway',
'motorway_junction',
'motorway_link',
'secondary'
);
with start as (
select
source
from
ways
order by
the_geom <-> st_setsrid(
st_geomfromtext('point (-74.244391 40.498995)'),
4326
)
limit
1
), destination as (
select
source
from
ways
order by
the_geom <-> st_setsrid(
st_geomfromtext('point (-73.902630 40.912329)'),
4326
)
limit
1
)
select
st_union(the_geom) as route
from
pgr_dijkstra(
'select
gid as id,
source,
target,
cost_s * penalty as cost,
reverse_cost_s * penalty as reverse_cost,
st_length(st_transform(the_geom, 3857)) as length
from
ways
join car_config using (tag_id)',
(
select
source
from
start
),
(
select
source
from
destination
),
true
) as di
join ways as pt on di.edge = pt.gid;