JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 7887
  • Score
    100M100P100Q142684F
  • License ISC

Find shortest path through a network of GeoJSON

Package Exports

  • geojson-path-finder

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (geojson-path-finder) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

GeoJSON Path Finder

Build status

Find shortest path through a network of GeoJSON.

Given a network of GeoJSON LineStrings, GeoJSON Path Finder will find the shortest path between two points in the network. This might be useful for automatic route searches in smaller networks, where setting up a real route planner like OSRM is too much work, or you simply need to do everything on the client.

See the GeoJSON Path Finder demo.

Installing

npm install --save geojson-path-finder

API

Create a path finding object:

var PathFinder = require('geojson-path-finder'),
    geojson = require('./network.json');

var pathFinder = new PathFinder(geojson);

The GeoJSON object should be a FeatureCollection of LineString features. The network will be built into a topology, so that lines that start and end, or cross, at the same coordinate are joined such that you can find a path from one feature to the other.

To find the shortest path between two coordinates:

var path = pathfinder.findPath(start, finish);

Where start and finish are two GeoJSON point features.

If a route can be found, an object with two properties: path and weight is returned, where path is the coordinates the path runs through, and weight is the total weight (distance) of the path.