
Security News
rv Is a New Rust-Powered Ruby Version Manager Inspired by Python's uv
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
arkmap-path-finder
Advanced tools
Find shortest path 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.
See the GeoJSON Path Finder demo.
npm install --save geojson-path-finder
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. 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
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.
PathFinder
optionsThe PathFinder
constructor takes an optional seconds parameter containing options
that you can
use to control the behaviour of the path finder. Available options:
weightFn
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 below for detailsprecision
(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 coordinateedgeDataReduceFn
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
propertyedgeDataSeed
is the seed used when reducing edge data with the edgeDataReduceFn
aboveBy default, the cost of going from one node in the network to another is determined simply by
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:
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);
}
});
The weight function is passed two coordinate arrays (in GeoJSON axis order), as well as the feature properties that are associated with this feature, and should return either:
a
to b
as going from b
to a
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.FAQs
GeoJSON Path Finder ===================
We found that arkmap-path-finder demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.
Security News
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.