perliedman / geojson-path-finder

Find shortest path through a network of GeoJSON
https://www.liedman.net/geojson-path-finder/
ISC License
300 stars 86 forks source link

Error: Compacted graph contains no forks (topology has no intersections) if GeoJSON is a closed loop #75

Closed oleg131 closed 1 year ago

oleg131 commented 3 years ago

If input GeoJSON is a closed loop, I get the following error on initialization:

const pathFinder = new PathFinder(geojson);
Uncaught Error: Compacted graph contains no forks (topology has no intersections).
    at new PathFinder (index.js:formatted:1)
    at calculate (RoutingPage.js:375)
    at HTMLUnknownElement.callCallback (react-dom.development.js:3945)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:3994)
    at invokeGuardedCallback (react-dom.development.js:4056)
    at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:4070)
    at executeDispatch (react-dom.development.js:8243)
    at processDispatchQueueItemsInOrder (react-dom.development.js:8275)
    at processDispatchQueue (react-dom.development.js:8288)
    at dispatchEventsForPlugins (react-dom.development.js:8299)
    at react-dom.development.js:8508
    at batchedEventUpdates$1 (react-dom.development.js:22396)
    at batchedEventUpdates (react-dom.development.js:3745)
    at dispatchEventForPluginEventSystem (react-dom.development.js:8507)
    at attemptToDispatchEvent (react-dom.development.js:6005)
    at dispatchEvent (react-dom.development.js:5924)
    at unstable_runWithPriority (scheduler.development.js:468)
    at runWithPriority$1 (react-dom.development.js:11276)
    at discreteUpdates$1 (react-dom.development.js:22413)
    at discreteUpdates (react-dom.development.js:3756)
    at dispatchDiscreteEvent (react-dom.development.js:5889)

Removing a single LinePath from GeoJSON makes the error go away.

GeoJSON used: https://pastebin.com/2mfrUxYU

oleg131 commented 3 years ago

Workaround: add some nearby point to the end of an arbitrary segment, so it looks like an appendix. It will not influence path calculation but makes the error go away.