How to use the turf.point 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 funkeinteraktiv / cogran / lib / methods / areal-weighting-advanced.js View on Github external
intersects.forEach((d,i) => {
    const Ps = parseFloat(sourceFeatures[i].properties[attributeName]);
    //if(isNaN(Ps)) { return; }

    // wenn komplett im source feature,
    const sb = Turf.extent(sourceFeatures[i]);
    let isInside = true;
    if(!Turf.inside(Turf.point([sb[0], sb[1]]), d)) { isInside = false };
    if(!Turf.inside(Turf.point([sb[2], sb[3]]), d)) { isInside = false };

    if(isInside) {
      result += Ps;
      return;
    }

    const As = Turf.area(feature);
    const Ast = Turf.area(d);
    result += (Ast * Ps) / As;
  });
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 mapbox / tile-reduce / test / disconnect / disconnect.js View on Github external
flat2.forEach(function(line2) {
                  if (layer === layer2 && i == j) {
                    return;
                  }

                  for (var k = 0; !dup && k < line2.geometry.coordinates.length; k++) {
                    if (end[0] === line2.geometry.coordinates[k][0] && end[1] === line2.geometry.coordinates[k][1]) {
                      dup = true;
                    }
                  }
                });
              }
            }

            if (!dup) {
              caps.push({layer: layer, i: i, point: turf.point(end), line: line});
            }
          });
        }
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;

}
github jpwright / subway / tools / demanderator.js View on Github external
var overlap_polygon = turf.intersect(tract, square);
                            if (overlap_polygon != undefined) {
                                
                                var overlap_area = turf.area(overlap_polygon);
                                var tract_area = turf.area(tract);
                                if (ct2010 in populations) {
                                    d += populations[ct2010] * overlap_area/tract_area;
                                } else {
                                    d += 1000.0 * overlap_area/tract_area;
                                }
                            }
                            
                        }
                    }
                    
                    var voxel_center = turf.point([lon + voxels_res_lon/2.0, lat + voxels_res_lat/2.0]);
                    for (lpoi in landmark_polygons_of_interest) {
                        if (turf.inside(voxel_center, landmark_polygons_of_interest[lpoi])) {
                            console.log("Inside "+lpoi);
                            d += 500.0;
                        }
                    }
                    
                    
                    //console.log(d);
                    demand[i][j] = d;
                    //console.log("Finished voxel "+(j+(i*voxels_dim))+" of "+voxels_total);
                    bar.tick();
                    if (bar.complete) {
                        console.log('complete!');
                    }
                }
github probr / probr-analysis / worker / components / location / location.foreach.js View on Github external
function locationToCircle(loc, multiplier) {
      var point = turf.point([loc.long,loc.lat]);
      var distance = signalToMeters(loc.weightedSignal, multiplier);

      var coordinates = [];
      for (var i=0; i<=360; i+=10) {
        coordinates.push( turf.destination(point, distance/1000, i, 'kilometers').geometry.coordinates );
      }
      var poly = turf.polygon([coordinates]);
      return poly;
    }
github kepta / idly / packages / idly / src / map / utils / nodeToFeat.ts View on Github external
function _nodeToFeat(n: any): NodeFeature {
  if (n instanceof Node) {
    const match =
      n.geometry === Geometry.POINT
        ? presetMatchPoint(n.tags)
        : presetMatchVertex(n.tags);

    const properties: INodeProperties = {
      node_properties: JSON.stringify(n.properties),
      tags: JSON.stringify(n.tags),
      id: n.id,
      icon: (match && match.icon) || 'circle',
      name: n.tags.get('name'),
      geometry: n.geometry
    };
    const feat = turf.point([n.loc.lon, n.loc.lat], properties) as Feature<
      Point,
      INodeProperties
    >;
    feat.id = n.id;
    return feat;
  }
}
github mapbox / cheap-ruler / bench / bench-line-slice.js View on Github external
'turf.lineSlice': function () {
        for (var i = 0; i < lines.length; i++) {
            turf.lineSlice(
                turf.point(endpoints[i].start),
                turf.point(endpoints[i].stop),
                turf.linestring(lines[i]));
        }
    },
    'ruler.lineSlice': function () {
github mapbox / cheap-ruler / bench / bench-line-slice.js View on Github external
'turf.lineSlice': function () {
        for (var i = 0; i < lines.length; i++) {
            turf.lineSlice(
                turf.point(endpoints[i].start),
                turf.point(endpoints[i].stop),
                turf.linestring(lines[i]));
        }
    },
    'ruler.lineSlice': function () {
github osmlab / osmlint / processors / duplicated-nodes / duplicated-nodes.js View on Github external
_.each(nodes, function(v) {
            result.features.push(turf.point(v));
        });
    }