How to use the jsts.operation function in jsts

To help you get started, we’ve selected a few jsts examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cswbrian / district-councils-dashboard / web / src / data / overlap.js View on Github external
const jsts_validate = function(geom) {
  if (geom instanceof jsts.geom.Polygon) {
    if (geom.isValid()) {
      geom.normalize() // validate does not pick up rings in the wrong order - this will fix that
      return geom // If the polygon is valid just return it
    }
    var polygonizer = new jsts.operation.polygonize.Polygonizer()
    jsts_addPolygon(geom, polygonizer)
    return jsts_toPolygonGeometry(polygonizer.getPolygons(), geom.getFactory())
  } else if (geom instanceof jsts.geom.MultiPolygon) {
    if (geom.isValid()) {
      geom.normalize() // validate does not pick up rings in the wrong order - this will fix that
      return geom // If the multipolygon is valid just return it
    }
    var polygonizer = new jsts.operation.polygonize.Polygonizer()

    for (var n = geom.getNumGeometries(); n > 0; n--) {
      jsts_addPolygon(geom.getGeometryN(n - 1), polygonizer)
    }
    return jsts_toPolygonGeometry(polygonizer.getPolygons(), geom.getFactory())
  } else {
    return geom // In my case, I only care about polygon / multipolygon geometries
  }