Socket
Socket
Sign inDemoInstall

geojson-path-finder

Package Overview
Dependencies
6
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0-3 to 2.0.0

docs/.nojekyll

3

package.json
{
"name": "geojson-path-finder",
"version": "2.0.0-3",
"version": "2.0.0",
"description": "Find shortest path through a network of GeoJSON",

@@ -35,4 +35,5 @@ "repository": "git@github.com:perliedman/geojson-path-finder.git",

"tape": "^5.6.1",
"typedoc": "^0.23.22",
"typescript": "^4.8.4"
}
}

@@ -1,13 +0,21 @@

GeoJSON Path Finder
===================
# GeoJSON Path Finder
[![Greenkeeper badge](https://badges.greenkeeper.io/perliedman/geojson-path-finder.svg)](https://greenkeeper.io/) [![Build status](https://travis-ci.org/perliedman/geojson-path-finder.svg?branch=master)](https://travis-ci.org/perliedman/geojson-path-finder)
[![Build status](https://travis-ci.org/perliedman/geojson-path-finder.svg?branch=master)](https://travis-ci.org/perliedman/geojson-path-finder)
Find shortest path through a network of GeoJSON.
Find shortest paths through a network of GeoJSON.
Given a network of GeoJSON `LineString`s, 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.
Given a network of GeoJSON `LineString`s, 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](https://www.liedman.net/geojson-path-finder/).
_Upgrade notice_ Version 2.0 has been released, which is a TypeScript rewrite - you can still use the module from plain JavaScript, of course. This version also contains some breaking changes regarding option naming; for most common use cases, everything will work as before.
Breaking changes:
- option `precision` is now named `tolerance`
- option `keyFn` is now named `key`
- option `weightFn` is now named `weight`
- option `edgeDataReduceFn` is now named `edgeDataReducer`
- option `edgeDataSeed` is now _a function_ taking the properties of the start node
## Installing

@@ -21,7 +29,9 @@

Detailed (and somewhat experimental) [API Docs](docs/)
Create a path finding object:
```javascript
var PathFinder = require('geojson-path-finder'),
geojson = require('./network.json');
var PathFinder = require("geojson-path-finder"),
geojson = require("./network.json");

@@ -41,5 +51,5 @@ var pathFinder = new PathFinder(geojson);

Where `start` and `finish` are two GeoJSON `point` features.
Where `start` and `finish` are two GeoJSON `point` features. Note that both points _have to_ be vertices in the routing network; if they are not, no route will be found.
If a route can be found, an object with two properties: `path` and `weight` is returned, where `path`
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 in kilometers, if you use the default weight function) of the path.

@@ -52,12 +62,12 @@

* `weightFn` controls how the weight (or cost) of travelling between two vertices is calculated;
- `weight` controls how the weight (or cost) of travelling between two vertices is calculated;
by default, the geographic distance between the coordinates is calculated and used as weight;
see [Weight functions](#weight-functions) below for details
* `precision` (default `1e-5`) controls the tolerance for how close vertices in the GeoJSON can be
- `tolerance` (default `1e-5`) controls the tolerance for how close vertices in the GeoJSON can be
before considered being the same vertice; you can say that coordinates closer than this will be
snapped together into one coordinate
* `edgeDataReduceFn` can optionally be used to store data present in the GeoJSON on each edge of
- `edgeDataReducer` can optionally be used to store data present in the GeoJSON on each edge of
the routing graph; typically, this can be used for storing things like street names; if specified,
the reduced data is present on found paths under the `edgeDatas` property
* `edgeDataSeed` is the seed used when reducing edge data with the `edgeDataReduceFn` above
- `edgeDataSeed` is a function returning taking a network feature's `properties` as argument and returning the seed used when reducing edge data with the `edgeDataReducer` above

@@ -68,11 +78,11 @@ ## Weight functions

the geographic distance between the two nodes. This means that, by default, shortest paths will be found.
You can however override this by providing a cost calculation function through the `weightFn` option:
You can however override this by providing a cost calculation function through the `weight` option:
```javascript
var pathFinder = new PathFinder(geojson, {
weightFn: function(a, b, props) {
var dx = a[0] - b[0];
var dy = a[1] - b[1];
return Math.sqrt(dx * dx + dy * dy);
}
weight: function (a, b, props) {
var dx = a[0] - b[0];
var dy = a[1] - b[1];
return Math.sqrt(dx * dx + dy * dy);
},
});

@@ -84,8 +94,8 @@ ```

* a numeric value for the cost of travelling between the two coordinates; in this case, the cost is assumed
to be the same going from `a` to `b` as going from `b` to `a`
* an object with two properties: `forward` and `backward`; in this case,
- a numeric value for the cost of travelling between the two coordinates; in this case, the cost is assumed
to be the same going from `a` to `b` as going from `b` to `a`; as cost of `0` means the edge can't be used
- an object with two properties: `forward` and `backward`; in this case,
`forward` denotes the cost of going from `a` to `b`, and
`backward` the cost of going from `b` to `a`; setting either
to `0`, `null` or `undefined` will prevent taking that direction,
the segment will be a oneway.
to `0` will prevent taking that direction, the segment will be a oneway.
- `undefined` is the same as setting the weight to `0`: this edge can't be used
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc