Last active
December 1, 2018 16:03
-
-
Save maptastik/666edc97efe75eb3c7fedfcd9c651d71 to your computer and use it in GitHub Desktop.
Iterate through polygon geojson and find number of points in each
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function countPointsInPolygons(points, polygonJson) { | |
let countsArray = []; | |
let polygonFeaturesArray = polygonJson.features; | |
for (let i = 0; i < polygonFeaturesArray.length; i++) { | |
let iGeometry = turf.polygon(polygonFeaturesArray[i].geometry.coordinates); | |
let pointsWithinPolygon = turf.pointsWithinPolygon(points, iGeometry); | |
iGeometry.properties.count = pointsWithinPolygon.features.length; | |
countsArray.push(iGeometry); | |
} | |
return turf.featureCollection(countsArray); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment