terra-route
Version:
A library for routing along GeoJSON LineString networks
45 lines (44 loc) • 1.94 kB
TypeScript
import { FeatureCollection, LineString, Point, Feature, Position } from "geojson";
import { haversineDistance } from "./distance/haversine";
import { createCheapRuler } from "./distance/cheap-ruler";
import { HeapConstructor } from "./heap/heap";
import { LineStringGraph } from "./graph/graph";
interface Router {
buildRouteGraph(network: FeatureCollection<LineString>): void;
getRoute(start: Feature<Point>, end: Feature<Point>): Feature<LineString> | null;
}
declare class TerraRoute implements Router {
private network;
private distanceMeasurement;
private heapConstructor;
private coordinateIndexMap;
private coordinates;
private adjacencyList;
constructor(options?: {
distanceMeasurement?: (a: Position, b: Position) => number;
heap?: HeapConstructor;
});
/**
* Converts a coordinate into a unique index. If the coordinate already exists, returns its index.
* Otherwise, assigns a new index and stores the coordinate.
*
* @param coord - A GeoJSON Position array representing [longitude, latitude].
* @returns A unique numeric index for the coordinate.
*/
buildRouteGraph(network: FeatureCollection<LineString>): void;
/**
* Computes the shortest route between two points in the network using the A* algorithm.
*
* @param start - A GeoJSON Point Feature representing the start location.
* @param end - A GeoJSON Point Feature representing the end location.
* @returns A GeoJSON LineString Feature representing the shortest path, or null if no path is found.
*
* @throws Error if the network has not been built yet with buildRouteGraph(network).
*/
getRoute(start: Feature<Point>, end: Feature<Point>): Feature<LineString> | null;
/**
* Helper to index start/end in getRoute.
*/
private getOrCreateIndex;
}
export { TerraRoute, createCheapRuler, haversineDistance, LineStringGraph };