I am working on a (hobby) project where I am processing gps data (GeoJSON LineStrings) in which this often occurs. I am looking for a solution using JavaScript because I would like to do this client-side.

I am already using leafletjs and turfjs but to my knowledge they both are missing this feature.

note: I opened an issue (as feature request to extend turf.kinks so it covers LineString as well) with the hope turf will cover this gap one day -> https://github.com/Turfjs/turf/issues/528


You could try the JSTS topology suite. Here is a description of the process for polygons you could adapt to your needs.

geojson-utils does not have a self-intersection check per se but, by iterating over the segments of a line you cold use its line-intersection function to test for self intersection. This approach is a bit bit more 'roll-your-own' but would work.

  • thanks. I also searched a lot and stumbled over the article describing JSTS. still a bit reluctant to use because it also looks a bit "roll-your-own" :) – udo Dec 6 '16 at 12:39

turf.kinks now covers LineString as well and returns the coordinates of self-intersections.

note: the issue I opened (https://github.com/Turfjs/turf/issues/528) has been fixed by the turfjs team.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.