diff --git a/packages/turf-nearest-point-to-line/LICENSE b/packages/turf-nearest-point-to-line/LICENSE
new file mode 100644
index 0000000000..96ce51b76f
--- /dev/null
+++ b/packages/turf-nearest-point-to-line/LICENSE
@@ -0,0 +1,20 @@
+The MIT License (MIT)
+
+Copyright (c) 2017 TurfJS
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/packages/turf-nearest-point-to-line/README.md b/packages/turf-nearest-point-to-line/README.md
new file mode 100644
index 0000000000..009add3109
--- /dev/null
+++ b/packages/turf-nearest-point-to-line/README.md
@@ -0,0 +1,51 @@
+# @turf/nearest-point-to-line
+
+# nearestPointToLine
+
+Returns the closest [point](http://geojson.org/geojson-spec.html#point), of a [collection](http://geojson.org/geojson-spec.html#feature-collection-objects) of points, to a [line](http://geojson.org/geojson-spec.html#linestring).
+The returned point has a `dist` property indicating its distance to the line.
+
+**Parameters**
+
+- `points` **([FeatureCollection](http://geojson.org/geojson-spec.html#feature-collection-objects) \| [GeometryCollection](http://geojson.org/geojson-spec.html#geometrycollection)<[Point](http://geojson.org/geojson-spec.html#point)>)** Point Collection
+- `line` **([Feature](http://geojson.org/geojson-spec.html#feature-objects) \| [Geometry](http://geojson.org/geojson-spec.html#geometry)<[LineString](http://geojson.org/geojson-spec.html#linestring)>)** Line Feature
+- `units` **\[[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** unit of the output distance property, can be degrees, radians, miles, or kilometer (optional, default `kilometers`)
+
+**Examples**
+
+```javascript
+var points = featureCollection([point([0, 0]), point([0.5, 0.5])]);
+var line = lineString([[1,1], [-1,1]]);
+
+var nearest = turf.nearestPointToLine(points, line);
+
+//addToMap
+var addToMap = [nearest, line];
+```
+
+Returns **[Feature](http://geojson.org/geojson-spec.html#feature-objects)<[Point](http://geojson.org/geojson-spec.html#point)>** the closest point
+
+
+
+---
+
+This module is part of the [Turfjs project](http://turfjs.org/), an open source
+module collection dedicated to geographic algorithms. It is maintained in the
+[Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
+PRs and issues.
+
+### Installation
+
+Install this module individually:
+
+```sh
+$ npm install @turf/nearest-point-to-line
+```
+
+Or install the Turf module that includes it as a function:
+
+```sh
+$ npm install @turf/turf
+```
diff --git a/packages/turf-nearest-point-to-line/bench.js b/packages/turf-nearest-point-to-line/bench.js
new file mode 100644
index 0000000000..1ad5026c41
--- /dev/null
+++ b/packages/turf-nearest-point-to-line/bench.js
@@ -0,0 +1,36 @@
+const path = require('path');
+const glob = require('glob');
+const load = require('load-json-file');
+const Benchmark = require('benchmark');
+const nearestPointToLine = require('./');
+
+/**
+ * Benchmark Results
+ *
+ * fiji: 2.973ms
+ * on-line: 0.758ms
+ * one: 0.549ms
+ * resolute: 0.349ms
+ * two: 0.358ms
+ *
+ * fiji x 36,409 ops/sec ±4.14% (69 runs sampled)
+ * on-line x 14,044 ops/sec ±4.92% (69 runs sampled)
+ * one x 65,604 ops/sec ±11.55% (64 runs sampled)
+ * resolute x 44,962 ops/sec ±6.76% (67 runs sampled)
+ * two x 42,690 ops/sec ±2.34% (76 runs sampled)
+ */
+const suite = new Benchmark.Suite('turf-nearest-point-to-line');
+glob.sync(path.join(__dirname, 'test', 'in', '*.geojson')).forEach(filepath => {
+ const {name} = path.parse(filepath);
+ const geojson = load.sync(filepath);
+ const [points, line] = geojson.features;
+ console.time(name);
+ nearestPointToLine(points, line);
+ console.timeEnd(name);
+ suite.add(name, () => nearestPointToLine(points, line));
+});
+
+suite
+ .on('cycle', e => console.log(String(e.target)))
+ .on('complete', () => {})
+ .run();
diff --git a/packages/turf-nearest-point-to-line/index.d.ts b/packages/turf-nearest-point-to-line/index.d.ts
new file mode 100644
index 0000000000..0496d2a05e
--- /dev/null
+++ b/packages/turf-nearest-point-to-line/index.d.ts
@@ -0,0 +1,19 @@
+///
+
+import { Units, FeatureGeometryCollection } from '@turf/helpers'
+
+type Points = GeoJSON.FeatureCollection | FeatureGeometryCollection;
+type LineString = GeoJSON.Feature | GeoJSON.LineString;
+interface Point extends GeoJSON.Feature {
+ properties: {
+ dist: number
+ [key: string]: any
+ }
+}
+
+/**
+ * http://turfjs.org/docs/#nearestpointtoline
+ */
+declare function nearestPointToLine(points: Points, line: LineString, units?: Units): Point;
+declare namespace nearestPointToLine { }
+export = nearestPointToLine;
diff --git a/packages/turf-nearest-point-to-line/index.js b/packages/turf-nearest-point-to-line/index.js
new file mode 100644
index 0000000000..e750b3915e
--- /dev/null
+++ b/packages/turf-nearest-point-to-line/index.js
@@ -0,0 +1,72 @@
+var meta = require('@turf/meta');
+var pointToLineDistance = require('@turf/point-to-line-distance');
+var featureEach = meta.featureEach;
+var geomEach = meta.geomEach;
+
+/**
+ * Returns the closest {@link Point|point}, of a {@link FeatureCollection|collection} of points, to a {@link LineString|line}.
+ * The returned point has a `dist` property indicating its distance to the line.
+ *
+ * @name nearestPointToLine
+ * @param {FeatureCollection|GeometryCollection} points Point Collection
+ * @param {Feature|Geometry} line Line Feature
+ * @param {string} [units=kilometers] unit of the output distance property, can be degrees, radians, miles, or kilometer
+ * @returns {Feature} the closest point
+ * @example
+ * var points = featureCollection([point([0, 0]), point([0.5, 0.5])]);
+ * var line = lineString([[1,1], [-1,1]]);
+ *
+ * var nearest = turf.nearestPointToLine(points, line);
+ *
+ * //addToMap
+ * var addToMap = [nearest, line];
+ */
+module.exports = function (points, line, units) {
+ // validation
+ if (!points) throw new Error('points is required');
+ points = handleCollection(points);
+ if (!points.features.length) throw new Error('points must contain features');
+
+ if (!line) throw new Error('line is required');
+ var type = line.geometry ? line.geometry.type : line.type;
+ if (type !== 'LineString') throw new Error('line must be a LineString');
+
+ var dist = Infinity;
+ var pt = null;
+
+ featureEach(points, function (point) {
+ var d = pointToLineDistance(point, line, units);
+ if (d < dist) {
+ dist = d;
+ pt = point;
+ }
+ });
+ pt.properties.dist = dist;
+ return pt;
+};
+
+/**
+ * Convert Collection to FeatureCollection
+ *
+ * @private
+ * @param {FeatureCollection|GeometryCollection} points Points
+ * @returns {FeatureCollection} points
+ */
+function handleCollection(points) {
+ var features = [];
+ var type = points.geometry ? points.geometry.type : points.type;
+ switch (type) {
+ case 'GeometryCollection':
+ geomEach(points, function (geom) {
+ if (geom.type === 'Point') features.push({type: 'Feature', properties: {}, geometry: geom});
+ });
+ return {type: 'FeatureCollection', features: features};
+ case 'FeatureCollection':
+ points.features = points.features.filter(function (feature) {
+ return feature.geometry.type === 'Point';
+ });
+ return points;
+ default:
+ throw new Error('points must be a Point Collection');
+ }
+}
diff --git a/packages/turf-nearest-point-to-line/package.json b/packages/turf-nearest-point-to-line/package.json
new file mode 100644
index 0000000000..13fa3a7dde
--- /dev/null
+++ b/packages/turf-nearest-point-to-line/package.json
@@ -0,0 +1,48 @@
+{
+ "name": "@turf/nearest-point-to-line",
+ "version": "4.0.0",
+ "description": "turf nearest-point-to-line module",
+ "main": "index.js",
+ "types": "index.d.ts",
+ "files": [
+ "index.js",
+ "index.d.ts"
+ ],
+ "scripts": {
+ "test": "node test.js",
+ "bench": "node bench.js"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/Turfjs/turf.git"
+ },
+ "keywords": [
+ "turf",
+ "geojson",
+ "gis",
+ "near",
+ "nearest-point-to-line"
+ ],
+ "author": "Turf Authors",
+ "contributors": [
+ "Stefano Borghi <@stebogit>"
+ ],
+ "license": "MIT",
+ "bugs": {
+ "url": "https://github.com/Turfjs/turf/issues"
+ },
+ "homepage": "https://github.com/Turfjs/turf",
+ "devDependencies": {
+ "@turf/circle": "^4.7.3",
+ "@turf/helpers": "4.7.1",
+ "@turf/truncate": "^4.7.3",
+ "benchmark": "^2.1.4",
+ "load-json-file": "^2.0.0",
+ "tape": "^4.6.3",
+ "write-json-file": "^2.2.0"
+ },
+ "dependencies": {
+ "@turf/meta": "^4.7.3",
+ "@turf/point-to-line-distance": "^4.7.3"
+ }
+}
diff --git a/packages/turf-nearest-point-to-line/test.js b/packages/turf-nearest-point-to-line/test.js
new file mode 100644
index 0000000000..1b0674ce48
--- /dev/null
+++ b/packages/turf-nearest-point-to-line/test.js
@@ -0,0 +1,76 @@
+const fs = require('fs');
+const test = require('tape');
+const path = require('path');
+const load = require('load-json-file');
+const write = require('write-json-file');
+const circle = require('@turf/circle');
+const truncate = require('@turf/truncate');
+const {geometryCollection, featureCollection, point, lineString, round} = require('@turf/helpers');
+const nearestPointToLine = require('./');
+
+const directories = {
+ in: path.join(__dirname, 'test', 'in') + path.sep,
+ out: path.join(__dirname, 'test', 'out') + path.sep
+};
+
+const fixtures = fs.readdirSync(directories.in).map(filename => {
+ return {
+ filename,
+ name: path.parse(filename).name,
+ geojson: load.sync(directories.in + filename)
+ };
+});
+
+test('turf-nearest-point-to-line', t => {
+ for (const {filename, name, geojson} of fixtures) {
+ const [points, line] = geojson.features;
+ let {units} = geojson.properties || {};
+ const nearest = nearestPointToLine(points, line, units);
+ const distance = round(nearest.properties.dist, 13);
+ nearest.properties.dist = distance;
+ nearest.properties = Object.assign(nearest.properties, {
+ 'marker-color': '#F00',
+ 'marker-size': 'large',
+ 'marker-symbol': 'star'
+ });
+ const distanceCircle = truncate(circle(nearest, distance || 1, null, units, {fill: '#F00'}));
+ const results = featureCollection([points, nearest, line, distanceCircle]);
+
+ if (process.env.REGEN) write.sync(directories.out + filename, results);
+ t.deepEqual(results, load.sync(directories.out + filename), name);
+ }
+ t.end();
+});
+
+
+test('turf-nearest-point-to-line -- throws', t => {
+ const points = featureCollection([point([0, 0]), point([0, 1])]);
+ const line = lineString([[1, 1], [-1, 1]]);
+
+ t.throws(() => nearestPointToLine(null, line), /points is required/, 'missing points');
+ t.throws(() => nearestPointToLine(points, null), /line is required/, 'missing line');
+
+ t.throws(() => nearestPointToLine(points, line, 'invalid'), /units is invalid/, 'invalid units');
+ t.throws(() => nearestPointToLine(points, points), /line must be a LineString/, 'invalid line');
+ t.throws(() => nearestPointToLine(line, line), /points must be a Point Collection/, 'invalid points');
+
+ t.end();
+});
+
+test('turf-nearest-point-to-line -- Geometry', t => {
+ const points = featureCollection([point([0, 0]), point([0, 1])]);
+ const geomPoints = geometryCollection([point([0, 0]).geometry, point([0, 1]).geometry]);
+ const line = lineString([[1, 1], [-1, 1]]);
+
+ t.assert(nearestPointToLine(points, line.geometry));
+ t.assert(nearestPointToLine(geomPoints, line.geometry));
+ t.end();
+});
+
+test('turf-nearest-point-to-line -- Empty FeatureCollection', t => {
+ const points = featureCollection([]);
+ const line = lineString([[1, 1], [-1, 1]]);
+
+ t.throws(() => nearestPointToLine(points, line), /points must contain features/, 'points must contain features');
+ t.end();
+});
diff --git a/packages/turf-nearest-point-to-line/test/in/fiji.geojson b/packages/turf-nearest-point-to-line/test/in/fiji.geojson
new file mode 100644
index 0000000000..6011d663bf
--- /dev/null
+++ b/packages/turf-nearest-point-to-line/test/in/fiji.geojson
@@ -0,0 +1,81 @@
+{
+ "type": "FeatureCollection",
+ "features": [
+ {
+ "type": "Feature",
+ "properties": {},
+ "geometry": {
+ "type": "GeometryCollection",
+ "geometries": [
+ {
+ "type": "Point",
+ "coordinates": [
+ 180.60699462890625,
+ -16.62303335009946
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ 181.0986328125,
+ -17.027898881942694
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ 179.10186767578125,
+ -17.413546114374437
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ 180.516357421875,
+ -17.287709050621917
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ 179.37103271484375,
+ -16.691447830122993
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ 180.25817871093747,
+ -16.95435146120393
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "type": "Feature",
+ "properties": {},
+ "geometry": {
+ "type": "LineString",
+ "coordinates": [
+ [
+ 179.68139648437497,
+ -16.607241925191516
+ ],
+ [
+ 180.6427001953125,
+ -16.935960102864705
+ ],
+ [
+ 179.58251953125,
+ -17.07253857905758
+ ],
+ [
+ 180.29937744140625,
+ -17.460712710429785
+ ]
+ ]
+ }
+ }
+ ]
+}
diff --git a/packages/turf-nearest-point-to-line/test/in/on-line.geojson b/packages/turf-nearest-point-to-line/test/in/on-line.geojson
new file mode 100644
index 0000000000..ee5997be2b
--- /dev/null
+++ b/packages/turf-nearest-point-to-line/test/in/on-line.geojson
@@ -0,0 +1,114 @@
+{
+ "type": "FeatureCollection",
+ "features": [
+ {
+ "type": "Feature",
+ "properties": {},
+ "geometry": {
+ "type": "GeometryCollection",
+ "geometries": [
+ {
+ "type": "Point",
+ "coordinates": [
+ -23.62060546875,
+ 15.050905707724771
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ -22.813110351562496,
+ 16.093320185359257
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ -23.1646728515625,
+ 15.220589019578128
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ -24.4061279296875,
+ 14.966013251567164
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ -22.93670654296875,
+ 16.759837823776632
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ -24.3182373046875,
+ 16.609873919524187
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ -24.98291015625,
+ 16.867633616803836
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ -25.191650390625,
+ 17.056784609942554
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ -22.818603515625,
+ 15.31597593426845
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "type": "Feature",
+ "properties": {},
+ "geometry": {
+ "type": "LineString",
+ "coordinates": [
+ [
+ -24.10400390625,
+ 13.864747046142286
+ ],
+ [
+ -24.049072265625,
+ 15.739388446649146
+ ],
+ [
+ -23.016357421875,
+ 14.82799134735208
+ ],
+ [
+ -22.818603515625,
+ 15.31597593426845
+ ],
+ [
+ -22.3077392578125,
+ 16.399200837347113
+ ],
+ [
+ -23.510742187499996,
+ 16.409739933377747
+ ],
+ [
+ -24.4500732421875,
+ 17.528820674552627
+ ]
+ ]
+ }
+ }
+ ]
+}
diff --git a/packages/turf-nearest-point-to-line/test/in/one.geojson b/packages/turf-nearest-point-to-line/test/in/one.geojson
new file mode 100644
index 0000000000..34c5c6479c
--- /dev/null
+++ b/packages/turf-nearest-point-to-line/test/in/one.geojson
@@ -0,0 +1,63 @@
+{
+ "type": "FeatureCollection",
+ "properties": {
+ "units": "miles"
+ },
+ "features": [
+ {
+ "type": "Feature",
+ "properties": {},
+ "geometry": {
+ "type": "GeometryCollection",
+ "geometries": [
+ {
+ "type": "Point",
+ "coordinates": [
+ 29.7509765625,
+ 17.5602465032949
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ 28.388671875,
+ 18.323240460443397
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ 29.619140624999996,
+ 19.228176737766262
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "type": "Feature",
+ "properties": {},
+ "geometry": {
+ "type": "LineString",
+ "coordinates": [
+ [
+ 27.015380859374996,
+ 15.008463695004872
+ ],
+ [
+ 29.168701171875,
+ 17.256236314156425
+ ],
+ [
+ 32.003173828125,
+ 16.36230951024085
+ ],
+ [
+ 33.2666015625,
+ 18.999802829053262
+ ]
+ ]
+ }
+ }
+ ]
+}
diff --git a/packages/turf-nearest-point-to-line/test/in/resolute.geojson b/packages/turf-nearest-point-to-line/test/in/resolute.geojson
new file mode 100644
index 0000000000..a6ac3ab342
--- /dev/null
+++ b/packages/turf-nearest-point-to-line/test/in/resolute.geojson
@@ -0,0 +1,67 @@
+{
+ "type": "FeatureCollection",
+ "features": [
+ {
+ "type": "Feature",
+ "properties": {},
+ "geometry": {
+ "type": "GeometryCollection",
+ "geometries": [
+ {
+ "type": "Point",
+ "coordinates": [
+ -94.04296874999999,
+ 75.24186616026972
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ -75.1025390625,
+ 74.66001636880338
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ -87.2314453125,
+ 75.50815837230884
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ -95.8447265625,
+ 71.80141030136785
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "type": "Feature",
+ "properties": {},
+ "geometry": {
+ "type": "LineString",
+ "coordinates": [
+ [
+ -88.06640625,
+ 75.397779424116
+ ],
+ [
+ -104.6337890625,
+ 72.69883881004748
+ ],
+ [
+ -91.4501953125,
+ 72.99690914812648
+ ],
+ [
+ -89.1650390625,
+ 71.71888229713917
+ ]
+ ]
+ }
+ }
+ ]
+}
diff --git a/packages/turf-nearest-point-to-line/test/in/segment.geojson b/packages/turf-nearest-point-to-line/test/in/segment.geojson
new file mode 100644
index 0000000000..906cd8e973
--- /dev/null
+++ b/packages/turf-nearest-point-to-line/test/in/segment.geojson
@@ -0,0 +1,55 @@
+{
+ "type": "FeatureCollection",
+ "properties": {
+ "units": "miles"
+ },
+ "features": [
+ {
+ "type": "Feature",
+ "properties": {},
+ "geometry": {
+ "type": "GeometryCollection",
+ "geometries": [
+ {
+ "type": "Point",
+ "coordinates": [
+ 27.26806640625,
+ 14.243086862716888
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ 28.388671875,
+ 18.323240460443397
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ 29.619140624999996,
+ 19.228176737766262
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "type": "Feature",
+ "properties": {},
+ "geometry": {
+ "type": "LineString",
+ "coordinates": [
+ [
+ 27.015380859374996,
+ 15.008463695004872
+ ],
+ [
+ 29.168701171875,
+ 17.256236314156425
+ ]
+ ]
+ }
+ }
+ ]
+}
diff --git a/packages/turf-nearest-point-to-line/test/in/two.geojson b/packages/turf-nearest-point-to-line/test/in/two.geojson
new file mode 100644
index 0000000000..4c70ec6d46
--- /dev/null
+++ b/packages/turf-nearest-point-to-line/test/in/two.geojson
@@ -0,0 +1,71 @@
+{
+ "type": "FeatureCollection",
+ "features": [
+ {
+ "type": "Feature",
+ "properties": {},
+ "geometry": {
+ "type": "GeometryCollection",
+ "geometries": [
+ {
+ "type": "Point",
+ "coordinates": [
+ -32.7392578125,
+ 28.76765910569123
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ -36.25488281249999,
+ 23.36242859340884
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ -38.0126953125,
+ 26.194876675795218
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ -39.90234375,
+ 27.059125784374068
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "type": "Feature",
+ "properties": {},
+ "geometry": {
+ "type": "LineString",
+ "coordinates": [
+ [
+ -45.791015625,
+ 23.96617587126503
+ ],
+ [
+ -42.0556640625,
+ 27.332735136859146
+ ],
+ [
+ -41.572265625,
+ 23.40276490540795
+ ],
+ [
+ -36.474609375,
+ 28.844673680771795
+ ],
+ [
+ -43.1103515625,
+ 29.267232865200878
+ ]
+ ]
+ }
+ }
+ ]
+}
diff --git a/packages/turf-nearest-point-to-line/test/out/fiji.geojson b/packages/turf-nearest-point-to-line/test/out/fiji.geojson
new file mode 100644
index 0000000000..89e8b87e01
--- /dev/null
+++ b/packages/turf-nearest-point-to-line/test/out/fiji.geojson
@@ -0,0 +1,370 @@
+{
+ "type": "FeatureCollection",
+ "features": [
+ {
+ "type": "Feature",
+ "properties": {},
+ "geometry": {
+ "type": "GeometryCollection",
+ "geometries": [
+ {
+ "type": "Point",
+ "coordinates": [
+ 180.60699462890625,
+ -16.62303335009946
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ 181.0986328125,
+ -17.027898881942694
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ 179.10186767578125,
+ -17.413546114374437
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ 180.516357421875,
+ -17.287709050621917
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ 179.37103271484375,
+ -16.691447830122993
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ 180.25817871093747,
+ -16.95435146120393
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "type": "Feature",
+ "properties": {
+ "dist": 3.5053168159852,
+ "marker-color": "#F00",
+ "marker-size": "large",
+ "marker-symbol": "star"
+ },
+ "geometry": {
+ "type": "Point",
+ "coordinates": [
+ 180.25817871093747,
+ -16.95435146120393
+ ]
+ }
+ },
+ {
+ "type": "Feature",
+ "properties": {},
+ "geometry": {
+ "type": "LineString",
+ "coordinates": [
+ [
+ 179.68139648437497,
+ -16.607241925191516
+ ],
+ [
+ 180.6427001953125,
+ -16.935960102864705
+ ],
+ [
+ 179.58251953125,
+ -17.07253857905758
+ ],
+ [
+ 180.29937744140625,
+ -17.460712710429785
+ ]
+ ]
+ }
+ },
+ {
+ "type": "Feature",
+ "properties": {
+ "fill": "#F00"
+ },
+ "geometry": {
+ "type": "Polygon",
+ "coordinates": [
+ [
+ [
+ 180.258179,
+ -16.922837
+ ],
+ [
+ 180.261407,
+ -16.922989
+ ],
+ [
+ 180.264605,
+ -16.923443
+ ],
+ [
+ 180.267741,
+ -16.924194
+ ],
+ [
+ 180.270785,
+ -16.925236
+ ],
+ [
+ 180.273707,
+ -16.926558
+ ],
+ [
+ 180.27648,
+ -16.928148
+ ],
+ [
+ 180.279077,
+ -16.92999
+ ],
+ [
+ 180.281472,
+ -16.932066
+ ],
+ [
+ 180.283644,
+ -16.934357
+ ],
+ [
+ 180.28557,
+ -16.936841
+ ],
+ [
+ 180.287232,
+ -16.939494
+ ],
+ [
+ 180.288615,
+ -16.942289
+ ],
+ [
+ 180.289705,
+ -16.945201
+ ],
+ [
+ 180.290491,
+ -16.948201
+ ],
+ [
+ 180.290966,
+ -16.95126
+ ],
+ [
+ 180.291125,
+ -16.954349
+ ],
+ [
+ 180.290967,
+ -16.957438
+ ],
+ [
+ 180.290493,
+ -16.960497
+ ],
+ [
+ 180.289708,
+ -16.963497
+ ],
+ [
+ 180.288619,
+ -16.966409
+ ],
+ [
+ 180.287237,
+ -16.969205
+ ],
+ [
+ 180.285575,
+ -16.971858
+ ],
+ [
+ 180.283649,
+ -16.974342
+ ],
+ [
+ 180.281478,
+ -16.976634
+ ],
+ [
+ 180.279082,
+ -16.978711
+ ],
+ [
+ 180.276485,
+ -16.980554
+ ],
+ [
+ 180.273712,
+ -16.982144
+ ],
+ [
+ 180.270789,
+ -16.983466
+ ],
+ [
+ 180.267744,
+ -16.984508
+ ],
+ [
+ 180.264607,
+ -16.98526
+ ],
+ [
+ 180.261409,
+ -16.985714
+ ],
+ [
+ 180.258179,
+ -16.985866
+ ],
+ [
+ 180.254949,
+ -16.985714
+ ],
+ [
+ 180.25175,
+ -16.98526
+ ],
+ [
+ 180.248613,
+ -16.984508
+ ],
+ [
+ 180.245569,
+ -16.983466
+ ],
+ [
+ 180.242646,
+ -16.982144
+ ],
+ [
+ 180.239872,
+ -16.980554
+ ],
+ [
+ 180.237275,
+ -16.978711
+ ],
+ [
+ 180.23488,
+ -16.976634
+ ],
+ [
+ 180.232708,
+ -16.974342
+ ],
+ [
+ 180.230782,
+ -16.971858
+ ],
+ [
+ 180.229121,
+ -16.969205
+ ],
+ [
+ 180.227739,
+ -16.966409
+ ],
+ [
+ 180.22665,
+ -16.963497
+ ],
+ [
+ 180.225865,
+ -16.960497
+ ],
+ [
+ 180.225391,
+ -16.957438
+ ],
+ [
+ 180.225233,
+ -16.954349
+ ],
+ [
+ 180.225392,
+ -16.95126
+ ],
+ [
+ 180.225867,
+ -16.948201
+ ],
+ [
+ 180.226653,
+ -16.945201
+ ],
+ [
+ 180.227742,
+ -16.942289
+ ],
+ [
+ 180.229125,
+ -16.939494
+ ],
+ [
+ 180.230788,
+ -16.936841
+ ],
+ [
+ 180.232714,
+ -16.934357
+ ],
+ [
+ 180.234885,
+ -16.932066
+ ],
+ [
+ 180.237281,
+ -16.92999
+ ],
+ [
+ 180.239877,
+ -16.928148
+ ],
+ [
+ 180.24265,
+ -16.926558
+ ],
+ [
+ 180.245573,
+ -16.925236
+ ],
+ [
+ 180.248616,
+ -16.924194
+ ],
+ [
+ 180.251752,
+ -16.923443
+ ],
+ [
+ 180.25495,
+ -16.922989
+ ],
+ [
+ 180.258179,
+ -16.922837
+ ]
+ ]
+ ]
+ }
+ }
+ ]
+}
diff --git a/packages/turf-nearest-point-to-line/test/out/on-line.geojson b/packages/turf-nearest-point-to-line/test/out/on-line.geojson
new file mode 100644
index 0000000000..a55cfbb74c
--- /dev/null
+++ b/packages/turf-nearest-point-to-line/test/out/on-line.geojson
@@ -0,0 +1,403 @@
+{
+ "type": "FeatureCollection",
+ "features": [
+ {
+ "type": "Feature",
+ "properties": {},
+ "geometry": {
+ "type": "GeometryCollection",
+ "geometries": [
+ {
+ "type": "Point",
+ "coordinates": [
+ -23.62060546875,
+ 15.050905707724771
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ -22.813110351562496,
+ 16.093320185359257
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ -23.1646728515625,
+ 15.220589019578128
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ -24.4061279296875,
+ 14.966013251567164
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ -22.93670654296875,
+ 16.759837823776632
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ -24.3182373046875,
+ 16.609873919524187
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ -24.98291015625,
+ 16.867633616803836
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ -25.191650390625,
+ 17.056784609942554
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ -22.818603515625,
+ 15.31597593426845
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "type": "Feature",
+ "properties": {
+ "dist": 0,
+ "marker-color": "#F00",
+ "marker-size": "large",
+ "marker-symbol": "star"
+ },
+ "geometry": {
+ "type": "Point",
+ "coordinates": [
+ -22.818603515625,
+ 15.31597593426845
+ ]
+ }
+ },
+ {
+ "type": "Feature",
+ "properties": {},
+ "geometry": {
+ "type": "LineString",
+ "coordinates": [
+ [
+ -24.10400390625,
+ 13.864747046142286
+ ],
+ [
+ -24.049072265625,
+ 15.739388446649146
+ ],
+ [
+ -23.016357421875,
+ 14.82799134735208
+ ],
+ [
+ -22.818603515625,
+ 15.31597593426845
+ ],
+ [
+ -22.3077392578125,
+ 16.399200837347113
+ ],
+ [
+ -23.510742187499996,
+ 16.409739933377747
+ ],
+ [
+ -24.4500732421875,
+ 17.528820674552627
+ ]
+ ]
+ }
+ },
+ {
+ "type": "Feature",
+ "properties": {
+ "fill": "#F00"
+ },
+ "geometry": {
+ "type": "Polygon",
+ "coordinates": [
+ [
+ [
+ -22.818604,
+ 15.324966
+ ],
+ [
+ -22.81769,
+ 15.324923
+ ],
+ [
+ -22.816785,
+ 15.324794
+ ],
+ [
+ -22.815898,
+ 15.324579
+ ],
+ [
+ -22.815036,
+ 15.324282
+ ],
+ [
+ -22.814209,
+ 15.323905
+ ],
+ [
+ -22.813425,
+ 15.323451
+ ],
+ [
+ -22.81269,
+ 15.322926
+ ],
+ [
+ -22.812012,
+ 15.322333
+ ],
+ [
+ -22.811398,
+ 15.321679
+ ],
+ [
+ -22.810853,
+ 15.320971
+ ],
+ [
+ -22.810383,
+ 15.320214
+ ],
+ [
+ -22.809991,
+ 15.319416
+ ],
+ [
+ -22.809683,
+ 15.318586
+ ],
+ [
+ -22.809461,
+ 15.31773
+ ],
+ [
+ -22.809327,
+ 15.316857
+ ],
+ [
+ -22.809282,
+ 15.315976
+ ],
+ [
+ -22.809327,
+ 15.315095
+ ],
+ [
+ -22.809461,
+ 15.314222
+ ],
+ [
+ -22.809684,
+ 15.313366
+ ],
+ [
+ -22.809992,
+ 15.312535
+ ],
+ [
+ -22.810383,
+ 15.311738
+ ],
+ [
+ -22.810853,
+ 15.310981
+ ],
+ [
+ -22.811398,
+ 15.310272
+ ],
+ [
+ -22.812012,
+ 15.309619
+ ],
+ [
+ -22.81269,
+ 15.309026
+ ],
+ [
+ -22.813425,
+ 15.308501
+ ],
+ [
+ -22.81421,
+ 15.308047
+ ],
+ [
+ -22.815036,
+ 15.30767
+ ],
+ [
+ -22.815898,
+ 15.307373
+ ],
+ [
+ -22.816785,
+ 15.307158
+ ],
+ [
+ -22.81769,
+ 15.307029
+ ],
+ [
+ -22.818604,
+ 15.306986
+ ],
+ [
+ -22.819517,
+ 15.307029
+ ],
+ [
+ -22.820422,
+ 15.307158
+ ],
+ [
+ -22.821309,
+ 15.307373
+ ],
+ [
+ -22.822171,
+ 15.30767
+ ],
+ [
+ -22.822997,
+ 15.308047
+ ],
+ [
+ -22.823782,
+ 15.308501
+ ],
+ [
+ -22.824517,
+ 15.309026
+ ],
+ [
+ -22.825195,
+ 15.309619
+ ],
+ [
+ -22.825809,
+ 15.310272
+ ],
+ [
+ -22.826354,
+ 15.310981
+ ],
+ [
+ -22.826824,
+ 15.311738
+ ],
+ [
+ -22.827215,
+ 15.312535
+ ],
+ [
+ -22.827523,
+ 15.313366
+ ],
+ [
+ -22.827746,
+ 15.314222
+ ],
+ [
+ -22.82788,
+ 15.315095
+ ],
+ [
+ -22.827925,
+ 15.315976
+ ],
+ [
+ -22.82788,
+ 15.316857
+ ],
+ [
+ -22.827746,
+ 15.31773
+ ],
+ [
+ -22.827524,
+ 15.318586
+ ],
+ [
+ -22.827216,
+ 15.319416
+ ],
+ [
+ -22.826824,
+ 15.320214
+ ],
+ [
+ -22.826354,
+ 15.320971
+ ],
+ [
+ -22.825809,
+ 15.321679
+ ],
+ [
+ -22.825195,
+ 15.322333
+ ],
+ [
+ -22.824517,
+ 15.322926
+ ],
+ [
+ -22.823782,
+ 15.323451
+ ],
+ [
+ -22.822998,
+ 15.323905
+ ],
+ [
+ -22.822171,
+ 15.324282
+ ],
+ [
+ -22.82131,
+ 15.324579
+ ],
+ [
+ -22.820422,
+ 15.324794
+ ],
+ [
+ -22.819517,
+ 15.324923
+ ],
+ [
+ -22.818604,
+ 15.324966
+ ]
+ ]
+ ]
+ }
+ }
+ ]
+}
diff --git a/packages/turf-nearest-point-to-line/test/out/one.geojson b/packages/turf-nearest-point-to-line/test/out/one.geojson
new file mode 100644
index 0000000000..45f1604eb8
--- /dev/null
+++ b/packages/turf-nearest-point-to-line/test/out/one.geojson
@@ -0,0 +1,349 @@
+{
+ "type": "FeatureCollection",
+ "features": [
+ {
+ "type": "Feature",
+ "properties": {},
+ "geometry": {
+ "type": "GeometryCollection",
+ "geometries": [
+ {
+ "type": "Point",
+ "coordinates": [
+ 29.7509765625,
+ 17.5602465032949
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ 28.388671875,
+ 18.323240460443397
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ 29.619140624999996,
+ 19.228176737766262
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "type": "Feature",
+ "properties": {
+ "dist": 31.8014202148872,
+ "marker-color": "#F00",
+ "marker-size": "large",
+ "marker-symbol": "star"
+ },
+ "geometry": {
+ "type": "Point",
+ "coordinates": [
+ 29.7509765625,
+ 17.5602465032949
+ ]
+ }
+ },
+ {
+ "type": "Feature",
+ "properties": {},
+ "geometry": {
+ "type": "LineString",
+ "coordinates": [
+ [
+ 27.015380859374996,
+ 15.008463695004872
+ ],
+ [
+ 29.168701171875,
+ 17.256236314156425
+ ],
+ [
+ 32.003173828125,
+ 16.36230951024085
+ ],
+ [
+ 33.2666015625,
+ 18.999802829053262
+ ]
+ ]
+ }
+ },
+ {
+ "type": "Feature",
+ "properties": {
+ "fill": "#F00"
+ },
+ "geometry": {
+ "type": "Polygon",
+ "coordinates": [
+ [
+ [
+ 29.750977,
+ 18.02037
+ ],
+ [
+ 29.798402,
+ 18.018148
+ ],
+ [
+ 29.845367,
+ 18.011506
+ ],
+ [
+ 29.891416,
+ 18.000507
+ ],
+ [
+ 29.936102,
+ 17.985258
+ ],
+ [
+ 29.978993,
+ 17.965908
+ ],
+ [
+ 30.019673,
+ 17.942643
+ ],
+ [
+ 30.057749,
+ 17.915689
+ ],
+ [
+ 30.092853,
+ 17.885308
+ ],
+ [
+ 30.124646,
+ 17.851794
+ ],
+ [
+ 30.152824,
+ 17.81547
+ ],
+ [
+ 30.177115,
+ 17.77669
+ ],
+ [
+ 30.197287,
+ 17.735827
+ ],
+ [
+ 30.213149,
+ 17.693276
+ ],
+ [
+ 30.22455,
+ 17.649448
+ ],
+ [
+ 30.231384,
+ 17.604767
+ ],
+ [
+ 30.233588,
+ 17.559662
+ ],
+ [
+ 30.231145,
+ 17.514568
+ ],
+ [
+ 30.224081,
+ 17.46992
+ ],
+ [
+ 30.212468,
+ 17.426146
+ ],
+ [
+ 30.19642,
+ 17.383668
+ ],
+ [
+ 30.176095,
+ 17.342894
+ ],
+ [
+ 30.151691,
+ 17.304214
+ ],
+ [
+ 30.123443,
+ 17.268001
+ ],
+ [
+ 30.091626,
+ 17.2346
+ ],
+ [
+ 30.056546,
+ 17.204333
+ ],
+ [
+ 30.01854,
+ 17.177489
+ ],
+ [
+ 29.977974,
+ 17.154326
+ ],
+ [
+ 29.935235,
+ 17.135064
+ ],
+ [
+ 29.890734,
+ 17.119887
+ ],
+ [
+ 29.844897,
+ 17.108943
+ ],
+ [
+ 29.798163,
+ 17.102334
+ ],
+ [
+ 29.750977,
+ 17.100123
+ ],
+ [
+ 29.703791,
+ 17.102334
+ ],
+ [
+ 29.657056,
+ 17.108943
+ ],
+ [
+ 29.611219,
+ 17.119887
+ ],
+ [
+ 29.566718,
+ 17.135064
+ ],
+ [
+ 29.52398,
+ 17.154326
+ ],
+ [
+ 29.483413,
+ 17.177489
+ ],
+ [
+ 29.445407,
+ 17.204333
+ ],
+ [
+ 29.410327,
+ 17.2346
+ ],
+ [
+ 29.37851,
+ 17.268001
+ ],
+ [
+ 29.350262,
+ 17.304214
+ ],
+ [
+ 29.325858,
+ 17.342894
+ ],
+ [
+ 29.305533,
+ 17.383668
+ ],
+ [
+ 29.289486,
+ 17.426146
+ ],
+ [
+ 29.277872,
+ 17.46992
+ ],
+ [
+ 29.270808,
+ 17.514568
+ ],
+ [
+ 29.268365,
+ 17.559662
+ ],
+ [
+ 29.270569,
+ 17.604767
+ ],
+ [
+ 29.277403,
+ 17.649448
+ ],
+ [
+ 29.288804,
+ 17.693276
+ ],
+ [
+ 29.304666,
+ 17.735827
+ ],
+ [
+ 29.324838,
+ 17.77669
+ ],
+ [
+ 29.349129,
+ 17.81547
+ ],
+ [
+ 29.377307,
+ 17.851794
+ ],
+ [
+ 29.4091,
+ 17.885308
+ ],
+ [
+ 29.444204,
+ 17.915689
+ ],
+ [
+ 29.48228,
+ 17.942643
+ ],
+ [
+ 29.52296,
+ 17.965908
+ ],
+ [
+ 29.565851,
+ 17.985258
+ ],
+ [
+ 29.610537,
+ 18.000507
+ ],
+ [
+ 29.656586,
+ 18.011506
+ ],
+ [
+ 29.703551,
+ 18.018148
+ ],
+ [
+ 29.750977,
+ 18.02037
+ ]
+ ]
+ ]
+ }
+ }
+ ]
+}
diff --git a/packages/turf-nearest-point-to-line/test/out/resolute.geojson b/packages/turf-nearest-point-to-line/test/out/resolute.geojson
new file mode 100644
index 0000000000..b4fa34d8d7
--- /dev/null
+++ b/packages/turf-nearest-point-to-line/test/out/resolute.geojson
@@ -0,0 +1,356 @@
+{
+ "type": "FeatureCollection",
+ "features": [
+ {
+ "type": "Feature",
+ "properties": {},
+ "geometry": {
+ "type": "GeometryCollection",
+ "geometries": [
+ {
+ "type": "Point",
+ "coordinates": [
+ -94.04296874999999,
+ 75.24186616026972
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ -75.1025390625,
+ 74.66001636880338
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ -87.2314453125,
+ 75.50815837230884
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ -95.8447265625,
+ 71.80141030136785
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "type": "Feature",
+ "properties": {
+ "dist": 26.3605458890526,
+ "marker-color": "#F00",
+ "marker-size": "large",
+ "marker-symbol": "star"
+ },
+ "geometry": {
+ "type": "Point",
+ "coordinates": [
+ -87.2314453125,
+ 75.50815837230884
+ ]
+ }
+ },
+ {
+ "type": "Feature",
+ "properties": {},
+ "geometry": {
+ "type": "LineString",
+ "coordinates": [
+ [
+ -88.06640625,
+ 75.397779424116
+ ],
+ [
+ -104.6337890625,
+ 72.69883881004748
+ ],
+ [
+ -91.4501953125,
+ 72.99690914812648
+ ],
+ [
+ -89.1650390625,
+ 71.71888229713917
+ ]
+ ]
+ }
+ },
+ {
+ "type": "Feature",
+ "properties": {
+ "fill": "#F00"
+ },
+ "geometry": {
+ "type": "Polygon",
+ "coordinates": [
+ [
+ [
+ -87.231445,
+ 75.74515
+ ],
+ [
+ -87.137115,
+ 75.74399
+ ],
+ [
+ -87.043739,
+ 75.740523
+ ],
+ [
+ -86.952256,
+ 75.734783
+ ],
+ [
+ -86.863589,
+ 75.726828
+ ],
+ [
+ -86.778625,
+ 75.716739
+ ],
+ [
+ -86.69821,
+ 75.704616
+ ],
+ [
+ -86.623137,
+ 75.690582
+ ],
+ [
+ -86.554143,
+ 75.674778
+ ],
+ [
+ -86.491894,
+ 75.657359
+ ],
+ [
+ -86.436985,
+ 75.638501
+ ],
+ [
+ -86.389929,
+ 75.618389
+ ],
+ [
+ -86.351159,
+ 75.597222
+ ],
+ [
+ -86.321017,
+ 75.575209
+ ],
+ [
+ -86.299761,
+ 75.552563
+ ],
+ [
+ -86.287555,
+ 75.529507
+ ],
+ [
+ -86.284477,
+ 75.506262
+ ],
+ [
+ -86.290511,
+ 75.483054
+ ],
+ [
+ -86.305559,
+ 75.460105
+ ],
+ [
+ -86.329435,
+ 75.437635
+ ],
+ [
+ -86.361873,
+ 75.415857
+ ],
+ [
+ -86.402529,
+ 75.394978
+ ],
+ [
+ -86.450986,
+ 75.375194
+ ],
+ [
+ -86.506758,
+ 75.356691
+ ],
+ [
+ -86.569299,
+ 75.339643
+ ],
+ [
+ -86.638003,
+ 75.324208
+ ],
+ [
+ -86.712213,
+ 75.31053
+ ],
+ [
+ -86.791229,
+ 75.298735
+ ],
+ [
+ -86.874308,
+ 75.288933
+ ],
+ [
+ -86.960678,
+ 75.281214
+ ],
+ [
+ -87.04954,
+ 75.275649
+ ],
+ [
+ -87.140073,
+ 75.27229
+ ],
+ [
+ -87.231445,
+ 75.271167
+ ],
+ [
+ -87.322818,
+ 75.27229
+ ],
+ [
+ -87.413351,
+ 75.275649
+ ],
+ [
+ -87.502212,
+ 75.281214
+ ],
+ [
+ -87.588582,
+ 75.288933
+ ],
+ [
+ -87.671662,
+ 75.298735
+ ],
+ [
+ -87.750677,
+ 75.31053
+ ],
+ [
+ -87.824888,
+ 75.324208
+ ],
+ [
+ -87.893592,
+ 75.339643
+ ],
+ [
+ -87.956132,
+ 75.356691
+ ],
+ [
+ -88.011905,
+ 75.375194
+ ],
+ [
+ -88.060362,
+ 75.394978
+ ],
+ [
+ -88.101017,
+ 75.415857
+ ],
+ [
+ -88.133455,
+ 75.437635
+ ],
+ [
+ -88.157331,
+ 75.460105
+ ],
+ [
+ -88.172379,
+ 75.483054
+ ],
+ [
+ -88.178414,
+ 75.506262
+ ],
+ [
+ -88.175335,
+ 75.529507
+ ],
+ [
+ -88.16313,
+ 75.552563
+ ],
+ [
+ -88.141873,
+ 75.575209
+ ],
+ [
+ -88.111732,
+ 75.597222
+ ],
+ [
+ -88.072961,
+ 75.618389
+ ],
+ [
+ -88.025906,
+ 75.638501
+ ],
+ [
+ -87.970996,
+ 75.657359
+ ],
+ [
+ -87.908747,
+ 75.674778
+ ],
+ [
+ -87.839753,
+ 75.690582
+ ],
+ [
+ -87.764681,
+ 75.704616
+ ],
+ [
+ -87.684266,
+ 75.716739
+ ],
+ [
+ -87.599301,
+ 75.726828
+ ],
+ [
+ -87.510634,
+ 75.734783
+ ],
+ [
+ -87.419152,
+ 75.740523
+ ],
+ [
+ -87.325775,
+ 75.74399
+ ],
+ [
+ -87.231445,
+ 75.74515
+ ]
+ ]
+ ]
+ }
+ }
+ ]
+}
diff --git a/packages/turf-nearest-point-to-line/test/out/segment.geojson b/packages/turf-nearest-point-to-line/test/out/segment.geojson
new file mode 100644
index 0000000000..ce518adee3
--- /dev/null
+++ b/packages/turf-nearest-point-to-line/test/out/segment.geojson
@@ -0,0 +1,341 @@
+{
+ "type": "FeatureCollection",
+ "features": [
+ {
+ "type": "Feature",
+ "properties": {},
+ "geometry": {
+ "type": "GeometryCollection",
+ "geometries": [
+ {
+ "type": "Point",
+ "coordinates": [
+ 27.26806640625,
+ 14.243086862716888
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ 28.388671875,
+ 18.323240460443397
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ 29.619140624999996,
+ 19.228176737766262
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "type": "Feature",
+ "properties": {
+ "dist": 55.5325298607931,
+ "marker-color": "#F00",
+ "marker-size": "large",
+ "marker-symbol": "star"
+ },
+ "geometry": {
+ "type": "Point",
+ "coordinates": [
+ 27.26806640625,
+ 14.243086862716888
+ ]
+ }
+ },
+ {
+ "type": "Feature",
+ "properties": {},
+ "geometry": {
+ "type": "LineString",
+ "coordinates": [
+ [
+ 27.015380859374996,
+ 15.008463695004872
+ ],
+ [
+ 29.168701171875,
+ 17.256236314156425
+ ]
+ ]
+ }
+ },
+ {
+ "type": "Feature",
+ "properties": {
+ "fill": "#F00"
+ },
+ "geometry": {
+ "type": "Polygon",
+ "coordinates": [
+ [
+ [
+ 27.268066,
+ 15.046567
+ ],
+ [
+ 27.349613,
+ 15.042684
+ ],
+ [
+ 27.430366,
+ 15.031072
+ ],
+ [
+ 27.509538,
+ 15.011846
+ ],
+ [
+ 27.586361,
+ 14.985192
+ ],
+ [
+ 27.660086,
+ 14.951369
+ ],
+ [
+ 27.73,
+ 14.910706
+ ],
+ [
+ 27.795425,
+ 14.8636
+ ],
+ [
+ 27.855728,
+ 14.810507
+ ],
+ [
+ 27.910328,
+ 14.751943
+ ],
+ [
+ 27.9587,
+ 14.688475
+ ],
+ [
+ 28.000382,
+ 14.620721
+ ],
+ [
+ 28.034976,
+ 14.549334
+ ],
+ [
+ 28.062155,
+ 14.475007
+ ],
+ [
+ 28.081663,
+ 14.398456
+ ],
+ [
+ 28.093321,
+ 14.320422
+ ],
+ [
+ 28.097024,
+ 14.241657
+ ],
+ [
+ 28.092746,
+ 14.162919
+ ],
+ [
+ 28.080534,
+ 14.084966
+ ],
+ [
+ 28.060516,
+ 14.008548
+ ],
+ [
+ 28.03289,
+ 13.934398
+ ],
+ [
+ 27.997929,
+ 13.863228
+ ],
+ [
+ 27.955974,
+ 13.795721
+ ],
+ [
+ 27.907434,
+ 13.732522
+ ],
+ [
+ 27.852777,
+ 13.674237
+ ],
+ [
+ 27.792531,
+ 13.621423
+ ],
+ [
+ 27.727274,
+ 13.574585
+ ],
+ [
+ 27.657633,
+ 13.534169
+ ],
+ [
+ 27.584274,
+ 13.500563
+ ],
+ [
+ 27.507899,
+ 13.474087
+ ],
+ [
+ 27.429236,
+ 13.454993
+ ],
+ [
+ 27.349037,
+ 13.443463
+ ],
+ [
+ 27.268066,
+ 13.439607
+ ],
+ [
+ 27.187096,
+ 13.443463
+ ],
+ [
+ 27.106897,
+ 13.454993
+ ],
+ [
+ 27.028234,
+ 13.474087
+ ],
+ [
+ 26.951859,
+ 13.500563
+ ],
+ [
+ 26.8785,
+ 13.534169
+ ],
+ [
+ 26.808859,
+ 13.574585
+ ],
+ [
+ 26.743602,
+ 13.621423
+ ],
+ [
+ 26.683356,
+ 13.674237
+ ],
+ [
+ 26.628699,
+ 13.732522
+ ],
+ [
+ 26.580159,
+ 13.795721
+ ],
+ [
+ 26.538204,
+ 13.863228
+ ],
+ [
+ 26.503243,
+ 13.934398
+ ],
+ [
+ 26.475617,
+ 14.008548
+ ],
+ [
+ 26.455599,
+ 14.084966
+ ],
+ [
+ 26.443387,
+ 14.162919
+ ],
+ [
+ 26.439108,
+ 14.241657
+ ],
+ [
+ 26.442812,
+ 14.320422
+ ],
+ [
+ 26.45447,
+ 14.398456
+ ],
+ [
+ 26.473978,
+ 14.475007
+ ],
+ [
+ 26.501157,
+ 14.549334
+ ],
+ [
+ 26.535751,
+ 14.620721
+ ],
+ [
+ 26.577432,
+ 14.688475
+ ],
+ [
+ 26.625805,
+ 14.751943
+ ],
+ [
+ 26.680405,
+ 14.810507
+ ],
+ [
+ 26.740708,
+ 14.8636
+ ],
+ [
+ 26.806133,
+ 14.910706
+ ],
+ [
+ 26.876046,
+ 14.951369
+ ],
+ [
+ 26.949772,
+ 14.985192
+ ],
+ [
+ 27.026595,
+ 15.011846
+ ],
+ [
+ 27.105767,
+ 15.031072
+ ],
+ [
+ 27.18652,
+ 15.042684
+ ],
+ [
+ 27.268066,
+ 15.046567
+ ]
+ ]
+ ]
+ }
+ }
+ ]
+}
diff --git a/packages/turf-nearest-point-to-line/test/out/two.geojson b/packages/turf-nearest-point-to-line/test/out/two.geojson
new file mode 100644
index 0000000000..1d7947f296
--- /dev/null
+++ b/packages/turf-nearest-point-to-line/test/out/two.geojson
@@ -0,0 +1,360 @@
+{
+ "type": "FeatureCollection",
+ "features": [
+ {
+ "type": "Feature",
+ "properties": {},
+ "geometry": {
+ "type": "GeometryCollection",
+ "geometries": [
+ {
+ "type": "Point",
+ "coordinates": [
+ -32.7392578125,
+ 28.76765910569123
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ -36.25488281249999,
+ 23.36242859340884
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ -38.0126953125,
+ 26.194876675795218
+ ]
+ },
+ {
+ "type": "Point",
+ "coordinates": [
+ -39.90234375,
+ 27.059125784374068
+ ]
+ }
+ ]
+ }
+ },
+ {
+ "type": "Feature",
+ "properties": {
+ "dist": 78.1041665546531,
+ "marker-color": "#F00",
+ "marker-size": "large",
+ "marker-symbol": "star"
+ },
+ "geometry": {
+ "type": "Point",
+ "coordinates": [
+ -38.0126953125,
+ 26.194876675795218
+ ]
+ }
+ },
+ {
+ "type": "Feature",
+ "properties": {},
+ "geometry": {
+ "type": "LineString",
+ "coordinates": [
+ [
+ -45.791015625,
+ 23.96617587126503
+ ],
+ [
+ -42.0556640625,
+ 27.332735136859146
+ ],
+ [
+ -41.572265625,
+ 23.40276490540795
+ ],
+ [
+ -36.474609375,
+ 28.844673680771795
+ ],
+ [
+ -43.1103515625,
+ 29.267232865200878
+ ]
+ ]
+ }
+ },
+ {
+ "type": "Feature",
+ "properties": {
+ "fill": "#F00"
+ },
+ "geometry": {
+ "type": "Polygon",
+ "coordinates": [
+ [
+ [
+ -38.012695,
+ 26.897064
+ ],
+ [
+ -37.935524,
+ 26.893662
+ ],
+ [
+ -37.85911,
+ 26.88349
+ ],
+ [
+ -37.784202,
+ 26.866647
+ ],
+ [
+ -37.711534,
+ 26.843299
+ ],
+ [
+ -37.641815,
+ 26.813674
+ ],
+ [
+ -37.575726,
+ 26.778063
+ ],
+ [
+ -37.513909,
+ 26.736813
+ ],
+ [
+ -37.456964,
+ 26.690329
+ ],
+ [
+ -37.40544,
+ 26.639063
+ ],
+ [
+ -37.359831,
+ 26.583516
+ ],
+ [
+ -37.320573,
+ 26.524228
+ ],
+ [
+ -37.288037,
+ 26.461775
+ ],
+ [
+ -37.262527,
+ 26.396764
+ ],
+ [
+ -37.244278,
+ 26.329825
+ ],
+ [
+ -37.233454,
+ 26.261604
+ ],
+ [
+ -37.230147,
+ 26.19276
+ ],
+ [
+ -37.234375,
+ 26.123957
+ ],
+ [
+ -37.246083,
+ 26.055856
+ ],
+ [
+ -37.265148,
+ 25.989112
+ ],
+ [
+ -37.291373,
+ 25.924364
+ ],
+ [
+ -37.324496,
+ 25.862233
+ ],
+ [
+ -37.36419,
+ 25.803311
+ ],
+ [
+ -37.410067,
+ 25.74816
+ ],
+ [
+ -37.461682,
+ 25.697308
+ ],
+ [
+ -37.518537,
+ 25.651236
+ ],
+ [
+ -37.580085,
+ 25.610384
+ ],
+ [
+ -37.645738,
+ 25.575138
+ ],
+ [
+ -37.71487,
+ 25.545834
+ ],
+ [
+ -37.786824,
+ 25.522749
+ ],
+ [
+ -37.860916,
+ 25.506102
+ ],
+ [
+ -37.936445,
+ 25.496051
+ ],
+ [
+ -38.012695,
+ 25.492689
+ ],
+ [
+ -38.088946,
+ 25.496051
+ ],
+ [
+ -38.164474,
+ 25.506102
+ ],
+ [
+ -38.238567,
+ 25.522749
+ ],
+ [
+ -38.31052,
+ 25.545834
+ ],
+ [
+ -38.379653,
+ 25.575138
+ ],
+ [
+ -38.445306,
+ 25.610384
+ ],
+ [
+ -38.506854,
+ 25.651236
+ ],
+ [
+ -38.563709,
+ 25.697308
+ ],
+ [
+ -38.615323,
+ 25.74816
+ ],
+ [
+ -38.661201,
+ 25.803311
+ ],
+ [
+ -38.700895,
+ 25.862233
+ ],
+ [
+ -38.734018,
+ 25.924364
+ ],
+ [
+ -38.760243,
+ 25.989112
+ ],
+ [
+ -38.779307,
+ 26.055856
+ ],
+ [
+ -38.791016,
+ 26.123957
+ ],
+ [
+ -38.795243,
+ 26.19276
+ ],
+ [
+ -38.791936,
+ 26.261604
+ ],
+ [
+ -38.781113,
+ 26.329825
+ ],
+ [
+ -38.762864,
+ 26.396764
+ ],
+ [
+ -38.737354,
+ 26.461775
+ ],
+ [
+ -38.704818,
+ 26.524228
+ ],
+ [
+ -38.665559,
+ 26.583516
+ ],
+ [
+ -38.619951,
+ 26.639063
+ ],
+ [
+ -38.568427,
+ 26.690329
+ ],
+ [
+ -38.511482,
+ 26.736813
+ ],
+ [
+ -38.449665,
+ 26.778063
+ ],
+ [
+ -38.383576,
+ 26.813674
+ ],
+ [
+ -38.313857,
+ 26.843299
+ ],
+ [
+ -38.241188,
+ 26.866647
+ ],
+ [
+ -38.16628,
+ 26.88349
+ ],
+ [
+ -38.089866,
+ 26.893662
+ ],
+ [
+ -38.012695,
+ 26.897064
+ ]
+ ]
+ ]
+ }
+ }
+ ]
+}
diff --git a/packages/turf-nearest-point-to-line/types.ts b/packages/turf-nearest-point-to-line/types.ts
new file mode 100644
index 0000000000..1d21fd8b5a
--- /dev/null
+++ b/packages/turf-nearest-point-to-line/types.ts
@@ -0,0 +1,13 @@
+import { geometryCollection, featureCollection, point, lineString } from '@turf/helpers'
+import * as nearestPointToLine from './'
+
+const points = featureCollection([point([0, 0]), point([0.5, 0.5])]);
+const line = lineString([[1,1], [-1,1]]);
+
+const nearest = nearestPointToLine(points, line)
+nearest.properties.dist
+nearest.properties.foo
+
+// GeometryCollection
+const geomPoints = geometryCollection([point([0, 0]).geometry, point([0.5, 0.5]).geometry]);
+nearestPointToLine(geomPoints, line)
\ No newline at end of file
diff --git a/packages/turf-nearest-point-to-line/yarn.lock b/packages/turf-nearest-point-to-line/yarn.lock
new file mode 100644
index 0000000000..c8c241ac59
--- /dev/null
+++ b/packages/turf-nearest-point-to-line/yarn.lock
@@ -0,0 +1,376 @@
+# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
+# yarn lockfile v1
+
+
+"@turf/bearing@^4.7.3":
+ version "4.7.3"
+ resolved "https://registry.yarnpkg.com/@turf/bearing/-/bearing-4.7.3.tgz#efd1a8a5c8ca0cdbecbcc02172c41ed216dff8f9"
+ dependencies:
+ "@turf/invariant" "^4.7.3"
+
+"@turf/circle@^4.7.3":
+ version "4.7.3"
+ resolved "https://registry.yarnpkg.com/@turf/circle/-/circle-4.7.3.tgz#e8f996ff87b0ca8e3e6b74b60f6ab5daf9086713"
+ dependencies:
+ "@turf/destination" "^4.7.3"
+ "@turf/helpers" "^4.7.3"
+
+"@turf/destination@^4.7.3":
+ version "4.7.3"
+ resolved "https://registry.yarnpkg.com/@turf/destination/-/destination-4.7.3.tgz#f1ea3bb3705cf52fed135a7917d49336e47b8d2e"
+ dependencies:
+ "@turf/helpers" "^4.7.3"
+ "@turf/invariant" "^4.7.3"
+
+"@turf/distance@^4.7.3":
+ version "4.7.3"
+ resolved "https://registry.yarnpkg.com/@turf/distance/-/distance-4.7.3.tgz#b5ab48a09a642706d65c39b919433d5d2cc571b1"
+ dependencies:
+ "@turf/helpers" "^4.7.3"
+ "@turf/invariant" "^4.7.3"
+
+"@turf/helpers@4.7.1":
+ version "4.7.1"
+ resolved "https://registry.yarnpkg.com/@turf/helpers/-/helpers-4.7.1.tgz#12cecbfe22b16386338537dae3e3da83de2f3fac"
+
+"@turf/helpers@^4.7.3":
+ version "4.7.3"
+ resolved "https://registry.yarnpkg.com/@turf/helpers/-/helpers-4.7.3.tgz#bc312ac43cab3c532a483151c4c382c5649429e9"
+
+"@turf/invariant@^4.7.3":
+ version "4.7.3"
+ resolved "https://registry.yarnpkg.com/@turf/invariant/-/invariant-4.7.3.tgz#538f367d23c113fc849d70c9a524b8563874601d"
+
+"@turf/meta@^4.7.3":
+ version "4.7.3"
+ resolved "https://registry.yarnpkg.com/@turf/meta/-/meta-4.7.3.tgz#038970178e90c8e43cf7dfed79d5782298a1080d"
+
+"@turf/point-to-line-distance@^4.7.3":
+ version "4.7.3"
+ resolved "https://registry.yarnpkg.com/@turf/point-to-line-distance/-/point-to-line-distance-4.7.3.tgz#1cd17a27a9438b5f3ae3717af7f0908258df0865"
+ dependencies:
+ "@turf/bearing" "^4.7.3"
+ "@turf/distance" "^4.7.3"
+ "@turf/helpers" "^4.7.3"
+ "@turf/invariant" "^4.7.3"
+ "@turf/meta" "^4.7.3"
+ "@turf/rhumb-bearing" "^4.7.3"
+ "@turf/rhumb-distance" "^4.7.3"
+
+"@turf/rhumb-bearing@^4.7.3":
+ version "4.7.3"
+ resolved "https://registry.yarnpkg.com/@turf/rhumb-bearing/-/rhumb-bearing-4.7.3.tgz#db1821b62706fb403adbf9413cc5e56b79006146"
+ dependencies:
+ "@turf/invariant" "^4.7.3"
+ geodesy "1.1.2"
+
+"@turf/rhumb-distance@^4.7.3":
+ version "4.7.3"
+ resolved "https://registry.yarnpkg.com/@turf/rhumb-distance/-/rhumb-distance-4.7.3.tgz#30eebc6b785502bd8e08548069712c9709ed22d4"
+ dependencies:
+ "@turf/helpers" "^4.7.3"
+ "@turf/invariant" "^4.7.3"
+ geodesy "1.1.2"
+
+"@turf/truncate@^4.7.3":
+ version "4.7.3"
+ resolved "https://registry.yarnpkg.com/@turf/truncate/-/truncate-4.7.3.tgz#827a8df8ff0c9fff9dcf1a4b3145cbdef80fb993"
+ dependencies:
+ "@turf/meta" "^4.7.3"
+
+balanced-match@^1.0.0:
+ version "1.0.0"
+ resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
+
+benchmark@^2.1.4:
+ version "2.1.4"
+ resolved "https://registry.yarnpkg.com/benchmark/-/benchmark-2.1.4.tgz#09f3de31c916425d498cc2ee565a0ebf3c2a5629"
+ dependencies:
+ lodash "^4.17.4"
+ platform "^1.3.3"
+
+brace-expansion@^1.1.7:
+ version "1.1.8"
+ resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.8.tgz#c07b211c7c952ec1f8efd51a77ef0d1d3990a292"
+ dependencies:
+ balanced-match "^1.0.0"
+ concat-map "0.0.1"
+
+concat-map@0.0.1:
+ version "0.0.1"
+ resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
+
+deep-equal@~1.0.1:
+ version "1.0.1"
+ resolved "https://registry.yarnpkg.com/deep-equal/-/deep-equal-1.0.1.tgz#f5d260292b660e084eff4cdbc9f08ad3247448b5"
+
+define-properties@^1.1.2:
+ version "1.1.2"
+ resolved "https://registry.yarnpkg.com/define-properties/-/define-properties-1.1.2.tgz#83a73f2fea569898fb737193c8f873caf6d45c94"
+ dependencies:
+ foreach "^2.0.5"
+ object-keys "^1.0.8"
+
+defined@~1.0.0:
+ version "1.0.0"
+ resolved "https://registry.yarnpkg.com/defined/-/defined-1.0.0.tgz#c98d9bcef75674188e110969151199e39b1fa693"
+
+detect-indent@^5.0.0:
+ version "5.0.0"
+ resolved "https://registry.yarnpkg.com/detect-indent/-/detect-indent-5.0.0.tgz#3871cc0a6a002e8c3e5b3cf7f336264675f06b9d"
+
+error-ex@^1.2.0:
+ version "1.3.1"
+ resolved "https://registry.yarnpkg.com/error-ex/-/error-ex-1.3.1.tgz#f855a86ce61adc4e8621c3cda21e7a7612c3a8dc"
+ dependencies:
+ is-arrayish "^0.2.1"
+
+es-abstract@^1.5.0:
+ version "1.8.2"
+ resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.8.2.tgz#25103263dc4decbda60e0c737ca32313518027ee"
+ dependencies:
+ es-to-primitive "^1.1.1"
+ function-bind "^1.1.1"
+ has "^1.0.1"
+ is-callable "^1.1.3"
+ is-regex "^1.0.4"
+
+es-to-primitive@^1.1.1:
+ version "1.1.1"
+ resolved "https://registry.yarnpkg.com/es-to-primitive/-/es-to-primitive-1.1.1.tgz#45355248a88979034b6792e19bb81f2b7975dd0d"
+ dependencies:
+ is-callable "^1.1.1"
+ is-date-object "^1.0.1"
+ is-symbol "^1.0.1"
+
+for-each@~0.3.2:
+ version "0.3.2"
+ resolved "https://registry.yarnpkg.com/for-each/-/for-each-0.3.2.tgz#2c40450b9348e97f281322593ba96704b9abd4d4"
+ dependencies:
+ is-function "~1.0.0"
+
+foreach@^2.0.5:
+ version "2.0.5"
+ resolved "https://registry.yarnpkg.com/foreach/-/foreach-2.0.5.tgz#0bee005018aeb260d0a3af3ae658dd0136ec1b99"
+
+fs.realpath@^1.0.0:
+ version "1.0.0"
+ resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
+
+function-bind@^1.0.2, function-bind@^1.1.1, function-bind@~1.1.0:
+ version "1.1.1"
+ resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d"
+
+geodesy@1.1.2:
+ version "1.1.2"
+ resolved "https://registry.yarnpkg.com/geodesy/-/geodesy-1.1.2.tgz#84cbdf7e7b98907bd3b13b09ae86c65926391a50"
+
+glob@~7.1.2:
+ version "7.1.2"
+ resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15"
+ dependencies:
+ fs.realpath "^1.0.0"
+ inflight "^1.0.4"
+ inherits "2"
+ minimatch "^3.0.4"
+ once "^1.3.0"
+ path-is-absolute "^1.0.0"
+
+graceful-fs@^4.1.11, graceful-fs@^4.1.2:
+ version "4.1.11"
+ resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"
+
+has@^1.0.1, has@~1.0.1:
+ version "1.0.1"
+ resolved "https://registry.yarnpkg.com/has/-/has-1.0.1.tgz#8461733f538b0837c9361e39a9ab9e9704dc2f28"
+ dependencies:
+ function-bind "^1.0.2"
+
+imurmurhash@^0.1.4:
+ version "0.1.4"
+ resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea"
+
+inflight@^1.0.4:
+ version "1.0.6"
+ resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9"
+ dependencies:
+ once "^1.3.0"
+ wrappy "1"
+
+inherits@2, inherits@~2.0.3:
+ version "2.0.3"
+ resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"
+
+is-arrayish@^0.2.1:
+ version "0.2.1"
+ resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d"
+
+is-callable@^1.1.1, is-callable@^1.1.3:
+ version "1.1.3"
+ resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.1.3.tgz#86eb75392805ddc33af71c92a0eedf74ee7604b2"
+
+is-date-object@^1.0.1:
+ version "1.0.1"
+ resolved "https://registry.yarnpkg.com/is-date-object/-/is-date-object-1.0.1.tgz#9aa20eb6aeebbff77fbd33e74ca01b33581d3a16"
+
+is-function@~1.0.0:
+ version "1.0.1"
+ resolved "https://registry.yarnpkg.com/is-function/-/is-function-1.0.1.tgz#12cfb98b65b57dd3d193a3121f5f6e2f437602b5"
+
+is-plain-obj@^1.0.0:
+ version "1.1.0"
+ resolved "https://registry.yarnpkg.com/is-plain-obj/-/is-plain-obj-1.1.0.tgz#71a50c8429dfca773c92a390a4a03b39fcd51d3e"
+
+is-regex@^1.0.4:
+ version "1.0.4"
+ resolved "https://registry.yarnpkg.com/is-regex/-/is-regex-1.0.4.tgz#5517489b547091b0930e095654ced25ee97e9491"
+ dependencies:
+ has "^1.0.1"
+
+is-symbol@^1.0.1:
+ version "1.0.1"
+ resolved "https://registry.yarnpkg.com/is-symbol/-/is-symbol-1.0.1.tgz#3cc59f00025194b6ab2e38dbae6689256b660572"
+
+load-json-file@^2.0.0:
+ version "2.0.0"
+ resolved "https://registry.yarnpkg.com/load-json-file/-/load-json-file-2.0.0.tgz#7947e42149af80d696cbf797bcaabcfe1fe29ca8"
+ dependencies:
+ graceful-fs "^4.1.2"
+ parse-json "^2.2.0"
+ pify "^2.0.0"
+ strip-bom "^3.0.0"
+
+lodash@^4.17.4:
+ version "4.17.4"
+ resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
+
+make-dir@^1.0.0:
+ version "1.0.0"
+ resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-1.0.0.tgz#97a011751e91dd87cfadef58832ebb04936de978"
+ dependencies:
+ pify "^2.3.0"
+
+minimatch@^3.0.4:
+ version "3.0.4"
+ resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
+ dependencies:
+ brace-expansion "^1.1.7"
+
+minimist@~1.2.0:
+ version "1.2.0"
+ resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284"
+
+object-inspect@~1.3.0:
+ version "1.3.0"
+ resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.3.0.tgz#5b1eb8e6742e2ee83342a637034d844928ba2f6d"
+
+object-keys@^1.0.8:
+ version "1.0.11"
+ resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.0.11.tgz#c54601778ad560f1142ce0e01bcca8b56d13426d"
+
+once@^1.3.0:
+ version "1.4.0"
+ resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1"
+ dependencies:
+ wrappy "1"
+
+parse-json@^2.2.0:
+ version "2.2.0"
+ resolved "https://registry.yarnpkg.com/parse-json/-/parse-json-2.2.0.tgz#f480f40434ef80741f8469099f8dea18f55a4dc9"
+ dependencies:
+ error-ex "^1.2.0"
+
+path-is-absolute@^1.0.0:
+ version "1.0.1"
+ resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"
+
+path-parse@^1.0.5:
+ version "1.0.5"
+ resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.5.tgz#3c1adf871ea9cd6c9431b6ea2bd74a0ff055c4c1"
+
+pify@^2.0.0, pify@^2.3.0:
+ version "2.3.0"
+ resolved "https://registry.yarnpkg.com/pify/-/pify-2.3.0.tgz#ed141a6ac043a849ea588498e7dca8b15330e90c"
+
+platform@^1.3.3:
+ version "1.3.4"
+ resolved "https://registry.yarnpkg.com/platform/-/platform-1.3.4.tgz#6f0fb17edaaa48f21442b3a975c063130f1c3ebd"
+
+resolve@~1.4.0:
+ version "1.4.0"
+ resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.4.0.tgz#a75be01c53da25d934a98ebd0e4c4a7312f92a86"
+ dependencies:
+ path-parse "^1.0.5"
+
+resumer@~0.0.0:
+ version "0.0.0"
+ resolved "https://registry.yarnpkg.com/resumer/-/resumer-0.0.0.tgz#f1e8f461e4064ba39e82af3cdc2a8c893d076759"
+ dependencies:
+ through "~2.3.4"
+
+signal-exit@^3.0.2:
+ version "3.0.2"
+ resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
+
+sort-keys@^1.1.1:
+ version "1.1.2"
+ resolved "https://registry.yarnpkg.com/sort-keys/-/sort-keys-1.1.2.tgz#441b6d4d346798f1b4e49e8920adfba0e543f9ad"
+ dependencies:
+ is-plain-obj "^1.0.0"
+
+string.prototype.trim@~1.1.2:
+ version "1.1.2"
+ resolved "https://registry.yarnpkg.com/string.prototype.trim/-/string.prototype.trim-1.1.2.tgz#d04de2c89e137f4d7d206f086b5ed2fae6be8cea"
+ dependencies:
+ define-properties "^1.1.2"
+ es-abstract "^1.5.0"
+ function-bind "^1.0.2"
+
+strip-bom@^3.0.0:
+ version "3.0.0"
+ resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3"
+
+tape@^4.6.3:
+ version "4.8.0"
+ resolved "https://registry.yarnpkg.com/tape/-/tape-4.8.0.tgz#f6a9fec41cc50a1de50fa33603ab580991f6068e"
+ dependencies:
+ deep-equal "~1.0.1"
+ defined "~1.0.0"
+ for-each "~0.3.2"
+ function-bind "~1.1.0"
+ glob "~7.1.2"
+ has "~1.0.1"
+ inherits "~2.0.3"
+ minimist "~1.2.0"
+ object-inspect "~1.3.0"
+ resolve "~1.4.0"
+ resumer "~0.0.0"
+ string.prototype.trim "~1.1.2"
+ through "~2.3.8"
+
+through@~2.3.4, through@~2.3.8:
+ version "2.3.8"
+ resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"
+
+wrappy@1:
+ version "1.0.2"
+ resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"
+
+write-file-atomic@^2.0.0:
+ version "2.3.0"
+ resolved "https://registry.yarnpkg.com/write-file-atomic/-/write-file-atomic-2.3.0.tgz#1ff61575c2e2a4e8e510d6fa4e243cce183999ab"
+ dependencies:
+ graceful-fs "^4.1.11"
+ imurmurhash "^0.1.4"
+ signal-exit "^3.0.2"
+
+write-json-file@^2.2.0:
+ version "2.2.0"
+ resolved "https://registry.yarnpkg.com/write-json-file/-/write-json-file-2.2.0.tgz#51862506bbb3b619eefab7859f1fd6c6d0530876"
+ dependencies:
+ detect-indent "^5.0.0"
+ graceful-fs "^4.1.2"
+ make-dir "^1.0.0"
+ pify "^2.0.0"
+ sort-keys "^1.1.1"
+ write-file-atomic "^2.0.0"
diff --git a/packages/turf-point-to-line-distance/index.d.ts b/packages/turf-point-to-line-distance/index.d.ts
index 5bf3c17185..3a5cfaed4b 100644
--- a/packages/turf-point-to-line-distance/index.d.ts
+++ b/packages/turf-point-to-line-distance/index.d.ts
@@ -3,7 +3,7 @@
import {Units} from '@turf/helpers'
type Point = GeoJSON.Feature | GeoJSON.Point | number[];
-type LineString = GeoJSON.LineString;
+type LineString = GeoJSON.Feature | GeoJSON.LineString;
/**
* http://turfjs.org/docs/#pointto-line-distance
diff --git a/packages/turf-point-to-line-distance/index.js b/packages/turf-point-to-line-distance/index.js
index f6ef1dd391..d228e8622d 100644
--- a/packages/turf-point-to-line-distance/index.js
+++ b/packages/turf-point-to-line-distance/index.js
@@ -1,20 +1,13 @@
// (logic of computation inspired by:
// https://stackoverflow.com/questions/32771458/distance-from-lat-lng-point-to-minor-arc-segment)
-var meta = require('@turf/meta');
+var segmentEach = require('@turf/meta').segmentEach;
var bearing = require('@turf/bearing');
var helpers = require('@turf/helpers');
var distance = require('@turf/distance');
-var invariant = require('@turf/invariant');
+var featureOf = require('@turf/invariant').featureOf;
var rhumbBearing = require('@turf/rhumb-bearing');
var rhumbDistance = require('@turf/rhumb-distance');
-var turfLine = helpers.lineString;
-var featureOf = invariant.featureOf;
-var turfPoint = helpers.point;
-var segmentEach = meta.segmentEach;
-var bearingToAngle = helpers.bearingToAngle;
-var convertDistance = helpers.convertDistance;
-var degrees2radians = helpers.degrees2radians;
/**
* Returns the minimum distance between a {@link Point} and a {@link LineString}, being the distance from a line the
@@ -36,10 +29,13 @@ var degrees2radians = helpers.degrees2radians;
module.exports = function (point, line, units, mercator) {
// validation
if (!point) throw new Error('point is required');
- if (Array.isArray(point)) point = turfPoint(point);
+ if (Array.isArray(point)) point = helpers.point(point);
+ else if (point.type === 'Point') point = {type: 'Feature', geometry: point};
else featureOf(point, 'Point', 'point');
+
if (!line) throw new Error('line is required');
- if (Array.isArray(line)) line = turfLine(line);
+ if (Array.isArray(line)) line = helpers.lineString(line);
+ else if (line.type === 'LineString') line = {type: 'Feature', properties: {}, geometry: line};
else featureOf(line, 'LineString', 'line');
var distance = Infinity;
@@ -68,8 +64,8 @@ module.exports = function (point, line, units, mercator) {
function distanceToSegment(p, a, b, units, mercator) {
var distanceAP = (mercator !== true) ? distance(a, p, units) : euclideanDistance(a, p, units);
- var azimuthAP = bearingToAngle((mercator !== true) ? bearing(a, p) : rhumbBearing(a, p));
- var azimuthAB = bearingToAngle((mercator !== true) ? bearing(a, b) : rhumbBearing(a, b));
+ var azimuthAP = helpers.bearingToAngle((mercator !== true) ? bearing(a, p) : rhumbBearing(a, p));
+ var azimuthAB = helpers.bearingToAngle((mercator !== true) ? bearing(a, b) : rhumbBearing(a, b));
var angleA = Math.abs(azimuthAP - azimuthAB);
// if (angleA > 180) angleA = Math.abs(angleA - 360);
// if the angle PAB is obtuse its projection on the line extending the segment falls outside the segment
@@ -85,7 +81,7 @@ function distanceToSegment(p, a, b, units, mercator) {
if (angleA > 90) return distanceAP;
var azimuthBA = (azimuthAB + 180) % 360;
- var azimuthBP = bearingToAngle((mercator !== true) ? bearing(b, p) : rhumbBearing(b, p));
+ var azimuthBP = helpers.bearingToAngle((mercator !== true) ? bearing(b, p) : rhumbBearing(b, p));
var angleB = Math.abs(azimuthBP - azimuthBA);
if (angleB > 180) angleB = Math.abs(angleB - 360);
// also if the angle ABP is acute the projection of P falls outside the segment, on the other side
@@ -110,7 +106,7 @@ function distanceToSegment(p, a, b, units, mercator) {
/____________|____\
A H B
*/
- if (mercator !== true) return distanceAP * Math.sin(degrees2radians(angleA));
+ if (mercator !== true) return distanceAP * Math.sin(helpers.degrees2radians(angleA));
return mercatorPH(a, b, p, units);
}
@@ -131,7 +127,7 @@ function mercatorPH(a, b, p, units) {
delta = (a[0] > 0 || b[0] > 0 || p[0] > 0) ? -180 : 180;
}
- var origin = turfPoint(p);
+ var origin = helpers.point(p);
var A = toMercator([a[0] + delta, a[1]]);
var B = toMercator([b[0] + delta, b[1]]);
var P = toMercator([p[0] + delta, p[1]]);
@@ -194,7 +190,7 @@ function euclideanDistance(from, to, units) {
var sqr = function (n) { return n * n; };
var squareD = sqr(p1[0] - p2[0]) + sqr(p1[1] - p2[1]);
var d = Math.sqrt(squareD);
- return convertDistance(d, 'meters', units);
+ return helpers.convertDistance(d, 'meters', units);
}
/**
diff --git a/packages/turf-point-to-line-distance/test.js b/packages/turf-point-to-line-distance/test.js
index 62d6989225..229c524a92 100644
--- a/packages/turf-point-to-line-distance/test.js
+++ b/packages/turf-point-to-line-distance/test.js
@@ -21,26 +21,28 @@ const fixtures = fs.readdirSync(directories.in).map(filename => {
});
test('turf-point-to-line-distance', t => {
+ const results = {};
for (const {filename, name, geojson} of fixtures) {
const [point, line] = geojson.features;
let {units, mercator} = geojson.properties || {};
if (!units) units = 'kilometers';
const distance = pointToLineDistance(point, line, units, mercator);
- // debug
- var c = circle(point, distance, 200, units);
- geojson.features.push(c);
+ // Store results
+ results[name] = round(distance, 10);
- if (process.env.REGEN) write.sync(directories.out + filename, results);
- const expected = load.sync(directories.out + 'distances.json');
- t.deepEqual(round(distance, 10), round(expected[name], 10), name);
+ // debug purposes
+ geojson.features.push(circle(point, distance, 200, units));
+ if (process.env.REGEN) write.sync(directories.out + filename, geojson);
}
+ if (process.env.REGEN) write.sync(directories.out + 'distances.json', results);
+ t.deepEqual(load.sync(directories.out + 'distances.json'), results);
t.end();
});
test('turf-point-to-line-distance -- throws', t => {
const pt = point([0, 0]);
- const line = lineString([[1,1], [-1,1]]);
+ const line = lineString([[1, 1], [-1, 1]]);
t.throws(() => pointToLineDistance(null, line), /point is required/, 'missing point');
t.throws(() => pointToLineDistance(pt, null), /line is required/, 'missing line');
@@ -50,3 +52,11 @@ test('turf-point-to-line-distance -- throws', t => {
t.end();
});
+
+test('turf-point-to-line-distance -- Geometry', t => {
+ const pt = point([0, 0]);
+ const line = lineString([[1, 1], [-1, 1]]);
+
+ t.assert(pointToLineDistance(pt.geometry, line.geometry));
+ t.end();
+});
diff --git a/packages/turf-point-to-line-distance/test/out/distances.json b/packages/turf-point-to-line-distance/test/out/distances.json
index 18aab3dcfe..13106914d5 100644
--- a/packages/turf-point-to-line-distance/test/out/distances.json
+++ b/packages/turf-point-to-line-distance/test/out/distances.json
@@ -1,21 +1,21 @@
{
- "segment1": 69.09334842498865,
- "segment1a": 69.09334842498865,
- "segment2": 69.09334842498865,
- "segment3": 69.17074902579057,
- "segment4": 333.73911452247074,
- "segment-fiji": 27.556466166676397,
- "line1": 23.616870857680677,
- "line2": 188.02212276470638,
- "line-fiji": 27.016029431060844,
- "line-resolute-bay": 424.56987879032073,
- "city-line1": 0.9997112294789969,
- "city-line2": 3.583891652669501,
- "city-segment-inside1": 1.1447896287675474,
- "city-segment-inside2": 0.9977971634304259,
- "city-segment-inside3": 3.4981840220723557,
- "city-segment-obtuse1": 2.8582176667031516,
- "city-segment-obtuse2": 3.35493956118816,
- "city-segment-projected1": 3.589782772179696,
- "city-segment-projected2": 4.1647711521094095
-}
\ No newline at end of file
+ "city-line1": 0.9997112295,
+ "city-line2": 3.5838916527,
+ "city-segment-inside1": 1.1447896288,
+ "city-segment-inside2": 0.9977971634,
+ "city-segment-inside3": 3.4981840221,
+ "city-segment-obtuse1": 2.8582176667,
+ "city-segment-obtuse2": 3.3549395612,
+ "city-segment-projected1": 3.5897827722,
+ "city-segment-projected2": 4.1647711521,
+ "line-fiji": 27.0160294311,
+ "line-resolute-bay": 424.5698787903,
+ "line1": 23.6168708577,
+ "line2": 188.0221227647,
+ "segment-fiji": 27.5564661667,
+ "segment1": 69.093348425,
+ "segment1a": 69.093348425,
+ "segment2": 69.093348425,
+ "segment3": 69.1707490258,
+ "segment4": 333.7391145225
+}
diff --git a/packages/turf-point-to-line-distance/types.ts b/packages/turf-point-to-line-distance/types.ts
new file mode 100644
index 0000000000..241c526f4e
--- /dev/null
+++ b/packages/turf-point-to-line-distance/types.ts
@@ -0,0 +1,10 @@
+import { point, lineString } from '@turf/helpers'
+import * as pointToLineDistance from './'
+
+const pt = point([0, 0])
+const line = lineString([[1, 1],[-1, 1]])
+const distance: number = pointToLineDistance(pt, line, 'miles')
+
+pointToLineDistance(pt, line)
+pointToLineDistance(pt, line, 'miles')
+pointToLineDistance(pt, line, 'miles', true)