How to use polygon-clipping - 3 common examples

To help you get started, we’ve selected a few 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 Turfjs / turf / src / difference / index.js View on Github external
function difference(polygon1, polygon2) {
    const geom1 = getGeom(polygon1);
    const geom2 = getGeom(polygon2);
    const properties = polygon1.properties || {};
    const differenced = polygonClipping.difference(geom1.coordinates, geom2.coordinates);
    if (differenced.length === 0) return null;
    return multiPolygon(differenced, properties);
}
github Turfjs / turf / src / intersect / index.js View on Github external
export default function intersect(poly1, poly2, options) {
    options = checkIfOptionsExist(options);
    const properties = options.properties || {};

    const geom1 = getGeom(poly1);
    const geom2 = getGeom(poly2);

    const intersection = polygonClipping.intersection(geom1.coordinates, geom2.coordinates);
    if (intersection.length === 0) return null;
    return multiPolygon(intersection, properties);
}
github Turfjs / turf / src / union / index.js View on Github external
function union(fc) {
    const args = [];
    geomEach(fc, function (geom) {
        if (geom.type === 'Polygon') args.push(geom.coordinates);
        else geom.coordinates.forEach(function (contour) {
            args.push(contour);
        });
    });
    const unioned = polygonClipping.union(args);
    if (unioned.length === 0) return null;
    else return multiPolygon(unioned);
}

polygon-clipping

Apply boolean Polygon clipping operations (intersection, union, difference, xor) to your Polygons & MultiPolygons.

MIT
Latest version published 11 months ago

Package Health Score

69 / 100
Full package analysis