How to use the turf.lineDistance 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 mapbox / osm-building-shapes / map.js View on Github external
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));

                // shape factor = (4 * PI * area) / (perimeter^2) http://www.empix.com/NE%20HELP/functions/glossary/morphometric_param.htm
                props.shape = parseFloat(((((Math.PI * 4 * props.area) / ((props.perimeter)*(props.perimeter))) * 100)).toFixed(3));
                val.properties = props;

                // Make it a real polygon
                val.geometry.type = 'Polygon';
                val.geometry.coordinates = [val.geometry.coordinates];
                return true;
            }
        }
    });
github mapbox / osm-sidewalker / sidewalker.js View on Github external
segments.features.forEach(function (segment) {
      // found a case where the original linestring is a single coordinate, not wrapped in an array
      if (segment.geometry.coordinates.length < 2 || !segment.geometry.coordinates[0].length) return;
      // skip short little segments
      if (turf.lineDistance(segment, 'miles') <= 10/5280) return;

      var segmented = lineChunk(segment, 250/5280, 'miles');
      
      segmented.features.forEach(function (seg) {
        if (turf.lineDistance(seg, 'miles') <= 150/5280) return;
        
        // Get bisectors fo this segment, and match it against 
        // each road. 
        var bisectors = buildBisectors(seg);
        var isMatched = false;

        var bisectBox = turf.extent(turf.featurecollection(bisectors));
        var maybeCollides = roadIndex.search(bisectBox);

        maybeCollides.forEach(function (maybe) {
          var road = roads[maybe[4].road_id];
github osmlab / osmlint / validators / Digiroad / map.js View on Github external
var centroidPt = turf.centroid(bboxPolygon);
  var tilePoly = cover.geojson(centroidPt.geometry, limits);
  var newtile = cover.tiles(centroidPt.geometry, limits);
  // digiroad
  for (var i = 0; i < diffLayer.features.length; i++) {
    var val = diffLayer.features[i];
    if (val.geometry.type == 'LineString') {
      var dist = turf.lineDistance(val, 'kilometers');
      resultDiffLayer = resultDiffLayer + dist;
    }
  }
  //digiroad layer
  for (var i = 0; i < digiroadLayer.features.length; i++) {
    var val = digiroadLayer.features[i];
    if (val.geometry.type == 'LineString') {
      var dist = turf.lineDistance(val, 'kilometers');
      resultdDigiLayer = resultdDigiLayer + dist;
    }
  }
  tilePoly.features[0].properties.id = newtile.join().replace(/,/g, '');
  tilePoly.features[0].properties.diffNum = diffLayer.features.length;
  tilePoly.features[0].properties.digiNum = digiroadLayer.features.length;
  tilePoly.features[0].properties.diffKil = Number(resultDiffLayer.toFixed(2));
  tilePoly.features[0].properties.digiKil = Number(resultdDigiLayer.toFixed(2));
  tilePoly.features[0].properties.diffPercentage = Number((resultDiffLayer * 100 / resultdDigiLayer).toFixed(2));
  writeData(JSON.stringify(tilePoly) + '\n');
  done(null, null);
};
github mapbox / osm-sidewalker / sidewalker.js View on Github external
segmented.features.forEach(function (seg) {
        if (turf.lineDistance(seg, 'miles') <= 150/5280) return;
        
        // Get bisectors fo this segment, and match it against 
        // each road. 
        var bisectors = buildBisectors(seg);
        var isMatched = false;

        var bisectBox = turf.extent(turf.featurecollection(bisectors));
        var maybeCollides = roadIndex.search(bisectBox);

        maybeCollides.forEach(function (maybe) {
          var road = roads[maybe[4].road_id];
        
          if (isMatched || road.properties.layer !== footways[f].properties.layer) return;

          var matched = 0;
          bisectors.forEach(function (bisector) {
github mapbox / tile-reduce / test / miles / miles.js View on Github external
streets.features.forEach(function(feature) {
    if (streetTypes.indexOf(feature.properties['class']) > -1) {
      miles += turf.lineDistance(feature, 'miles');
    }
  });
github mapbox / mapping / utilities / road_length / road-length.js View on Github external
fs.readFile(args[0], 'utf8', function (err,data) {
  if (err) {return console.log(err);}
  var content = JSON.parse(data);
  var length = 0;
  for (var i = 0; i < content.features.length; i++) {
    if (content.features[i].geometry.type === "LineString") {
        var coords = content.features[i].geometry.coordinates;
        length += turf.lineDistance(content.features[i], 'kilometers');
    }
  }
  console.log(length);
});
github mapbox / cheap-ruler / bench / bench-distance.js View on Github external
'turf.lineDistance': function () {
        for (var i = 0; i < lines.length; i++) {
            turf.lineDistance(turf.linestring(lines[i]));
        }
    },
    'ruler.lineDistance': function () {
github frankrowe / iso / src / utils / VectorTools.js View on Github external
lines.forEach(function(line) {
      distance += turf.lineDistance(line, 'miles')
    })
    var msg = '<p>Length</p><p>' + numeral(distance).format('0.0000') + ' mi'</p>
github hotosm / osm-analytics / app / components / Stats / searchFeatures.js View on Github external
data.features = data.features.map(feature => {
      var centr = centroid(feature)
      centr.properties = feature.properties
      centr.properties._length = centr.properties._length ||
          centr.properties._lineDistance ||
          (feature.geometry.type === "LineString" ? lineDistance(feature, 'kilometers') : 0.0)
      return centr
    })
    cache[cachePage][tile.hash] = data