Skip to content

Instantly share code, notes, and snippets.

@nautilytics
Created January 27, 2021 15:52
Show Gist options
  • Save nautilytics/a31294075da9392854b493213ddd9f7a to your computer and use it in GitHub Desktop.
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
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