How to use the turf.within function in turf

To help you get started, we’ve selected a few turf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github codeforanchorage / realtime-bus-sms / lib / index.js View on Github external
function findNearestStops(lat, lon) {
    var point = turf.point([lon, lat]);
    var buffer = turf.buffer(point, config.NEAREST_BUFFER, 'miles');
    var nearest_stops = turf.within(gtfs.all_stops, buffer);
    var out = nearest_stops.features.map(function(stop){
        var stopId = stop.properties.stop_id.match(/\d+/g)[0];
        return { route: stop.properties.name,
                 stopId: stopId,
                 distance: turf.distance(point, stop, "miles"),
                 ll: stopLatLong(stopId)
        }
    });
    // returns empty if none found nearby
    out.sort(function(a, b) {
        return (a.distance - b.distance)
    });
    if (out.length > config.NEAREST_MAX) out = out.slice(0,config.NEAREST_MAX);
    return out;
}
github hotosm / osm-analytics / app / components / Stats / searchBuiltupAreas.js View on Github external
tiles.forEach(tile => {
      output = output.concat(
        within(cache[cachePage][tile.hash], regionFc).features
      )
    })
    // todo: handle tile boundaries / split features (merge features with same osm id)
github mapbox / osm-building-shapes / map.js View on Github external
var buildings = layer.features.filter(function(val) {
        if (val.properties.building && val.geometry.type === 'Polygon') {
            var flag = 0;
            var buildingPoints = turf.explode(val);
            var pointsWithin = turf.within(buildingPoints, buffer);
            if (!pointsWithin.features.length) {

                var props = {
                    "_osm_way_id": val.properties._osm_way_id,
                    "building": val.properties.building,
                };

                //area in m^2
                props.area = parseFloat((turf.area(val)).toFixed(3));

                // Convert the polygon to a line to find perimeter
                val.geometry.type = 'LineString';
                val.geometry.coordinates = val.geometry.coordinates[0];
                // perimeter in meter
                props.perimeter = parseFloat(((turf.lineDistance(val,'kilometers') * 1000)).toFixed(3));
github hotosm / osm-analytics / app / components / Stats / searchFeatures.js View on Github external
tiles.forEach(tile => {
      output = output.concat(
        within(cache[cachePage][tile.hash], regionFc).features
      )
    })
    // todo: handle tile boundaries / split features (merge features with same osm id)
github WorldBank-Transport / ram-backend / scripts / node / isochroneservice.js View on Github external
function villagesInCircle(center,time,maxspeed) {

	var centerPt = turf.point([center[0],center[1]]);
	var length = (time/3600)*maxspeed;
	var circle = turf.buffer(centerPt,length,'kilometers');
	var result = turf.within(villages,circle);
	console.log(result.features.length +' villages within max distance')
	return result;

}