Skip to content

Commit 2042a16

Browse files
committedSep 26, 2021
vertices table added
1 parent 90bf85b commit 2042a16

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed
 

‎src/pgRouting.js

+22-17
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const {query} = require('./database');
2-
const {config_pg} = require('./config');
1+
const { query } = require('./database');
2+
const { config_pg } = require('./config');
33

44
function distanceQuery(start, end) {
55
// ST_GeomFromText('POINT(24.240194 60.008345)', 4326)
@@ -10,7 +10,7 @@ function distanceQuery(start, end) {
1010
, false)`;
1111
return query;
1212
}
13-
13+
// https://blog.crunchydata.com/blog/routing-with-postgresql-and-crunchy-spatial
1414
function routeQuery(start, end) {
1515
const query = `
1616
SELECT *, st_transform(geom, ${config_pg.output_srid}) as geom, st_asgeojson(st_transform(geom, ${config_pg.output_srid})) geojson, st_astext(st_transform(geom, ${config_pg.output_srid})) wkt FROM pgr_dijkstra(
@@ -45,20 +45,25 @@ function closest(lat, lng, buffer, limit) {
4545
}
4646

4747
const topology = async () => {
48-
await query(`SELECT pgr_createTopology(${config_pg.table}, 0.0001, 'geom', 'id')`, () => {
49-
console.log("Topology created");
50-
})
51-
await query(`SELECT pgr_analyzeGraph(${config_pg.table}, 0.0001, 'geom','id', 'source', 'target')`, () => {
52-
console.log("Graph Anaysis");
53-
54-
})
55-
await query(`UPDATE ${config_pg.table} SET cost_len = ST_Length(st_transform(geom, 3857))`, () => {
56-
console.log("Cost length");
57-
58-
})
59-
await query(`UPDATE ${config_pg.table} SET rcost_len = cost_len)`, () => {
60-
console.log("Reverse cost length");
61-
})
48+
// https://docs.pgrouting.org/latest/en/topology-functions.html
49+
await query(`SELECT pgr_createTopology('${config_pg.table}', 0.0001, 'geom', 'id')`, () => {
50+
console.log("Topology created");
51+
})
52+
53+
await query(`SELECT pgr_createVerticesTable('${config_pg.vertices_table}', 'geom', 'source', 'target')`, () => {
54+
console.log("Vertices Tablee created");
55+
})
56+
await query(`SELECT pgr_analyzeGraph('${config_pg.table}', 0.0001, 'geom','id', 'source', 'target')`, () => {
57+
console.log("Graph Anaysis");
58+
59+
})
60+
await query(`UPDATE ${config_pg.table} SET cost_len = ST_Length(st_transform(geom, 3857))`, () => {
61+
console.log("Cost length");
62+
63+
})
64+
await query(`UPDATE ${config_pg.table} SET rcost_len = cost_len)`, () => {
65+
console.log("Reverse cost length");
66+
})
6267
}
6368
module.exports = {
6469
route,

0 commit comments

Comments
 (0)
Please sign in to comment.