0.3.0 • Published 6 years ago

node-pgrouting v0.3.0

Weekly downloads
8
License
GPL-3.0
Repository
github
Last release
6 years ago

node-pgrouting

Travis Dependency Status npm npm Twitter

A simple interface to pgRouting.

Features:

  • Multi-cost
  • Filters
  • Aggregation of identical sections based on its properties
  • Multi-snapping
  • routing AND isocurve

How to use ?

Routing

const pgr = require("node-pgrouting")(conf);
let geojeson_results = await pgr.routing({from:"46,1",to:"47,2","type":"duration", "avoid":"toll"});
  • The routing return a Promise, so you can use the async/await like above or the Promise itself.
  • type and avoid depend on data structure (see Data structure)

Isocurve

const pgr = require("node-pgrouting")(conf);
let geojeson_results = await pgr.isocurve({from:"46,1","type":"duration", "avoid":"toll", "values":"3600,7200"});
  • The isocurve return a Promise, so you can use the async/await like above or the Promise itself.
  • type and avoid depend on data structure (see Data structure)
  • from or to

Capabilities (data structure)

const pgr = require("node-pgrouting")(conf);
let types = await pgr.getTypes();
  • The getTypes return a Promise, so you can use the async/await like above or the Promise itself.
  • types is an array of available cost based on data structure (see Data structure)
const pgr = require("node-pgrouting")(conf);
let filters = await pgr.getFilters();
  • The getFilters return a Promise, so you can use the async/await like above or the Promise itself.
  • filters is an array of available filter based on data structure (see Data structure)
const pgr = require("node-pgrouting")(conf);
let properties = await pgr.getProperties();
  • The getProperties return a Promise, so you can use the async/await like above or the Promise itself.
  • properties is an array of available feature properties based on data structure (see Data structure)

PgRouting version

const pgr = require("node-pgrouting")(conf);
let version = await pgr.pgVersion();
  • The pgVersion return a Promise, so you can use the async/await like above or the Promise itself.
  • pgVersion is the version of PgRouting extension, not PosGIS or Postgresql version.

Close connection to the database

const pgr = require("node-pgrouting")(conf);
...your stuff...
pgr.close();

Configuration

The conf object let you configure the connection to the database and some routing options :

  • Connection parameters: node-pgrouting use pg 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 for more details.
  • table: : table that contains the network. You can use the environment variable PGTABLE too. table can contain a schema. (Default: edge)
  • maxSnappingDistance: when process the routing, node-pgrouting needs to connect your start and end point to closest edge of the network within maxSnappingDistance meters.
  • 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)).

Data structure

Requirements: pgRouting concepts.

The data structure determine the routing capabilites. Some attributes are reserved:

  • id: an uniq identifier of the network section
  • source, target: for pgRouting topology
  • cost_TYPE and reverse_cost_TYPE: the cost of the section when perform routing to minimize TYPE. You can provides as many type as wanted.
  • filter_FILTER: true to avoid this section by use avoid: 'FILTER' in routing params. You can provides as many filter as wanted.
  • the_geom: geometry of the section, with 4326 SRID.
  • seq: use in routing response.

All other properties are used to identify the section. If multiple sections have the same properties, they are grouped in the routing response.

Example:

idnamesourcetargetcost_distancereverse_cost_distancecost_durationreverse_cost_durationcost_consumptionreverse_cost_consumptionfilter_tollcostfilter_highway
10693D866566397.550220811875397.55022081187520.445439927467920.44543992746790.02385301324871250.0238530132487125fFreef
7711A1/E15-E19649769143369.18929473963369.1892947396101.075678842188101.0756788421880.3032270365265640.303227036526564tPayingt
11326A107172702.986479543753702.98647954375321.089594386312621.08959438631260.06326878315893780.0632687831589378fFreet
7885D345461238.943621758431238.9436217584349.55774487033749.5577448703370.08672605352308980.0867260535230898fFreef
7663D317681968725334.010829922365334.01082992236274.320556967436274.3205569674360.3200406497953420.320040649795342fFreef
7799N1046789463921.777095409263921.77709540926117.653312862278117.6533128622780.3529599385868340.352959938586834fFreef

This table provides:

  • 3 types: distance, duration, consumption
  • 2 filters: toll, highway
  • 2 properties: name, cost

Demonstration/Development

  1. Start demo/dev environmnent
bash dev/up.sh
  1. Use the GUI or the REST service:
  1. Perform unit tests:
docker exec -i -t pgr_node_1 grunt test
  1. Cleanup Dev env
bash dev/down.sh
0.3.0

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago