Giter Club home page Giter Club logo

node-pgrouting's Introduction

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:

id name source target cost_distance reverse_cost_distance cost_duration reverse_cost_duration cost_consumption reverse_cost_consumption filter_toll cost filter_highway
10693 D86 65 66 397.550220811875 397.550220811875 20.4454399274679 20.4454399274679 0.0238530132487125 0.0238530132487125 f Free f
7711 A1/E15-E19 6497 6914 3369.1892947396 3369.1892947396 101.075678842188 101.075678842188 0.303227036526564 0.303227036526564 t Paying t
11326 A10 71 72 702.986479543753 702.986479543753 21.0895943863126 21.0895943863126 0.0632687831589378 0.0632687831589378 f Free t
7885 D3 45 46 1238.94362175843 1238.94362175843 49.557744870337 49.557744870337 0.0867260535230898 0.0867260535230898 f Free f
7663 D317 6819 6872 5334.01082992236 5334.01082992236 274.320556967436 274.320556967436 0.320040649795342 0.320040649795342 f Free f
7799 N104 6789 46 3921.77709540926 3921.77709540926 117.653312862278 117.653312862278 0.352959938586834 0.352959938586834 f Free f

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

node-pgrouting's People

Contributors

tcoupin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

cedricici

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.