Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 {
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;
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'
})
},
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'
})
},
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;
};
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({