1

We are using Leaflet.js to allow our users to draw polygons and save them to their GIS server. We do this by converting the geometry from Leaflet into WFS format and making an Insert Transaction via WFS.

We are having problems where users are drawing polygons that intersect themselves and saving them. These are then showing up as invalid in PostGIS.

Is there any way to check for validity in JavaScript before we insert them?

We are using Leaflet.Geoman for drawing:

map.on('pm:create', function (e) {
  var layerToDraw = e.layer;            
  //want to check here whether the layerToDraw is valid
  features.addLayer(layerToDraw);
});
3
  • 2
    Something in turf.js might help with this
    – Ian Turton
    Sep 1 at 12:44
  • @IanTurton looks like someone has suggested it but it's not been added yet github.com/Turfjs/turf/issues/64
    – fred
    Sep 1 at 14:28
  • @TomazicM I'm not sure what code would help. We are using L.GeoJSON objects.
    – fred
    Sep 1 at 14:29

1 Answer 1

1

If you look at the docs for Leaflet-Geoman at https://github.com/geoman-io/leaflet-geoman#draw-mode you'll see there is allowSelfIntersection option that can prevent drawing kinked polygons.

All you have to do is to set a global option:

map.pm.setGlobalOptions({
  allowSelfIntersection: false
});

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.