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

To help you get started, we’ve selected a few @turf/turf 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-laser-pointer / examples / demo-path / src / index.js View on Github external
//========
                // this was being used...
                // let mergedElevationPoly = turf.merge(
                //     turf.featureCollection(elevationPolys));
                //========
                // - turf.merge is deprecated, so...
                // - https://github.com/turf-junkyard/turf-merge
                //     This module is now deprecated in favor of using
                //     the turf-union module repeatedly on an array.
                // - https://gis.stackexchange.com/questions/243460/turf-js-union-with-array-of-features
                // console.log('feat collection:', turf.featureCollection(elevationPolys));
                let mergedElevationPoly = turf.union.apply(
                    this, turf.featureCollection(elevationPolys).features);

                // trim to desired search area
                mergedElevationPoly = turf.intersect(
                    polygon, mergedElevationPoly);

                if (mergedElevationPoly) {
                    let contourArea = turf.area(mergedElevationPoly.geometry);
                    // FIXME: ???????? ???????? ???????? ????????
                    // L.mapbox.featureLayer().setGeoJSON(mergedElevationPoly).addTo(map);

                    contours.push({
                        'geometry': mergedElevationPoly,
                        'ele': currentElevation,
                        'area': contourArea,
                    });
                }
            } catch (error) { // on merge fail, insert the previous contour again and skip
                console.log('merge failed at elevation '+currentElevation);
                console.log(error.message);
github kurisubrooks / sherlock / modules / api / fire / main.js View on Github external
results.push(final);
        };

        // Each filter
        for (let filterFeature of filter.features) {
            try {
                let geometry = filterFeature.geometry;
                let filter = geometry.type === "Point" ? turf.circle(geometry, geometry.properties.radius) : geometry;

                // Each incident
                for (let feature of incidents.features) {
                    let geometry = feature.geometry;

                    // filter results to overlapping regions
                    let result = turf.intersect(filter, geometry.type === "Point" ? turf.circle(geometry, radius) : geometry.geometries[1].geometries[0]);

                    // if match
                    if (result !== undefined) format(feature);
                }
            } catch(error) {
                res.status(500).send({ ok: false, code: 500, error: "Internal Server Error" });
                console.error(error);
                break;
            }
        }

        // Sort results by HIGH→LOW warning levels
        // then sort by Distance from Home
        results.sort((a, b) => {
            let home = ["-33.746", "150.7123"];
github farmOS / farmOS-client / src / client / store / geoModule.js View on Github external
});
        } else {
          geoJSON.push(parsePoly(geometry.slice(10, -2)));
        }
        return geoJSON;
      }

      const geometry = params.area.geofield[0].geom;
      const geomJSON = geoJSONify(geometry);

      // Now I'll check whether the point is inside the polygon (isInside)
      // OR if the point is within [radius] km of the polygon border (isNear)
      const circle = turf.circle(params.point, params.radius, { units: 'kilometers' });
      const polygon = turf.polygon(geomJSON);
      const isInside = turf.inside(params.point, polygon);
      const isNear = turf.intersect(circle, polygon) !== null;
      if (isInside || isNear) {
        commit('addLocalArea', params.area);
      }
    },
  },
github kurisubrooks / sherlock2 / api / georfs / fires.js View on Github external
}

    for (const feature of filters.filter.features) {
      try {
        const geometry = feature.geometry;
        const filter = geometry.type === 'Point'
          ? turf.circle(geometry, geometry.properties.radius)
          : geometry;

        // Each incident
        for (const feature of incidents.features) {
          const geometry = feature.geometry;

          // Filter Results for Overlapping Regions
          try {
            const result = turf.intersect(filter, geometry.type === 'Point'
              ? turf.circle(geometry, radius)
              : geometry.geometries[1].geometries[0]);

            // Match
            if (result !== undefined) {
              const formatted = this.format(feature);
              if (formatted) results.push(formatted); // eslint-disable-line max-depth
            }
          } catch(error) {
            console.log(error.message);
            ++missing;
            continue;
          }
        }
      } catch(error) {
        res.status(500).send({ ok: false, error: 'Internal Server Error' });
github cswbrian / district-councils-dashboard / web / src / data / overlap.js View on Github external
feature2.features.forEach(feature2 => {
    let poly2 = turf.polygon(feature2.geometry.coordinates)
    const kinks2 = turf.kinks(poly2)
    poly2 = (typeof kinks2 !== 'undefined' && jsts_validate(poly2)) || poly2
    if (turf.booleanOverlap(poly1, poly2)) {
      let intersection
      try {
        intersection = turf.intersect(poly1, poly2)
      } catch (e) {
        if (
          e &&
          e.message &&
          e.message.includes('found non-noded intersection between')
        ) {
          console.log(`${feature1.properties.CACODE} ,self-intersection`)
        }
      } finally {
        if (intersection && intersection.geometry.coordinates) {
          const area = turf.area(intersection)
          if (area > 0) {
            result.push({
              code: feature2.properties.CACODE,
              area,
            })
github hotosm / tasking-manager / frontend / src / components / projectCreate / setTaskSizes.js View on Github external
taskGrid.features.forEach(f => {
    let poly = turf.polygon(f.geometry.coordinates[0]);
    let contains = turf.intersect(geom, poly);
    if (contains === null) {
      newTaskGrid.push(f);
    } else {
      const splitGrid = makeGrid(f, f.properties.zoom + 1, {});
      splitGrid.features.forEach(g => {
        newTaskGrid.push(g);
      });
    }
  });
github osmlab / osmlint / validators / crossingBuildings / map.js View on Github external
multiPt.properties._fromWay = val.properties['@id'];
        //save detection
        output[val.properties['@id']] = val;
        output[val.properties['@id'] + 'M'] = multiPt;
      }
    }
  }
  var buildingTraceTree = rbush(bboxes.length);
  buildingTraceTree.load(bboxes);
  for (var z = 0; z < bboxes.length; z++) {
    var bbox = bboxes[z];
    var overlaps = buildingTraceTree.search(bbox);
    for (var k = 0; k < overlaps.length; k++) {
      var overlap = overlaps[k];
      if (overlap.id !== bbox.id) {
        var intersect = turf.intersect(
          buildings[overlap.id],
          buildings[bbox.id]
        );
        if (
          intersect &&
          (intersect.geometry.type === 'Polygon' ||
            intersect.geometry.type === 'MultiPolygon')
        ) {
          var area = turf.area(intersect);
          if (area > overlapArea) {
            var buildingA = buildings[overlap.id];
            buildingA.properties._osmlint = osmlint;
            var buildingB = buildings[bbox.id];
            buildingB.properties._osmlint = osmlint;
            var points = turf.explode(intersect);
            var multiPoint = turf.combine(points).features[0];
github code4history / Maplat / editor / lib / mapedit.js View on Github external
['forw', 'bakw'].map(function(dir) {
            var result = turf.intersect(searchResult[0][dir], searchResult[1][dir]);
            if (!result || result.geometry.type == 'Point' || result.geometry.type == 'LineString') return;
            if (!prev[dir]) prev[dir] = {};
            try {
                var diff1 = turf.difference(searchResult[0][dir], result);
                var diff2 = turf.difference(searchResult[1][dir], result);
                if (!diff1 || !diff2) {
                    prev[dir][key] = 'Include case';
                } else {
                    prev[dir][key] = 'Not include case';
                }
            } catch(e) {
                prev[dir][key] = 'Not include case';
            }
        });
        return prev;