@@ -77,150 +77,3 @@ IS 'pgr_withPointsVia
77
77
- Documentation:
78
78
- ${PROJECT_DOC_LINK}/pgr_withPointsVia.html
79
79
' ;
80
-
81
- -- v2.6
82
- CREATE FUNCTION _pgr_withPointsVia (
83
- sql TEXT ,
84
- via_edges BIGINT [],
85
- fraction FLOAT[],
86
- directed BOOLEAN DEFAULT TRUE,
87
-
88
- OUT seq INTEGER ,
89
- OUT path_id INTEGER ,
90
- OUT path_seq INTEGER ,
91
- OUT start_vid BIGINT ,
92
- OUT end_vid BIGINT ,
93
- OUT node BIGINT ,
94
- OUT edge BIGINT ,
95
- OUT cost FLOAT,
96
- OUT agg_cost FLOAT,
97
- OUT route_agg_cost FLOAT)
98
-
99
- RETURNS SETOF RECORD AS
100
- $BODY$
101
- DECLARE
102
- has_rcost boolean ;
103
- sql_new_vertices text := ' ' ;
104
- sql_on_vertex text ;
105
- v_union text := ' ' ;
106
- dummyrec record;
107
- rec1 record;
108
- via_vertices int [];
109
- sql_safe text ;
110
- new_edges text ;
111
- BEGIN
112
- BEGIN
113
- sql_safe = ' SELECT id, source, target, cost, reverse_cost FROM (' || sql || ' ) AS __a' ;
114
-
115
- EXECUTE ' select reverse_cost, pg_typeof(reverse_cost)::text as rev_type from (' || sql_safe|| ' ) AS __b__ limit 1 ' INTO rec1;
116
- has_rcost := true;
117
- EXCEPTION
118
- WHEN OTHERS THEN
119
- has_rcost = false;
120
- END;
121
-
122
-
123
- IF array_length(via_edges, 1 ) != array_length(fraction, 1 ) then
124
- RAISE EXCEPTION ' The length of via_edges is different of length of via_edges' ;
125
- END IF;
126
-
127
- FOR i IN 1 .. array_length(via_edges, 1 )
128
- LOOP
129
- IF fraction[i] = 0 THEN
130
- sql_on_vertex := ' SELECT source FROM (' || sql || ' ) __a where id = ' || via_edges[i];
131
- EXECUTE sql_on_vertex into dummyrec;
132
- via_vertices[i] = dummyrec .source ;
133
- ELSE IF fraction[i] = 1 THEN
134
- sql_on_vertex := ' SELECT target FROM (' || sql || ' ) __a where id = ' || via_edges[i];
135
- EXECUTE sql_on_vertex into dummyrec;
136
- via_vertices[i] = dummyrec .target ;
137
- ELSE
138
- via_vertices[i] = - i;
139
- IF has_rcost THEN
140
- sql_new_vertices = sql_new_vertices || v_union ||
141
- ' (SELECT id, source, ' || - i || ' AS target, cost * ' || fraction[i] || ' AS cost,
142
- reverse_cost * (1 - ' || fraction[i] || ' ) AS reverse_cost
143
- FROM (SELECT * FROM (' || sql || ' ) __b' || i || ' WHERE id = ' || via_edges[i] || ' ) __a' || i || ' )
144
- UNION
145
- (SELECT id, ' || - i || ' AS source, target, cost * (1 -' || fraction[i] || ' ) AS cost,
146
- reverse_cost * ' || fraction[i] || ' AS reverse_cost
147
- FROM (SELECT * FROM (' || sql || ' ) __b' || i || ' where id = ' || via_edges[i] || ' ) __a' || i || ' )' ;
148
- v_union = ' UNION ' ;
149
- ELSE
150
- sql_new_vertices = sql_new_vertices || v_union ||
151
- ' (SELECT id, source, ' || - i || ' AS target, cost * ' || fraction[i] || ' AS cost
152
- FROM (SELECT * FROM (' || sql || ' ) __b' || i || ' WHERE id = ' || via_edges[i] || ' ) __a' || i || ' )
153
- UNION
154
- (SELECT id, ' || - i || ' AS source, target, cost * (1 -' || fraction[i] || ' ) AS cost
155
- FROM (SELECT * FROM (' || sql || ' ) __b' || i || ' WHERE id = ' || via_edges[i] || ' ) __a' || i || ' )' ;
156
- v_union = ' UNION ' ;
157
- END IF;
158
- END IF;
159
- END IF;
160
- END LOOP;
161
-
162
- IF sql_new_vertices = ' ' THEN
163
- new_edges := sql;
164
- ELSE
165
- IF has_rcost THEN
166
- new_edges:= ' WITH
167
- orig AS ( ' || sql || ' ),
168
- original AS (SELECT id, source, target, cost, reverse_cost FROM orig),
169
- the_union AS ( ' || sql_new_vertices || ' ),
170
- first_part AS ( SELECT * FROM (SELECT id, target AS source, lead(target) OVER w AS target,
171
- lead(cost) OVER w - cost AS cost,
172
- lead(cost) OVER w - cost AS reverse_cost
173
- FROM the_union WHERE source > 0 AND cost > 0
174
- WINDOW w AS (PARTITION BY id ORDER BY cost ASC) ) as n2
175
- WHERE target IS NOT NULL),
176
- second_part AS ( SELECT * FROM (SELECT id, lead(source) OVER w AS source, source as target,
177
- reverse_cost - lead(reverse_cost) OVER w AS cost,
178
- reverse_cost - lead(reverse_cost) OVER w AS reverse_cost
179
- FROM the_union WHERE target > 0 and reverse_cost > 0
180
- WINDOW w AS (PARTITION BY id ORDER BY reverse_cost ASC) ) as n2
181
- WHERE source IS NOT NULL),
182
- more_union AS ( SELECT * from (
183
- (SELECT * FROM original)
184
- UNION
185
- (SELECT * FROM the_union)
186
- UNION
187
- (SELECT * FROM first_part)
188
- UNION
189
- (SELECT * FROM second_part) ) _union )
190
- SELECT * FROM more_union' ;
191
- ELSE
192
- new_edges:= ' WITH
193
- orig AS ( ' || sql || ' ),
194
- original AS (SELECT id, source, target, cost FROM orig),
195
- the_union AS ( ' || sql_new_vertices || ' ),
196
- first_part AS ( SELECT * FROM (SELECT id, target AS source, lead(target) OVER w AS target,
197
- lead(cost) OVER w - cost AS cost
198
- FROM the_union WHERE source > 0 AND cost > 0
199
- WINDOW w AS (PARTITION BY id ORDER BY cost ASC) ) as n2
200
- WHERE target IS NOT NULL ),
201
- more_union AS ( SELECT * from (
202
- (SELECT * FROM original)
203
- UNION
204
- (SELECT * FROM the_union)
205
- UNION
206
- (SELECT * FROM first_part) ) _union )
207
- SELECT * FROM more_union' ;
208
- END IF;
209
- END IF;
210
-
211
- sql_new_vertices := sql_new_vertices || v_union || ' (' || sql || ' )' ;
212
-
213
- RETURN query SELECT *
214
- FROM pgr_dijkstraVia(new_edges, via_vertices, directed, has_rcost);
215
- END
216
- $BODY$
217
- LANGUAGE plpgsql VOLATILE STRICT
218
- COST 100
219
- ROWS 1000 ;
220
-
221
-
222
- -- COMMENTS
223
-
224
-
225
- COMMENT ON FUNCTION _pgr_withPointsVia(TEXT , BIGINT [], FLOAT[], BOOLEAN )
226
- IS ' pgRouting internal function deprecated on v3.4.0' ;
0 commit comments