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;
};