Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

polygons that intersect themselves #92

jduhls opened this Issue Feb 28, 2014 · 3 comments


None yet
3 participants

jduhls commented Feb 28, 2014

Using leaflet/leaflet.draw I can create polygons that intersect themselves. leaflet.draw has a way to not allow intersections but it currently works when initially drawing a polygon but not when editing one (Leaflet/Leaflet.draw#131). When I try to merge polygons, one of which intersects itself, this throws an error from turf. Perhaps I can iterate through all of the polylines in the polygon and get intersections and add those points to build a new polygon? Not sure yet. Any suggestions? Thanks again for turf - it's been a great way for me to learn nodejs!

screen shot 2014-02-28 at 1 18 12 pm

screen shot 2014-02-28 at 1 18 29 pm

Turf error:

rlayOp.overlayOp(this.geom[0],this.geom[1],opCode);}catch(ex){throw savedExcep
    at Object.<anonymous> (/usr/lib/node_modules/turf/node_modules/jsts/lib/jsts.js:21:414)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/usr/lib/node_modules/turf/node_modules/jsts/index.js:4:12)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)

morganherlocker commented Apr 1, 2014

I currently wrap calls that use jsts in a try catch. I do think it should probably error out if there are invalid polygons, but this should probably be handled by turf directly. The difference would be that it would pass the error back instead of crashing the entire process.

@morganherlocker morganherlocker added the bug label Apr 1, 2014


tmcw commented May 29, 2014

Fwiw, this is an expectation of the simple features spec that is not a factor in geojson validity. I'll look around for a fast self-intersection test...


morganherlocker commented May 29, 2014

I have been leaning in this direction too. If a polygon is invalid, that should be handled a) by the tool that created it or b) by a validation tool like geojsonhint. In this case, I think that Leaflet.Draw might not want to let you place a self intersecting vertex.

@Rub21 Rub21 referenced this issue in osmlab/osmlint Jan 7, 2016


Error with self-intersect Polygon. #29

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment