{"id":14037324,"url":"https://github.com/perliedman/geojson-path-finder","last_synced_at":"2025-05-16T18:06:44.517Z","repository":{"id":8183701,"uuid":"57132041","full_name":"perliedman/geojson-path-finder","owner":"perliedman","description":"Find shortest path through a network of GeoJSON","archived":false,"fork":false,"pushed_at":"2025-01-07T20:33:36.000Z","size":7556,"stargazers_count":315,"open_issues_count":22,"forks_count":89,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-05-16T18:06:40.714Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.liedman.net/geojson-path-finder/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/perliedman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-04-26T13:49:15.000Z","updated_at":"2025-05-12T23:02:49.000Z","dependencies_parsed_at":"2023-02-18T23:10:25.063Z","dependency_job_id":"9c914e3e-86ae-4e34-a2c4-ecd0f4b500d8","html_url":"https://github.com/perliedman/geojson-path-finder","commit_stats":{"total_commits":100,"total_committers":8,"mean_commits":12.5,"dds":0.6,"last_synced_commit":"5995272420d62e2ced513664a6b290a2aab33ebf"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perliedman%2Fgeojson-path-finder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perliedman%2Fgeojson-path-finder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perliedman%2Fgeojson-path-finder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/perliedman%2Fgeojson-path-finder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/perliedman","download_url":"https://codeload.github.com/perliedman/geojson-path-finder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254582905,"owners_count":22095518,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-12T03:02:42.708Z","updated_at":"2025-05-16T18:06:44.486Z","avatar_url":"https://github.com/perliedman.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# GeoJSON Path Finder\n\n[![Build status](https://travis-ci.org/perliedman/geojson-path-finder.svg?branch=master)](https://travis-ci.org/perliedman/geojson-path-finder)\n\nFind shortest paths through a network of GeoJSON.\n\nGiven 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.\n\nSee the [GeoJSON Path Finder demo](https://www.liedman.net/geojson-path-finder/).\n\n_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.\n\nBreaking changes:\n\n- option `precision` is now named `tolerance`\n- option `keyFn` is now named `key`\n- option `weightFn` is now named `weight`\n- option `edgeDataReduceFn` is now named `edgeDataReducer`\n- option `edgeDataSeed` is now _a function_ taking the properties of the start node\n\n## Installing\n\n```\nnpm install --save geojson-path-finder\n```\n\n## API\n\nDetailed (and somewhat experimental) [API Docs](https://www.liedman.net/geojson-path-finder/docs/)\n\nCreate a path finding object:\n\n```javascript\nimport PathFinder from \"geojson-path-finder\";\nimport geojson from \"./network.json\";\n\nconst pathFinder = new PathFinder(geojson);\n```\n\nThe GeoJSON object should be a `FeatureCollection` of `LineString` features. The network will be built\ninto a topology, so that lines that start and end, or cross, at the same coordinate are joined such that\nyou can find a path from one feature to the other.\n\nTo find the shortest path between two coordinates:\n\n```javascript\nvar path = pathFinder.findPath(start, finish);\n```\n\nWhere `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.\n\nIf a route can be found, an object with two properties: `path` and `weight` is returned, where `path`\nis 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.\n\nAs a convenience, the function `pathToGeoJSON` is also exported, it converts the result of a `findPath` call to\na GeoJSON linestring:\n\n```javascript\nimport PathFinder, { pathToGeoJSON } from \"geojson-path-finder\";\nconst pathFinder = new PathFinder(geojson);\nconst pathLineString = pathToGeoJSON(pathFinder.findPath(start, finish));\n```\n\n(If `findPath` does not find a path, pathToGeoJSON will also return `undefined`.)\n\n### `PathFinder` options\n\nThe `PathFinder` constructor takes an optional seconds parameter containing `options` that you can\nuse to control the behaviour of the path finder. Available options:\n\n- `weight` controls how the weight (or cost) of travelling between two vertices is calculated;\n  by default, the geographic distance between the coordinates is calculated and used as weight;\n  see [Weight functions](#weight-functions) below for details\n- `tolerance` (default `1e-5`) controls the tolerance for how close vertices in the GeoJSON can be\n  before considered being the same vertice; you can say that coordinates closer than this will be\n  snapped together into one coordinate\n- `edgeDataReducer` can optionally be used to store data present in the GeoJSON on each edge of\n  the routing graph; typically, this can be used for storing things like street names; if specified,\n  the reduced data is present on found paths under the `edgeDatas` property\n- `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\n\n## Weight functions\n\nBy default, the _cost_ of going from one node in the network to another is determined simply by\nthe geographic distance between the two nodes. This means that, by default, shortest paths will be found.\nYou can however override this by providing a cost calculation function through the `weight` option:\n\n```javascript\nconst pathFinder = new PathFinder(geojson, {\n  weight: function (a, b, props) {\n    const dx = a[0] - b[0];\n    const dy = a[1] - b[1];\n    return Math.sqrt(dx * dx + dy * dy);\n  },\n});\n```\n\nThe weight function is passed two coordinate arrays (in GeoJSON axis order), as well as the feature properties\nthat are associated with this feature, and should return either:\n\n- a numeric value for the cost of travelling between the two coordinates; in this case, the cost is assumed\n  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\n- an object with two properties: `forward` and `backward`; in this case,\n  `forward` denotes the cost of going from `a` to `b`, and\n  `backward` the cost of going from `b` to `a`; setting either\n  to `0` will prevent taking that direction, the segment will be a oneway.\n- `undefined` is the same as setting the weight to `0`: this edge can't be used\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperliedman%2Fgeojson-path-finder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fperliedman%2Fgeojson-path-finder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperliedman%2Fgeojson-path-finder/lists"}