How to use the @turf/points-within-polygon function in @turf/points-within-polygon

To help you get started, we’ve selected a few @turf/points-within-polygon 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 mapseed / platform / src / base / static / utils / geo.js View on Github external
const aggregatePointsInBuffer = ({ placeGeometry, targetFeatures, config }) => {
  const bufferFeature = getBufferFeature(placeGeometry, config.buffer);

  if (!bufferFeature) {
    return {};
  }

  let pointsWithin;
  try {
    pointsWithin = pointsWithinPolygon(
      featureCollection(targetFeatures),
      bufferFeature,
    );
  } catch (e) {
    // eslint-disable-next-line no-console
    console.error("ERROR!", e);
    Mixpanel.track("Error", {
      message: "unable to perform pointsWithinPolygon on features",
      error: e,
    });

    pointsWithin = featureCollection([]); // Empty FeatureCollection.
  }

  if (config.aggregator.type === "totalCount") {
    return {
github Turfjs / turf / packages / turf-kernel_density / index.js View on Github external
featureEach(output, current => {
        let
            area = buffer(current, sr),
            ptsWithin = pointsWithinPolygon(output, area);
        // the initial value of -1 is on purpose to disregard the point itself.
        current.properties.kernelDensity = featureReduce(ptsWithin, prev => prev + 1, -1);
    });
    return output;
github sanity-io / sanity / packages / test-studio / schemas / validation.js View on Github external
Rule.required().custom(geoPoint => {
          if (!geoPoint) {
            return true
          }

          const location = points([[geoPoint.lng, geoPoint.lat]])
          const norwayFeature = featureCollection(norway)
          const ptsWithin = pointsWithinPolygon(location, norwayFeature)
          return ptsWithin.features.length > 0 ? true : 'Location must be in Norway'
        })
    },
github sanity-io / sanity / packages / backstop-test-studio / schemas / validation.js View on Github external
Rule.required().custom(geoPoint => {
          if (!geoPoint) {
            return true
          }

          const location = points([[geoPoint.lng, geoPoint.lat]])
          const norwayFeature = featureCollection(norway)
          const ptsWithin = pointsWithinPolygon(location, norwayFeature)
          return ptsWithin.features.length > 0 ? true : 'Location must be in Norway'
        })
    },
github Turfjs / turf / packages / turf-standard-deviational-ellipse / index.js View on Github external
sigmaY = radiansToLength(degreesToRadians(sigmaY));

    theta = radiansToDegrees(theta);
    var semiMajorAxis, semiMinorAxis;
    if (sigmaX > sigmaY) {
      semiMajorAxis = sigmaX;
      semiMinorAxis = sigmaY;
    } else {
      semiMinorAxis = sigmaX;
      semiMajorAxis = sigmaY;
      theta = theta - 90;
    }

    var theEllipse = ellipse(meanCenter, semiMajorAxis, semiMinorAxis, {angle: theta, steps: steps, properties: properties});
    var eccentricity = (Math.sqrt(Math.pow(semiMajorAxis, 2) - Math.pow(semiMinorAxis, 2))) / semiMajorAxis;
    var pointsWithinEllipse = pointsWithinPolygon(points, turf.featureCollection([theEllipse]));
    var standardDeviationalEllipseProperties = {
        meanCenterCoordinates: getCoord(theMeanCenter),
        semiMajorAxis: semiMajorAxis,
        semiMinorAxis: semiMinorAxis,
        angle: theta,
        eccentricity: eccentricity,
        pctWithinEllipse: 100 * turf.coordAll(pointsWithinEllipse).length / n
    };
    theEllipse.properties.standardDeviationalEllipse = standardDeviationalEllipseProperties;

    return theEllipse;
};

@turf/points-within-polygon

turf points-within-polygon module

MIT
Latest version published 4 months ago

Package Health Score

94 / 100
Full package analysis

Popular @turf/points-within-polygon functions