How to use the @turf/turf.length function in @turf/turf

To help you get started, we’ve selected a few @turf/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 sharedstreets / trip-simulator / src / agent.js View on Github external
});

    const quadkey = this.simulation.chance.weighted(quadkeys, scores);
    const bbox = tilebelt.tileToBBOX(tilebelt.quadkeyToTile(quadkey));
    // select random destination within bbox
    var destination = [
      this.simulation.chance.longitude({ min: bbox[0], max: bbox[2] }),
      this.simulation.chance.latitude({ min: bbox[1], max: bbox[3] })
    ];
    // snap destination to graph
    destination = await this.simulation.snap(destination);
    // route from location to destination
    this.path = await this.simulation.route(this.location, destination);
    this.path.duration = this.path.duration * this.speed * 1000;
    this.path.line = turf.lineString(this.path.geometry.coordinates);
    this.path.distance = turf.length(this.path.line);
    this.start = this.simulation.time;
    this.next = this.simulation.time + this.path.duration;

    if (this.path.distance === 0) {
      return await this.route(range * 1.5);
    }

    if (this.traces) {
      fs.appendFileSync(
        this.traces,
        JSON.stringify(
          turf.lineString(
            this.path.line.geometry.coordinates.map(c => {
              return this.gps(c);
            }),
            { d: this.path.distance }
github peterqliu / threebox / src / Layers / SymbolLayer3D.js View on Github external
}

            obj.rotation.copy(rotation);    

            // prepare followPath animation
            var fp = f.geojson.properties.followPath;

            var newTransition = fp && !fp.expires
            var expiredTransition = fp && fp.expires > Date.now();

            if (newTransition){
                //if set to animate along path, prep that object
                f.geojson.properties.followPath.start = Date.now();
                f.geojson.properties.followPath.expiration = Date.now() + fp.duration;
                f.geojson.properties.followPath.geometry = fp.path;
                f.geojson.properties.followPath.distancePerMs = turf.length(fp.path) / fp.duration;
            
                var animationEntry = {
                    type: 'followPath',
                    parameters: f.geojson.properties.followPath
                }
                obj.rotation.copy(rotation);

                obj.animationQueue.push(animationEntry)
            }

            else if (expiredTransition) delete f.properties.followPath;



        }
    }
github DoFabien / OsmGo / src / services / osmApi.service.ts View on Github external
let geom;
                    switch (feature.geometry.type) {
                        case 'Polygon':
                            feature.properties['mesure'] = area(feature.geometry)
                            geom = polygon(feature.geometry.coordinates);
                            break;
                        case 'MultiPolygon':
                            feature.properties['mesure'] = area(feature.geometry)
                            geom = multiPolygon(feature.geometry.coordinates);
                            break;
                        case 'LineString':
                            feature.properties['mesure'] = length(feature.geometry)
                            geom = lineString(feature.geometry.coordinates);
                            break;
                        case 'MultiLineString':
                            feature.properties['mesure'] = length(feature.geometry)
                            geom = multiLineString(feature.geometry.coordinates);
                            break;
                    }

                    if (geom) {
                        feature.geometry.coordinates = pointOnSurface(geom).geometry.coordinates;
                        feature.geometry.type = 'Point';
                    }
                }
            }
        }
        return FeatureCollection;
    }
} // EOF Services
github heremaps / here-cli / src / here-xyz.ts View on Github external
let gisFeature;
    if(options.centroid){
        if(feature.geometry && (feature.geometry.type == 'LineString' || feature.geometry.type == 'Polygon' || feature.geometry.type == 'MultiLineString' || feature.geometry.type == 'MultiPolygon')){
            gisFeature = turf.centroid(feature, feature.properties);
            if(options.samespace){
                if(!gisFeature.properties){
                    gisFeature.properties = {};
                }
                gisFeature.properties.sourceId = feature.id;
            } else {
                gisFeature.id = feature.id;
            }
        }
    } else if(options['length']){
        if(feature.geometry && (feature.geometry.type == 'LineString' || feature.geometry.type == 'MultiLineString')){
            let length = turf.length(feature, {units: 'meters'});
            if(!feature.properties){
                feature.properties = {};
            }
            feature.properties['xyz_length_m'] = length;
            feature.properties['xyz_length_km'] = (length / 1000).toFixed(2);
            feature.properties['xyz_length_miles'] = (length * 0.000621371).toFixed(2);
            gisFeature = feature; 
        }
    } else if(options.area){
        if(feature.geometry && (feature.geometry.type == 'Polygon' || feature.geometry.type == 'MultiPolygon')){
            gisFeature = populateArea(feature); 
        }
    } else {
        console.log("Please specify GIS operation option");
        process.exit(1);
    }
github Googer / Professor-Pine / app / map.js View on Github external
        results.sort((a, b) => turf.length(b) - turf.length(a));
      } else {
github brendannee / bikesy / lib / map.js View on Github external
export function getPathDistance(path) {
  return turf.length(path, {units: 'miles'});
}
github sharedstreets / trip-simulator / index.js View on Github external
(err, result) => {
            if (!err && result.routes[0]) {
              var overview = turf.lineString(
                result.routes[0].geometry.coordinates
              );
              var distance = turf.length(overview);
              var duration = result.routes[0].duration;
              if (distance > 0) {
                var trip = [];
                var timestamps = [];
                var playback = 0;
                var periodBias = normal() * 5;
                if (periodBias < 1) periodBias = 1;
                var driftBias = normal();

                while (playback <= duration) {
                  var step = normal() * PERIOD * periodBias;
                  if (step < 0) step = step * -1;
                  playback += step;
                  var progress = playback / duration;
                  var probe = turf.destination(
                    turf.along(overview, progress / distance),