How to use @turf/points-within-polygon - 6 common examples

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;
};
github PieceMaker / max-inscribed-circle / max-inscribed-circle.js View on Github external
vertices.features.push({
            type: "Feature",
            properties: {},
            geometry: {
                type: "Point",
                coordinates: [diagram.vertices[i].x, diagram.vertices[i].y]
            }
        })
    }
    vertices.features.push(centroid(polygon));
    //within requires a FeatureCollection for input polygons
    const polygonFeatureCollection = {
        type: "FeatureCollection",
        features: [polygon]
    };
    const ptsWithin = within(vertices, polygonFeatureCollection); //remove any vertices that are not inside the polygon
    if(ptsWithin.features.length === 0) {
        throw new NoPointsInShapeError('Neither the centroid nor any Voronoi vertices intersect the shape.');
    }
    const labelLocation = {
        coordinates: [0,0],
        maxDist: 0
    };
    const polygonBoundaries = {
        type: "FeatureCollection",
        features: []
    };
    let vertexDistance;

    //define borders of polygon and holes as LineStrings
    for(let j = 0; j < polygon.geometry.coordinates.length; j++) {
        polygonBoundaries.features.push({

@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