1
- const { query} = require ( './database' ) ;
2
- const { config_pg} = require ( './config' ) ;
1
+ const { query } = require ( './database' ) ;
2
+ const { config_pg } = require ( './config' ) ;
3
3
4
4
function distanceQuery ( start , end ) {
5
5
// ST_GeomFromText('POINT(24.240194 60.008345)', 4326)
@@ -10,7 +10,7 @@ function distanceQuery(start, end) {
10
10
, false)` ;
11
11
return query ;
12
12
}
13
-
13
+ // https://blog.crunchydata.com/blog/routing-with-postgresql-and-crunchy-spatial
14
14
function routeQuery ( start , end ) {
15
15
const query = `
16
16
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) {
45
45
}
46
46
47
47
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
+ } )
62
67
}
63
68
module . exports = {
64
69
route,
0 commit comments