How to use the @turf/intersect function in @turf/intersect

To help you get started, we’ve selected a few @turf/intersect 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 w3reality / three-geo / src / index.js View on Github external
// console.log(`getContours(): ${x}/${eleList.length}`);
            let currentElevation = eleList[x];
            let elevationPolys = geojson.features.filter((feature) => {
                return feature.properties.ele === currentElevation;
            });

            try { // merge between tiles
                let feats = turfHelpers.featureCollection(elevationPolys).features;
                // console.log(currentElevation, feats.length, feats);
                // feats.forEach(feat => { console.log('type:', feat.geometry.type); }); // 'Polygon'

                let mergedElevationPoly = feats.reduce(((accm, feat) => turfUnion(accm, feat)), feats[0]);
                // console.log('@@@', mergedElevationPoly, currentElevation);

                if (0) { // trim to desired search area
                    mergedElevationPoly = turfIntersect( // use module version instead
                        polygon, mergedElevationPoly);
                    // console.log('@@@', polygon);
                }

                // console.log('@@@mergedElevationPoly:', mergedElevationPoly);
                if (mergedElevationPoly) {
                    // console.log('@@@merge success', currentElevation);
                    let contourArea = turfArea(mergedElevationPoly.geometry);
                    // L.mapbox.featureLayer().setGeoJSON(mergedElevationPoly).addTo(map);

                    contours.push({
                        'geometry': mergedElevationPoly,
                        'ele': currentElevation,
                        'area': contourArea,
                    });
                }
github uber / nebula.gl / modules / edit-modes / src / lib / geojson-edit-mode.js View on Github external
);
        return null;
      }

      const feature = {
        type: 'Feature',
        geometry
      };

      let updatedGeometry;
      if (modeConfig.booleanOperation === 'union') {
        updatedGeometry = turfUnion(selectedFeature, feature);
      } else if (modeConfig.booleanOperation === 'difference') {
        updatedGeometry = turfDifference(selectedFeature, feature);
      } else if (modeConfig.booleanOperation === 'intersection') {
        updatedGeometry = turfIntersect(selectedFeature, feature);
      } else {
        // eslint-disable-next-line no-console,no-undef
        console.warn(`Invalid booleanOperation ${modeConfig.booleanOperation}`);
        return null;
      }

      if (!updatedGeometry) {
        // eslint-disable-next-line no-console,no-undef
        console.warn('Canceling edit. Boolean operation erased entire polygon.');
        return null;
      }

      const featureIndex = props.selectedIndexes[0];

      const updatedData = new ImmutableFeatureCollection(props.data)
        .replaceGeometry(featureIndex, updatedGeometry.geometry)
github uber / nebula.gl / modules / layers / src / mode-handlers / mode-handler.js View on Github external
);
        return null;
      }

      const feature = {
        type: 'Feature',
        geometry
      };

      let updatedGeometry;
      if (modeConfig.booleanOperation === 'union') {
        updatedGeometry = turfUnion(selectedFeature, feature);
      } else if (modeConfig.booleanOperation === 'difference') {
        updatedGeometry = turfDifference(selectedFeature, feature);
      } else if (modeConfig.booleanOperation === 'intersection') {
        updatedGeometry = turfIntersect(selectedFeature, feature);
      } else {
        // eslint-disable-next-line no-console,no-undef
        console.warn(`Invalid booleanOperation ${modeConfig.booleanOperation}`);
        return null;
      }

      if (!updatedGeometry) {
        // eslint-disable-next-line no-console,no-undef
        console.warn('Canceling edit. Boolean operation erased entire polygon.');
        return null;
      }

      const featureIndex = this.getSelectedFeatureIndexes()[0];

      const updatedData = this.getImmutableFeatureCollection()
        .replaceGeometry(featureIndex, updatedGeometry.geometry)
