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
+20
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.
+68
View File
@@ -0,0 +1,68 @@
# @turf/line-segment
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
## lineSegment
Creates a [FeatureCollection][1] of 2-vertex [LineString][2] segments from a [(Multi)LineString][2] or [(Multi)Polygon][3].
**Parameters**
- `geojson` **([Geometry][4] \| [FeatureCollection][5] \| [Feature][6]&lt;([LineString][7] \| [MultiLineString][8] \| [MultiPolygon][9] \| [Polygon][10])>)** GeoJSON Polygon or LineString
**Examples**
```javascript
var polygon = turf.polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]);
var segments = turf.lineSegment(polygon);
//addToMap
var addToMap = [polygon, segments]
```
Returns **[FeatureCollection][5]&lt;[LineString][7]>** 2-vertex line segments
[1]: https://tools.ietf.org/html/rfc7946#section-3.3
[2]: https://tools.ietf.org/html/rfc7946#section-3.1.4
[3]: https://tools.ietf.org/html/rfc7946#section-3.1.6
[4]: https://tools.ietf.org/html/rfc7946#section-3.1
[5]: https://tools.ietf.org/html/rfc7946#section-3.3
[6]: https://tools.ietf.org/html/rfc7946#section-3.2
[7]: https://tools.ietf.org/html/rfc7946#section-3.1.4
[8]: https://tools.ietf.org/html/rfc7946#section-3.1.5
[9]: https://tools.ietf.org/html/rfc7946#section-3.1.7
[10]: https://tools.ietf.org/html/rfc7946#section-3.1.6
<!-- 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/line-segment
```
Or install the Turf module that includes it as a function:
```sh
$ npm install @turf/turf
```
+93
View File
@@ -0,0 +1,93 @@
import { featureCollection, lineString, } from "@turf/helpers";
import { getCoords } from "@turf/invariant";
import { flattenEach } from "@turf/meta";
/**
* Creates a {@link FeatureCollection} of 2-vertex {@link LineString} segments from a
* {@link LineString|(Multi)LineString} or {@link Polygon|(Multi)Polygon}.
*
* @name lineSegment
* @param {GeoJSON} geojson GeoJSON Polygon or LineString
* @returns {FeatureCollection<LineString>} 2-vertex line segments
* @example
* var polygon = turf.polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]);
* var segments = turf.lineSegment(polygon);
*
* //addToMap
* var addToMap = [polygon, segments]
*/
function lineSegment(geojson) {
if (!geojson) {
throw new Error("geojson is required");
}
var results = [];
flattenEach(geojson, function (feature) {
lineSegmentFeature(feature, results);
});
return featureCollection(results);
}
/**
* Line Segment
*
* @private
* @param {Feature<LineString|Polygon>} geojson Line or polygon feature
* @param {Array} results push to results
* @returns {void}
*/
function lineSegmentFeature(geojson, results) {
var coords = [];
var geometry = geojson.geometry;
if (geometry !== null) {
switch (geometry.type) {
case "Polygon":
coords = getCoords(geometry);
break;
case "LineString":
coords = [getCoords(geometry)];
}
coords.forEach(function (coord) {
var segments = createSegments(coord, geojson.properties);
segments.forEach(function (segment) {
segment.id = results.length;
results.push(segment);
});
});
}
}
/**
* Create Segments from LineString coordinates
*
* @private
* @param {Array<Array<number>>} coords LineString coordinates
* @param {*} properties GeoJSON properties
* @returns {Array<Feature<LineString>>} line segments
*/
function createSegments(coords, properties) {
var segments = [];
coords.reduce(function (previousCoords, currentCoords) {
var segment = lineString([previousCoords, currentCoords], properties);
segment.bbox = bbox(previousCoords, currentCoords);
segments.push(segment);
return currentCoords;
});
return segments;
}
/**
* Create BBox between two coordinates (faster than @turf/bbox)
*
* @private
* @param {Array<number>} coords1 Point coordinate
* @param {Array<number>} coords2 Point coordinate
* @returns {BBox} [west, south, east, north]
*/
function bbox(coords1, coords2) {
var x1 = coords1[0];
var y1 = coords1[1];
var x2 = coords2[0];
var y2 = coords2[1];
var west = x1 < x2 ? x1 : x2;
var south = y1 < y2 ? y1 : y2;
var east = x1 > x2 ? x1 : x2;
var north = y1 > y2 ? y1 : y2;
return [west, south, east, north];
}
export default lineSegment;
+1
View File
@@ -0,0 +1 @@
{"type":"module"}
+17
View File
@@ -0,0 +1,17 @@
import { Feature, FeatureCollection, LineString, MultiLineString, MultiPolygon, Polygon } from "@turf/helpers";
/**
* Creates a {@link FeatureCollection} of 2-vertex {@link LineString} segments from a
* {@link LineString|(Multi)LineString} or {@link Polygon|(Multi)Polygon}.
*
* @name lineSegment
* @param {GeoJSON} geojson GeoJSON Polygon or LineString
* @returns {FeatureCollection<LineString>} 2-vertex line segments
* @example
* var polygon = turf.polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]);
* var segments = turf.lineSegment(polygon);
*
* //addToMap
* var addToMap = [polygon, segments]
*/
declare function lineSegment<G extends LineString | MultiLineString | Polygon | MultiPolygon>(geojson: Feature<G> | FeatureCollection<G> | G): FeatureCollection<LineString>;
export default lineSegment;
+95
View File
@@ -0,0 +1,95 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var helpers_1 = require("@turf/helpers");
var invariant_1 = require("@turf/invariant");
var meta_1 = require("@turf/meta");
/**
* Creates a {@link FeatureCollection} of 2-vertex {@link LineString} segments from a
* {@link LineString|(Multi)LineString} or {@link Polygon|(Multi)Polygon}.
*
* @name lineSegment
* @param {GeoJSON} geojson GeoJSON Polygon or LineString
* @returns {FeatureCollection<LineString>} 2-vertex line segments
* @example
* var polygon = turf.polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]);
* var segments = turf.lineSegment(polygon);
*
* //addToMap
* var addToMap = [polygon, segments]
*/
function lineSegment(geojson) {
if (!geojson) {
throw new Error("geojson is required");
}
var results = [];
meta_1.flattenEach(geojson, function (feature) {
lineSegmentFeature(feature, results);
});
return helpers_1.featureCollection(results);
}
/**
* Line Segment
*
* @private
* @param {Feature<LineString|Polygon>} geojson Line or polygon feature
* @param {Array} results push to results
* @returns {void}
*/
function lineSegmentFeature(geojson, results) {
var coords = [];
var geometry = geojson.geometry;
if (geometry !== null) {
switch (geometry.type) {
case "Polygon":
coords = invariant_1.getCoords(geometry);
break;
case "LineString":
coords = [invariant_1.getCoords(geometry)];
}
coords.forEach(function (coord) {
var segments = createSegments(coord, geojson.properties);
segments.forEach(function (segment) {
segment.id = results.length;
results.push(segment);
});
});
}
}
/**
* Create Segments from LineString coordinates
*
* @private
* @param {Array<Array<number>>} coords LineString coordinates
* @param {*} properties GeoJSON properties
* @returns {Array<Feature<LineString>>} line segments
*/
function createSegments(coords, properties) {
var segments = [];
coords.reduce(function (previousCoords, currentCoords) {
var segment = helpers_1.lineString([previousCoords, currentCoords], properties);
segment.bbox = bbox(previousCoords, currentCoords);
segments.push(segment);
return currentCoords;
});
return segments;
}
/**
* Create BBox between two coordinates (faster than @turf/bbox)
*
* @private
* @param {Array<number>} coords1 Point coordinate
* @param {Array<number>} coords2 Point coordinate
* @returns {BBox} [west, south, east, north]
*/
function bbox(coords1, coords2) {
var x1 = coords1[0];
var y1 = coords1[1];
var x2 = coords2[0];
var y2 = coords2[1];
var west = x1 < x2 ? x1 : x2;
var south = y1 < y2 ? y1 : y2;
var east = x1 > x2 ? x1 : x2;
var north = y1 > y2 ? y1 : y2;
return [west, south, east, north];
}
exports.default = lineSegment;
+64
View File
@@ -0,0 +1,64 @@
{
"name": "@turf/line-segment",
"version": "6.5.0",
"description": "turf line-segment module",
"author": "Turf Authors",
"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",
"line",
"segment"
],
"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"
},
"devDependencies": {
"@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"
},
"gitHead": "5375941072b90d489389db22b43bfe809d5e451e"
}