all these changes

This commit is contained in:
Jake Kasper
2026-04-09 13:19:47 -05:00
parent e83a51a051
commit 65315f36d1
39102 changed files with 7932979 additions and 567 deletions

View File

@@ -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.

View File

@@ -0,0 +1,86 @@
# @turf/nearest-point-to-line
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
## nearestPointToLine
Returns the closest [point][1], of a [collection][2] of points, to a [line][3].
The returned point has a `dist` property indicating its distance to the line.
**Parameters**
- `points` **([FeatureCollection][4] \| [GeometryCollection][5]&lt;[Point][6]>)** Point Collection
- `line` **([Feature][7] \| [Geometry][8]&lt;[LineString][9]>)** Line Feature
- `options` **[Object][10]?** Optional parameters
- `options.units` **[string][11]** unit of the output distance property, can be degrees, radians, miles, or kilometers (optional, default `'kilometers'`)
- `options.properties` **[Object][10]** Translate Properties to Point (optional, default `{}`)
**Examples**
```javascript
var pt1 = turf.point([0, 0]);
var pt2 = turf.point([0.5, 0.5]);
var points = turf.featureCollection([pt1, pt2]);
var line = turf.lineString([[1,1], [-1,1]]);
var nearest = turf.nearestPointToLine(points, line);
//addToMap
var addToMap = [nearest, line];
```
Returns **[Feature][7]&lt;[Point][6]>** the closest point
## pt
Translate Properties to final Point, priorities:
1\. options.properties
2\. inherent Point properties
3\. dist custom properties created by NearestPointToLine
[1]: https://tools.ietf.org/html/rfc7946#section-3.1.2
[2]: https://tools.ietf.org/html/rfc7946#section-3.3
[3]: https://tools.ietf.org/html/rfc7946#section-3.1.4
[4]: https://tools.ietf.org/html/rfc7946#section-3.3
[5]: https://tools.ietf.org/html/rfc7946#section-3.1.8
[6]: https://tools.ietf.org/html/rfc7946#section-3.1.2
[7]: https://tools.ietf.org/html/rfc7946#section-3.2
[8]: https://tools.ietf.org/html/rfc7946#section-3.1
[9]: https://tools.ietf.org/html/rfc7946#section-3.1.4
[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
<!-- This file is automatically generated. Please don't edit it directly:
if you find an error, edit the source file (likely index.js), and re-run
./scripts/generate-readmes in the turf project. -->
---
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
```

View File

@@ -0,0 +1,91 @@
import { getType } from "@turf/invariant";
import { featureEach, geomEach } from "@turf/meta";
import pointToLineDistance from "@turf/point-to-line-distance";
import objectAssign from "object-assign";
/**
* 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<Point>} points Point Collection
* @param {Feature|Geometry<LineString>} line Line Feature
* @param {Object} [options] Optional parameters
* @param {string} [options.units='kilometers'] unit of the output distance property
* (eg: degrees, radians, miles, or kilometers)
* @param {Object} [options.properties={}] Translate Properties to Point
* @returns {Feature<Point>} the closest point
* @example
* var pt1 = turf.point([0, 0]);
* var pt2 = turf.point([0.5, 0.5]);
* var points = turf.featureCollection([pt1, pt2]);
* var line = turf.lineString([[1,1], [-1,1]]);
*
* var nearest = turf.nearestPointToLine(points, line);
*
* //addToMap
* var addToMap = [nearest, line];
*/
function nearestPointToLine(points, line, options) {
if (options === void 0) { options = {}; }
var units = options.units;
var properties = options.properties || {};
// validation
var pts = normalize(points);
if (!pts.features.length) {
throw new Error("points must contain features");
}
if (!line) {
throw new Error("line is required");
}
if (getType(line) !== "LineString") {
throw new Error("line must be a LineString");
}
var dist = Infinity;
var pt = null;
featureEach(pts, function (point) {
var d = pointToLineDistance(point, line, { units: units });
if (d < dist) {
dist = d;
pt = point;
}
});
/**
* Translate Properties to final Point, priorities:
* 1. options.properties
* 2. inherent Point properties
* 3. dist custom properties created by NearestPointToLine
*/
if (pt) {
pt.properties = objectAssign({ dist: dist }, pt.properties, properties);
}
// if (pt) { pt.properties = objectAssign({dist}, pt.properties, properties); }
return pt;
}
/**
* Convert Collection to FeatureCollection
*
* @private
* @param {FeatureCollection|GeometryCollection} points Points
* @returns {FeatureCollection<Point>} points
*/
function normalize(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");
}
}
export default nearestPointToLine;

View File

@@ -0,0 +1 @@
{"type":"module"}

View File

@@ -0,0 +1,32 @@
import { Feature, FeatureCollection, GeometryCollection, LineString, Point, Properties, Units } from "@turf/helpers";
/**
* 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<Point>} points Point Collection
* @param {Feature|Geometry<LineString>} line Line Feature
* @param {Object} [options] Optional parameters
* @param {string} [options.units='kilometers'] unit of the output distance property
* (eg: degrees, radians, miles, or kilometers)
* @param {Object} [options.properties={}] Translate Properties to Point
* @returns {Feature<Point>} the closest point
* @example
* var pt1 = turf.point([0, 0]);
* var pt2 = turf.point([0.5, 0.5]);
* var points = turf.featureCollection([pt1, pt2]);
* var line = turf.lineString([[1,1], [-1,1]]);
*
* var nearest = turf.nearestPointToLine(points, line);
*
* //addToMap
* var addToMap = [nearest, line];
*/
declare function nearestPointToLine<P = {
dist: number;
[key: string]: any;
}>(points: FeatureCollection<Point> | Feature<GeometryCollection> | GeometryCollection, line: Feature<LineString> | LineString, options?: {
units?: Units;
properties?: Properties;
}): Feature<Point, P>;
export default nearestPointToLine;

View File

@@ -0,0 +1,96 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var invariant_1 = require("@turf/invariant");
var meta_1 = require("@turf/meta");
var point_to_line_distance_1 = __importDefault(require("@turf/point-to-line-distance"));
var object_assign_1 = __importDefault(require("object-assign"));
/**
* 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<Point>} points Point Collection
* @param {Feature|Geometry<LineString>} line Line Feature
* @param {Object} [options] Optional parameters
* @param {string} [options.units='kilometers'] unit of the output distance property
* (eg: degrees, radians, miles, or kilometers)
* @param {Object} [options.properties={}] Translate Properties to Point
* @returns {Feature<Point>} the closest point
* @example
* var pt1 = turf.point([0, 0]);
* var pt2 = turf.point([0.5, 0.5]);
* var points = turf.featureCollection([pt1, pt2]);
* var line = turf.lineString([[1,1], [-1,1]]);
*
* var nearest = turf.nearestPointToLine(points, line);
*
* //addToMap
* var addToMap = [nearest, line];
*/
function nearestPointToLine(points, line, options) {
if (options === void 0) { options = {}; }
var units = options.units;
var properties = options.properties || {};
// validation
var pts = normalize(points);
if (!pts.features.length) {
throw new Error("points must contain features");
}
if (!line) {
throw new Error("line is required");
}
if (invariant_1.getType(line) !== "LineString") {
throw new Error("line must be a LineString");
}
var dist = Infinity;
var pt = null;
meta_1.featureEach(pts, function (point) {
var d = point_to_line_distance_1.default(point, line, { units: units });
if (d < dist) {
dist = d;
pt = point;
}
});
/**
* Translate Properties to final Point, priorities:
* 1. options.properties
* 2. inherent Point properties
* 3. dist custom properties created by NearestPointToLine
*/
if (pt) {
pt.properties = object_assign_1.default({ dist: dist }, pt.properties, properties);
}
// if (pt) { pt.properties = objectAssign({dist}, pt.properties, properties); }
return pt;
}
/**
* Convert Collection to FeatureCollection
*
* @private
* @param {FeatureCollection|GeometryCollection} points Points
* @returns {FeatureCollection<Point>} points
*/
function normalize(points) {
var features = [];
var type = points.geometry ? points.geometry.type : points.type;
switch (type) {
case "GeometryCollection":
meta_1.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");
}
}
exports.default = nearestPointToLine;

View File

@@ -0,0 +1,75 @@
{
"name": "@turf/nearest-point-to-line",
"version": "6.5.0",
"description": "turf nearest-point-to-line module",
"author": "Turf Authors",
"contributors": [
"Stefano Borghi <@stebogit>"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/Turfjs/turf/issues"
},
"homepage": "https://github.com/Turfjs/turf",
"repository": {
"type": "git",
"url": "git://github.com/Turfjs/turf.git"
},
"funding": "https://opencollective.com/turf",
"publishConfig": {
"access": "public"
},
"keywords": [
"turf",
"geojson",
"gis",
"near",
"nearest-point-to-line"
],
"main": "dist/js/index.js",
"module": "dist/es/index.js",
"exports": {
"./package.json": "./package.json",
".": {
"import": "./dist/es/index.js",
"require": "./dist/js/index.js"
}
},
"types": "dist/js/index.d.ts",
"sideEffects": false,
"files": [
"dist"
],
"scripts": {
"bench": "ts-node bench.js",
"build": "npm-run-all build:*",
"build:es": "tsc --outDir dist/es --module esnext --declaration false && echo '{\"type\":\"module\"}' > dist/es/package.json",
"build:js": "tsc",
"docs": "node ../../scripts/generate-readmes",
"test": "npm-run-all test:*",
"test:tape": "ts-node -r esm test.js",
"test:types": "tsc --esModuleInterop --noEmit types.ts"
},
"devDependencies": {
"@turf/circle": "^6.5.0",
"@turf/truncate": "^6.5.0",
"@types/object-assign": "*",
"@types/tape": "*",
"benchmark": "*",
"load-json-file": "*",
"npm-run-all": "*",
"tape": "*",
"ts-node": "*",
"tslint": "*",
"typescript": "*",
"write-json-file": "*"
},
"dependencies": {
"@turf/helpers": "^6.5.0",
"@turf/invariant": "^6.5.0",
"@turf/meta": "^6.5.0",
"@turf/point-to-line-distance": "^6.5.0",
"object-assign": "*"
},
"gitHead": "5375941072b90d489389db22b43bfe809d5e451e"
}