github terrestris / ol-util / src / GeometryUtil / GeometryUtil.js View on Github external
featureEach(polygonizedUnionGeom, cuttedSection => {
        // checks to see if segment is in polygon
        const segmentInPolygon = intersect(cuttedSection, outerPolygon);
        if (segmentInPolygon && segmentInPolygon.geometry.type === 'Polygon') {
          let polygonWithoutHoles = [];
          if (innerPolygon.features.length > 0) {
            // iterates over all the holes and removes their intersection with the cutted polygon
            innerPolygon.features.forEach(holes => {
              const toCut = polygonWithoutHoles.length > 0 ? polygonWithoutHoles : [segmentInPolygon];
              toCut.forEach((tocutPart, i) => {
                let intersection = difference(tocutPart, holes);
                if (intersection && (intersection.geometry.type === 'Polygon' || intersection.geometry.type === 'MultiPolygon')) {
                  if (intersection.geometry.type === 'MultiPolygon') {
                    intersection.geometry.coordinates.forEach(intersectPolyCoords => {
                      polygonWithoutHoles.push(makePolygon(intersectPolyCoords));
                    });
                  } else {
                    polygonWithoutHoles[i] = intersection;
                  }
github WorldBank-Transport / ram-backend / __converter / app / calculate-eta / index.js View on Github external
var squareTasks = squares.map(square => {
    // Clip the square with the input geometry. In this way we work with a
    // smaller area..
    let workArea = intersect(adminArea, square);
    return createProcessAreaTask(workArea, poiByType, villages, osrm, maxTime, maxSpeed, id);
  });
github Turfjs / turf / packages / turf-hex-grid / index.ts View on Github external
sines).forEach(function (triangle) {
                    if (options.mask) {
                        if (intersect(options.mask, triangle)) results.push(triangle);
                    } else {
                        results.push(triangle);
                    }
                });
            } else {
github Turfjs / turf / packages / turf-triangle-grid / index.ts View on Github external
cellTriangle1 = polygon([[
                    [currentX, currentY],
                    [currentX, currentY + cellHeight],
                    [currentX + cellWidth, currentY],
                    [currentX, currentY]
                ]], options.properties);
                cellTriangle2 = polygon([[
                    [currentX, currentY + cellHeight],
                    [currentX + cellWidth, currentY + cellHeight],
                    [currentX + cellWidth, currentY],
                    [currentX, currentY + cellHeight]
                ]], options.properties);
            }
            if (options.mask) {
                if (intersect(options.mask, cellTriangle1)) results.push(cellTriangle1);
                if (intersect(options.mask, cellTriangle2)) results.push(cellTriangle2);
            } else {
                results.push(cellTriangle1);
                results.push(cellTriangle2);
            }

            currentY += cellHeight;
            yi++;
        }
        xi++;
        currentX += cellWidth;
    }
    return featureCollection(results);
}
github Turfjs / turf / packages / turf-triangle-grid / index.ts View on Github external
} else if (yi % 2 === 1 && xi % 2 === 1) {
                cellTriangle1 = polygon([[
                    [currentX, currentY],
                    [currentX, currentY + cellHeight],
                    [currentX + cellWidth, currentY],
                    [currentX, currentY]
                ]], options.properties);
                cellTriangle2 = polygon([[
                    [currentX, currentY + cellHeight],
                    [currentX + cellWidth, currentY + cellHeight],
                    [currentX + cellWidth, currentY],
                    [currentX, currentY + cellHeight]
                ]], options.properties);
            }
            if (options.mask) {
                if (intersect(options.mask, cellTriangle1)) results.push(cellTriangle1);
                if (intersect(options.mask, cellTriangle2)) results.push(cellTriangle2);
            } else {
                results.push(cellTriangle1);
                results.push(cellTriangle2);
            }

            currentY += cellHeight;
            yi++;
        }
        xi++;
        currentX += cellWidth;
    }
    return featureCollection(results);
}
github Turfjs / turf / packages / turf-hex-grid / index.ts View on Github external
if (intersect(options.mask, triangle)) results.push(triangle);
                    } else {
                        results.push(triangle);
                    }
                });
            } else {
                var hex = hexagon(
                    [center_x, center_y],
                    cellWidth / 2,
                    cellHeight / 2,
                    options.properties,
                    cosines,
                    sines
                );
                if (options.mask) {
                    if (intersect(options.mask, hex)) results.push(hex);
                } else {
                    results.push(hex);
                }
            }
        }
    }

    return featureCollection(results);
}

@turf/intersect

turf intersect module

MIT
Latest version published 3 months ago

Package Health Score

96 / 100
Full package analysis

Popular @turf/intersect functions