You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,7 @@ Features:
7
7
* Multi-cost
8
8
* Filters
9
9
* Aggregation of identical sections based on its properties
10
+
* Multi-snapping
10
11
11
12
## How to use ?
12
13
@@ -71,6 +72,7 @@ The `conf` object let you configure the connection to the database and some rout
71
72
***Connection parameters:** node-pgrouting use [pg](https://node-postgres.com) as an interface to PostgreSQL database, with the `conf` object as parameters like *host*, *port*, *user*, *password* and *database*. You can use same environment variables as libpq too : see [pg documentation](https://node-postgres.com/features/connecting) for more details.
72
73
***table:** : table that contains the network. You can use the environment variable *PGTABLE* too. *table* can contain a schema. (Default: *edge*)
73
74
***maxSnappingDistance:** when process the routing, *node-pgrouting* needs to connect your start and end point to closest edge of the network within *maxSnappingDistance* meters.
75
+
***snappingRatio:** allow to snap not only the nearest point but also all near points with a distance difference lower than *snappingRatio* (=(distance-min(distance))/min(distance)). (Default: 0 (no ratio)).
(case when (min(distance) over (order by distance)) = 0 then (case when distance = 0 then 0 else 100 end) else (distance-(min(distance) over (order by distance)))/(min(distance) over (order by distance)) end) ratio,
43
+
( select edge_table.id
44
+
from ${schema}.${table} as edge_table
45
+
where st_dwithin(edge_table.the_geom,st_setsrid(st_makepoint($2,$1),4326),${maxSnappingDistance},true) and
46
+
st_intersects(edge_table.the_geom, new_geom) and
47
+
edge_table.id <> edge_id
48
+
limit 1
49
+
) intersectsother
50
+
FROM (
51
+
SELECT edge_table.id as edge_id,
52
+
st_LineLocatePoint(edge_table.the_geom,st_setsrid(st_makepoint($2,$1),4326)) as fraction,
53
+
st_distance(edge_table.the_geom,st_setsrid(st_makepoint($2,$1),4326),true) as distance,
54
+
ST_AsGeoJSON(st_LineInterpolatePoint(edge_table.the_geom,st_LineLocatePoint(edge_table.the_geom,st_setsrid(st_makepoint($2,$1),4326)))) as edge_point,
55
+
st_linesubstring(
56
+
ST_MakeLine(
57
+
st_setsrid(st_makepoint($2,$1),4326),
58
+
ST_ClosestPoint(
59
+
edge_table.the_geom,
60
+
st_setsrid(st_makepoint($2,$1),4326)
61
+
)
62
+
),0.0001,0.9999) new_geom
63
+
FROM ${schema}.${table} as edge_table
64
+
WHERE st_dwithin(edge_table.the_geom,st_setsrid(st_makepoint($2,$1),4326),${maxSnappingDistance},true) ${filters_where}
65
+
ORDER BY st_distance(edge_table.the_geom,st_setsrid(st_makepoint($2,$1),4326),true)
66
+
) tmp
67
+
) tmp
68
+
WHERE ratio < ${snappingRatio} AND intersectsother is null
constgetStartId="select -start_pid from startandstop";
73
+
constgetStartFraction="select fraction from points where pid = ("+getStartId+")";
74
+
constgetEndId="select -end_pid from startandstop";
75
+
constgetEndFraction="select fraction from points where pid = ("+getEndId+")";
76
+
functioncostSection(type,nbStartPoint){
35
77
return`
36
78
((case
37
-
when tmp.source_node=-1 and tmp.target_node=-2 OR tmp.source_node=-2 and tmp.target_node=-1 then (case when ${startPoint.fraction} < ${endPoint.fraction} then (${endPoint.fraction}-${startPoint.fraction})*edge_table.cost_${type} else (${startPoint.fraction}-${endPoint.fraction})*edge_table.reverse_cost_${type} end)
38
-
when tmp.source_node=-1 then (case when tmp.target_node = edge_table.target then (1-${startPoint.fraction})*edge_table.cost_${type} else (${startPoint.fraction})*edge_table.reverse_cost_${type} END)
39
-
when tmp.target_node=-2 then (case when tmp.source_node = edge_table.source then ${endPoint.fraction}*edge_table.cost_${type} else (1-${endPoint.fraction})*edge_table.reverse_cost_${type} end)
79
+
when tmp.source_node<0 and tmp.source_node>=${-nbStartPoint} and tmp.target_node<${-nbStartPoint} OR tmp.source_node<${-nbStartPoint} and tmp.target_node<0 and tmp.target_node>=${-nbStartPoint} then (case when (${getStartFraction}) < ((${getEndFraction})) then (((${getEndFraction}))-(${getStartFraction}))*edge_table.cost_${type} else ((${getStartFraction})-((${getEndFraction})))*edge_table.reverse_cost_${type} end)
80
+
when tmp.source_node<0 and tmp.source_node>=${-nbStartPoint} then (case when tmp.target_node = edge_table.target then (1-(${getStartFraction}))*edge_table.cost_${type} else ((${getStartFraction}))*edge_table.reverse_cost_${type} END)
81
+
when tmp.target_node<${-nbStartPoint} then (case when tmp.source_node = edge_table.source then ((${getEndFraction}))*edge_table.cost_${type} else (1-((${getEndFraction})))*edge_table.reverse_cost_${type} end)
40
82
else (case when tmp.source_node = edge_table.source then edge_table.cost_${type} else edge_table.reverse_cost_${type} END)
types_aggregate=types_aggregate+"sum(tmp."+type+") as "+type+", "
49
103
})
50
104
@@ -59,28 +113,34 @@ module.exports = {
59
113
properties_select=properties_select+"edge_table."+v+" as "+v+",";
60
114
})
61
115
116
+
62
117
return`
118
+
63
119
with results as (select *
64
120
FROM pgr_withPoints(
65
121
'SELECT edge_table.id, edge_table.source, edge_table.target, edge_table.cost_${type} as cost, edge_table.reverse_cost_${type} as reverse_cost FROM ${schema}.${table} as edge_table ${filters_where}',
66
-
'SELECT 1 as pid, ${startPoint.edge_id} as edge_id, ${startPoint.fraction}::float as fraction
select *, sum(flag_newgroup) over (order by seq) flag_groupid from (
75
135
select
76
136
${types_sections}
77
137
tmp.seq seq,
78
138
(case when lag(${properties_agg}) OVER (order by seq)=${properties_agg} then 0 else 1 end) flag_newgroup,
79
139
${properties_select}
80
140
((((case
81
-
when tmp.source_node=-1 and tmp.target_node=-2 OR tmp.source_node=-2 and tmp.target_node=-1 then (case when ${startPoint.fraction} < ${endPoint.fraction} then ST_LineSubstring(edge_table.the_geom,${startPoint.fraction}, ${endPoint.fraction}) else st_reverse(ST_LineSubstring(edge_table.the_geom, ${endPoint.fraction}, ${startPoint.fraction})) end)
82
-
when tmp.source_node=-1 then (case when tmp.target_node = edge_table.target then ST_LineSubstring(edge_table.the_geom,${startPoint.fraction} ,1) else st_reverse(ST_LineSubstring(edge_table.the_geom,0,${startPoint.fraction})) END)
83
-
when tmp.target_node=-2 then (case when tmp.source_node = edge_table.source then ST_LineSubstring(edge_table.the_geom,0,${endPoint.fraction}) else st_reverse(ST_LineSubstring(edge_table.the_geom,${endPoint.fraction},1)) end)
141
+
when tmp.source_node<0 and tmp.source_node>=${-startPtsIds.length} and tmp.target_node<${-startPtsIds.length} OR tmp.source_node<${-startPtsIds.length} and tmp.target_node<0 and tmp.target_node>=${-startPtsIds.length} then (case when (${getStartFraction}) < ((${getEndFraction})) then ST_LineSubstring(edge_table.the_geom,(${getStartFraction}), ((${getEndFraction}))) else st_reverse(ST_LineSubstring(edge_table.the_geom, ((${getEndFraction})), (${getStartFraction}))) end)
142
+
when tmp.source_node<0 and tmp.source_node>=${-startPtsIds.length} then (case when tmp.target_node = edge_table.target then ST_LineSubstring(edge_table.the_geom,(${getStartFraction}) ,1) else st_reverse(ST_LineSubstring(edge_table.the_geom,0,(${getStartFraction}))) END)
143
+
when tmp.target_node<${-startPtsIds.length} then (case when tmp.source_node = edge_table.source then ST_LineSubstring(edge_table.the_geom,0,((${getEndFraction}))) else st_reverse(ST_LineSubstring(edge_table.the_geom,((${getEndFraction})),1)) end)
84
144
else (case when tmp.source_node = edge_table.source then edge_table.the_geom else st_reverse(edge_table.the_geom) END)
85
145
end))))the_geom
86
146
from
@@ -90,7 +150,7 @@ module.exports = {
90
150
rs.node as source_node,
91
151
rt.node as target_node,
92
152
rs.edge as edge
93
-
from results as rs, results as rt
153
+
from bestresult as rs, bestresult as rt
94
154
where rs.seq = rt.seq-1) tmp
95
155
inner join ${schema}.${table} as edge_table
96
156
on edge_table.id=tmp.edge ) tmp ) tmp group by flag_groupid, ${properties_list} order by seq
0 commit comments