How to use the martinez-polygon-clipping.intersection function in martinez-polygon-clipping

To help you get started, we’ve selected a few martinez-polygon-clipping 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 levskaya / polyhedronisme / src / depth.js View on Github external
const simple_intersect = function (A_Vs2d, B_Vs2d) {
  // find 2d intersection of two polygons each specified as list of 2d vertices.
  try {
    // martinez lib expects geojson multi-path polygon which uses repeated final vertices.
    const A_Vs2d_ = A_Vs2d.concat([A_Vs2d[0]]);
    const B_Vs2d_ = B_Vs2d.concat([B_Vs2d[0]]);
    const result = martinez.intersection([A_Vs2d_], [B_Vs2d_]);
    // assume simple intersection structure
    // take 1st polygon, 1st path, drop last repeated vertex
    if (result.length > 0 && result[0].length > 0) {
      return result[0][0].slice(0, result[0][0].length);
    } else {
      return [];
    }
  } catch (e) { // catch rare errors
    console.log(e);
    return [];
  }
}
github Turfjs / turf / packages / turf-intersect / index.js View on Github external
function intersect(poly1, poly2) {
    var geom1 = getGeom(poly1);
    var geom2 = getGeom(poly2);
    var properties = poly1.properties || {};
    // Return null if geometry is too narrow in coordinate precision
    // fixes topology errors with JSTS
    // https://github.com/Turfjs/turf/issues/463
    // https://github.com/Turfjs/turf/pull/1004
    // if (cleanCoords(truncate(geom2, {precision: 4})).coordinates[0].length < 4) return null;
    // if (cleanCoords(truncate(geom1, {precision: 4})).coordinates[0].length < 4) return null;

    var intersection = martinez.intersection(geom1.coordinates, geom2.coordinates);
    if (intersection === null || intersection.length === 0) return null;
    if (intersection.length === 1) return polygon(intersection[0], properties);
    else return multiPolygon(intersection, properties);
}
github Turfjs / turf / packages / turf-intersect / index.ts View on Github external
export default function intersect<p>(
    poly1: Feature</p>

martinez-polygon-clipping

Martinez polygon clipping algorithm, does boolean operation on polygons (multipolygons, polygons with holes etc): intersection, union, difference, xor

MIT
Latest version published 2 months ago

Package Health Score

71 / 100
Full package analysis