Created
January 27, 2021 15:52
-
-
Save nautilytics/a31294075da9392854b493213ddd9f7a to your computer and use it in GitHub Desktop.
Use turf.js to find all CharityNavigator services within a 50-mile radius/buffer of a city
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
import * as turf from '@turf/turf'; | |
// Create a FeatureCollection from all of the resources | |
const featureCollection = turf.featureCollection(resources.features); | |
// Get the lat/long of the selected feature | |
const point = turf.point(rows.length ? rows[0]?.geometry?.coordinates : [0, 0]); | |
// Create a 50-mile buffer around the selected point | |
const buffered = turf.buffer(point, 50, { units: 'miles' }); | |
// Find all resource w/in the 50-mile buffer | |
const resourcesWithinBuffer = turf.pointsWithinPolygon(featureCollection, buffered); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment