Socket
Socket
Sign inDemoInstall

turf-along

Package Overview
Dependencies
Maintainers
7
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

turf-along - npm Package Compare versions

Comparing version 1.0.2 to 3.0.0-canary.2f5f7167

14

bench.js

@@ -6,7 +6,7 @@ var along = require('./');

var line = {
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString",
"coordinates": [
type: "Feature",
properties: {},
geometry: {
type: "LineString",
coordinates: [
[

@@ -40,3 +40,3 @@ -77.0316696166992,

var route = JSON.parse(fs.readFileSync(__dirname + '/fixtures/route.geojson'));
var route = JSON.parse(fs.readFileSync(__dirname + '/test/fixtures/route.geojson'));

@@ -66,2 +66,2 @@ var suite = new Benchmark.Suite('turf-along');

})
.run();
.run();
var distance = require('turf-distance');
var point = require('turf-point');
var point = require('turf-helpers').point;
var bearing = require('turf-bearing');

@@ -7,10 +7,10 @@ var destination = require('turf-destination');

/**
* Takes a {@link LineString} feature and returns a {@link Point} feature at a specified distance along a line.
* Takes a {@link LineString|line} and returns a {@link Point|point} at a specified distance along the line.
*
* @module turf/along
* @name along
* @category measurement
* @param {LineString} line a LineString feature
* @param {Feature<LineString>} line input line
* @param {Number} distance distance along the line
* @param {String} [units=miles] can be degrees, radians, miles, or kilometers
* @return {Point} Point along the line at `distance` distance
* @return {Feature<Point>} Point `distance` `units` along the line
* @example

@@ -43,24 +43,23 @@ * var line = {

module.exports = function (line, dist, units) {
var coords;
if(line.type === 'Feature') coords = line.geometry.coordinates;
else if(line.type === 'LineString') coords = line.geometry.coordinates;
else throw new Error('input must be a LineString Feature or Geometry');
var coords;
if (line.type === 'Feature') coords = line.geometry.coordinates;
else if (line.type === 'LineString') coords = line.geometry.coordinates;
else throw new Error('input must be a LineString Feature or Geometry');
var travelled = 0;
for(var i = 0; i < coords.length; i++) {
if (dist >= travelled && i === coords.length - 1) break;
else if(travelled >= dist) {
var overshot = dist - travelled;
if(!overshot) return point(coords[i]);
else {
var direction = bearing(point(coords[i]), point(coords[i-1])) - 180;
var interpolated = destination(point(coords[i]), overshot, direction, units);
return interpolated;
}
var travelled = 0;
for (var i = 0; i < coords.length; i++) {
if (dist >= travelled && i === coords.length - 1) break;
else if (travelled >= dist) {
var overshot = dist - travelled;
if (!overshot) return point(coords[i]);
else {
var direction = bearing(coords[i], coords[i - 1]) - 180;
var interpolated = destination(coords[i], overshot, direction, units);
return interpolated;
}
} else {
travelled += distance(coords[i], coords[i + 1], units);
}
}
else {
travelled += distance(point(coords[i]), point(coords[i+1]), units);
}
}
return point(coords[coords.length - 1]);
}
return point(coords[coords.length - 1]);
};
{
"name": "turf-along",
"version": "1.0.2",
"version": "3.0.0-canary.2f5f7167",
"description": "",
"main": "index.js",
"scripts": {
"test": "node test.js",
"doc": "dox -r < index.js | doxme --readme > README.md"
"test": "node test.js"
},

@@ -30,12 +29,10 @@ "repository": {

"tape": "^3.5.0",
"turf-featurecollection": "^1.0.0",
"dox": "^0.6.1",
"doxme": "^1.4.3"
"turf-helpers": "^3.0.0-canary.2f5f7167"
},
"dependencies": {
"turf-bearing": "^1.0.0",
"turf-destination": "^1.2.0",
"turf-distance": "^1.0.0",
"turf-point": "^2.0.0"
"turf-bearing": "^3.0.0-canary.2f5f7167",
"turf-destination": "^3.0.0-canary.2f5f7167",
"turf-distance": "^3.0.0-canary.2f5f7167",
"turf-helpers": "^3.0.0-canary.2f5f7167"
}
}

@@ -8,5 +8,5 @@ # turf-along

### `turf.along(Line, Distance, [units=miles])`
### `turf.along(line, distance, [units=miles])`
Returns a point at a specified distance along a line.
Takes a LineString|line and returns a Point|point at a specified distance along the line.

@@ -16,7 +16,7 @@

| parameter | type | description |
| --------------- | ---------- | --------------------------------------------------------- |
| `Line` | LineString | to move along |
| `Distance` | Number | to move |
| `[units=miles]` | String | _optional:_ can be degrees, radians, miles, or kilometers |
| parameter | type | description |
| --------------- | ----------------------- | --------------------------------------------------------- |
| `line` | Feature\.\<LineString\> | input line |
| `distance` | Number | distance along the line |
| `[units=miles]` | String | _optional:_ can be degrees, radians, miles, or kilometers |

@@ -33,34 +33,25 @@

"coordinates": [
[
-77.0316696166992,
38.878605901789236
],
[
-77.02960968017578,
38.88194668656296
],
[
-77.02033996582031,
38.88408470638821
],
[
-77.02566146850586,
38.885821800123196
],
[
-77.02188491821289,
38.88956308852534
],
[
-77.01982498168944,
38.89236892551996
]
[-77.031669, 38.878605],
[-77.029609, 38.881946],
[-77.020339, 38.884084],
[-77.025661, 38.885821],
[-77.021884, 38.889563],
[-77.019824, 38.892368]
]
}
}
};
var along = turf.along(line, 1, 'miles');
//=along
var result = {
"type": "FeatureCollection",
"features": [line, along]
};
//=result
```
**Returns** `Feature.<Point>`, Point `distance` `units` along the line
## Installation

@@ -80,1 +71,2 @@

var test = require('tape');
var fs = require('fs');
var along = require('./');
var featurecollection = require('turf-featurecollection');
var point = require('turf-point');
var featurecollection = require('turf-helpers').featureCollection;
var line = JSON.parse(fs.readFileSync(__dirname + '/fixtures/dc-line.geojson'));
var line = JSON.parse(fs.readFileSync(__dirname + '/test/fixtures/dc-line.geojson'));

@@ -30,2 +29,2 @@ test('turf-along', function (t) {

t.end();
});
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc