npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-pgrouting

v0.3.0

Published

A simple interface to pgRouting to compute route and isocurve.

Downloads

7

Readme

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:
  • http://127.0.0.1:8080, graphical interface : use the right click to define start and end point.
  • http://127.0.0.1:8080/app/version
  • http://127.0.0.1:8080/app/capabilities
  • http://127.0.0.1:8080/app/route?from=46,1&to=47,2&type=duration&avoid=toll
  1. Perform unit tests:
docker exec -i -t pgr_node_1 grunt test
  1. Cleanup Dev env
bash dev/down.sh