@turf/concave 7.0.0-alpha.1 → 7.0.0-alpha.111
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -9
- package/dist/cjs/index.cjs +209 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/{js → cjs}/index.d.ts +5 -3
- package/dist/esm/index.d.mts +36 -0
- package/dist/esm/index.mjs +209 -0
- package/dist/esm/index.mjs.map +1 -0
- package/package.json +38 -33
- package/dist/es/index.js +0 -82
- package/dist/es/lib/turf-dissolve.js +0 -70
- package/dist/es/lib/turf-line-dissolve.js +0 -104
- package/dist/es/lib/turf-polygon-dissolve.js +0 -35
- package/dist/es/package.json +0 -1
- package/dist/js/index.js +0 -85
- package/dist/js/lib/turf-dissolve.d.ts +0 -15
- package/dist/js/lib/turf-dissolve.js +0 -73
- package/dist/js/lib/turf-line-dissolve.d.ts +0 -14
- package/dist/js/lib/turf-line-dissolve.js +0 -107
- package/dist/js/lib/turf-polygon-dissolve.d.ts +0 -12
- package/dist/js/lib/turf-polygon-dissolve.js +0 -39
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/concave",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
3
|
+
"version": "7.0.0-alpha.111+08576cb50",
|
|
4
4
|
"description": "turf concave module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"contributors": [
|
|
@@ -33,53 +33,58 @@
|
|
|
33
33
|
"concave",
|
|
34
34
|
"geometry"
|
|
35
35
|
],
|
|
36
|
-
"
|
|
37
|
-
"
|
|
36
|
+
"type": "commonjs",
|
|
37
|
+
"main": "dist/cjs/index.cjs",
|
|
38
|
+
"module": "dist/esm/index.mjs",
|
|
39
|
+
"types": "dist/cjs/index.d.ts",
|
|
38
40
|
"exports": {
|
|
39
41
|
"./package.json": "./package.json",
|
|
40
42
|
".": {
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
"import": {
|
|
44
|
+
"types": "./dist/esm/index.d.mts",
|
|
45
|
+
"default": "./dist/esm/index.mjs"
|
|
46
|
+
},
|
|
47
|
+
"require": {
|
|
48
|
+
"types": "./dist/cjs/index.d.ts",
|
|
49
|
+
"default": "./dist/cjs/index.cjs"
|
|
50
|
+
}
|
|
44
51
|
}
|
|
45
52
|
},
|
|
46
|
-
"types": "dist/js/index.d.ts",
|
|
47
53
|
"sideEffects": false,
|
|
48
54
|
"files": [
|
|
49
55
|
"dist"
|
|
50
56
|
],
|
|
51
57
|
"scripts": {
|
|
52
|
-
"bench": "tsx bench.
|
|
53
|
-
"build": "
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"test": "npm-run-all test:*",
|
|
58
|
-
"test:tape": "tsx test.js"
|
|
58
|
+
"bench": "tsx bench.ts",
|
|
59
|
+
"build": "tsup --config ../../tsup.config.ts",
|
|
60
|
+
"docs": "tsx ../../scripts/generate-readmes.ts",
|
|
61
|
+
"test": "npm-run-all --npm-path npm test:*",
|
|
62
|
+
"test:tape": "tsx test.ts"
|
|
59
63
|
},
|
|
60
64
|
"devDependencies": {
|
|
61
|
-
"@types/
|
|
62
|
-
"@types/
|
|
63
|
-
"@types/topojson-
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
65
|
+
"@types/benchmark": "^2.1.5",
|
|
66
|
+
"@types/tape": "^4.2.32",
|
|
67
|
+
"@types/topojson-client": "3.1.3",
|
|
68
|
+
"@types/topojson-server": "3.0.3",
|
|
69
|
+
"benchmark": "^2.1.4",
|
|
70
|
+
"load-json-file": "^7.0.1",
|
|
71
|
+
"npm-run-all": "^4.1.5",
|
|
72
|
+
"tape": "^5.7.2",
|
|
73
|
+
"tsup": "^8.0.1",
|
|
74
|
+
"tsx": "^4.6.2",
|
|
75
|
+
"typescript": "^5.2.2",
|
|
76
|
+
"write-json-file": "^5.0.0"
|
|
72
77
|
},
|
|
73
78
|
"dependencies": {
|
|
74
|
-
"@turf/clone": "^7.0.0-alpha.
|
|
75
|
-
"@turf/distance": "^7.0.0-alpha.
|
|
76
|
-
"@turf/helpers": "^7.0.0-alpha.
|
|
77
|
-
"@turf/invariant": "^7.0.0-alpha.
|
|
78
|
-
"@turf/meta": "^7.0.0-alpha.
|
|
79
|
-
"@turf/tin": "^7.0.0-alpha.
|
|
79
|
+
"@turf/clone": "^7.0.0-alpha.111+08576cb50",
|
|
80
|
+
"@turf/distance": "^7.0.0-alpha.111+08576cb50",
|
|
81
|
+
"@turf/helpers": "^7.0.0-alpha.111+08576cb50",
|
|
82
|
+
"@turf/invariant": "^7.0.0-alpha.111+08576cb50",
|
|
83
|
+
"@turf/meta": "^7.0.0-alpha.111+08576cb50",
|
|
84
|
+
"@turf/tin": "^7.0.0-alpha.111+08576cb50",
|
|
80
85
|
"topojson-client": "3.x",
|
|
81
86
|
"topojson-server": "3.x",
|
|
82
|
-
"tslib": "^2.
|
|
87
|
+
"tslib": "^2.6.2"
|
|
83
88
|
},
|
|
84
|
-
"gitHead": "
|
|
89
|
+
"gitHead": "08576cb50376e0199aea02dbd887e3af83672246"
|
|
85
90
|
}
|
package/dist/es/index.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import distance from "@turf/distance";
|
|
2
|
-
import { feature, featureCollection } from "@turf/helpers";
|
|
3
|
-
import { featureEach } from "@turf/meta";
|
|
4
|
-
import tin from "@turf/tin";
|
|
5
|
-
import dissolve from "./lib/turf-dissolve.js";
|
|
6
|
-
/**
|
|
7
|
-
* Takes a set of {@link Point|points} and returns a concave hull Polygon or MultiPolygon.
|
|
8
|
-
* Internally, this uses [turf-tin](https://github.com/Turfjs/turf-tin) to generate geometries.
|
|
9
|
-
*
|
|
10
|
-
* @name concave
|
|
11
|
-
* @param {FeatureCollection<Point>} points input points
|
|
12
|
-
* @param {Object} [options={}] Optional parameters
|
|
13
|
-
* @param {number} [options.maxEdge=Infinity] the length (in 'units') of an edge necessary for part of the
|
|
14
|
-
* hull to become concave.
|
|
15
|
-
* @param {string} [options.units='kilometers'] can be degrees, radians, miles, or kilometers
|
|
16
|
-
* @returns {Feature<(Polygon|MultiPolygon)>|null} a concave hull (null value is returned if unable to compute hull)
|
|
17
|
-
* @example
|
|
18
|
-
* var points = turf.featureCollection([
|
|
19
|
-
* turf.point([-63.601226, 44.642643]),
|
|
20
|
-
* turf.point([-63.591442, 44.651436]),
|
|
21
|
-
* turf.point([-63.580799, 44.648749]),
|
|
22
|
-
* turf.point([-63.573589, 44.641788]),
|
|
23
|
-
* turf.point([-63.587665, 44.64533]),
|
|
24
|
-
* turf.point([-63.595218, 44.64765])
|
|
25
|
-
* ]);
|
|
26
|
-
* var options = {units: 'miles', maxEdge: 1};
|
|
27
|
-
*
|
|
28
|
-
* var hull = turf.concave(points, options);
|
|
29
|
-
*
|
|
30
|
-
* //addToMap
|
|
31
|
-
* var addToMap = [points, hull]
|
|
32
|
-
*/
|
|
33
|
-
function concave(points, options = {}) {
|
|
34
|
-
const maxEdge = options.maxEdge || Infinity;
|
|
35
|
-
const cleaned = removeDuplicates(points);
|
|
36
|
-
const tinPolys = tin(cleaned);
|
|
37
|
-
// calculate length of all edges and area of all triangles
|
|
38
|
-
// and remove triangles that fail the max length test
|
|
39
|
-
tinPolys.features = tinPolys.features.filter((triangle) => {
|
|
40
|
-
const pt1 = triangle.geometry.coordinates[0][0];
|
|
41
|
-
const pt2 = triangle.geometry.coordinates[0][1];
|
|
42
|
-
const pt3 = triangle.geometry.coordinates[0][2];
|
|
43
|
-
const dist1 = distance(pt1, pt2, options);
|
|
44
|
-
const dist2 = distance(pt2, pt3, options);
|
|
45
|
-
const dist3 = distance(pt1, pt3, options);
|
|
46
|
-
return dist1 <= maxEdge && dist2 <= maxEdge && dist3 <= maxEdge;
|
|
47
|
-
});
|
|
48
|
-
if (tinPolys.features.length < 1) {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
// merge the adjacent triangles
|
|
52
|
-
const dissolved = dissolve(tinPolys);
|
|
53
|
-
// geojson-dissolve always returns a MultiPolygon
|
|
54
|
-
if (dissolved.coordinates.length === 1) {
|
|
55
|
-
dissolved.coordinates = dissolved.coordinates[0];
|
|
56
|
-
dissolved.type = "Polygon";
|
|
57
|
-
}
|
|
58
|
-
return feature(dissolved);
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Removes duplicated points in a collection returning a new collection
|
|
62
|
-
*
|
|
63
|
-
* @private
|
|
64
|
-
* @param {FeatureCollection<Point>} points to be cleaned
|
|
65
|
-
* @returns {FeatureCollection<Point>} cleaned set of points
|
|
66
|
-
*/
|
|
67
|
-
function removeDuplicates(points) {
|
|
68
|
-
const cleaned = [];
|
|
69
|
-
const existing = {};
|
|
70
|
-
featureEach(points, (pt) => {
|
|
71
|
-
if (!pt.geometry) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
const key = pt.geometry.coordinates.join("-");
|
|
75
|
-
if (!Object.prototype.hasOwnProperty.call(existing, key)) {
|
|
76
|
-
cleaned.push(pt);
|
|
77
|
-
existing[key] = true;
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
return featureCollection(cleaned);
|
|
81
|
-
}
|
|
82
|
-
export default concave;
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import clone from "@turf/clone";
|
|
2
|
-
import { isObject } from "@turf/helpers";
|
|
3
|
-
import { getType } from "@turf/invariant";
|
|
4
|
-
import { flattenEach } from "@turf/meta";
|
|
5
|
-
import lineDissolve from "./turf-line-dissolve.js";
|
|
6
|
-
import polygonDissolve from "./turf-polygon-dissolve.js";
|
|
7
|
-
/**
|
|
8
|
-
* Transform function: attempts to dissolve geojson objects where possible
|
|
9
|
-
* [GeoJSON] -> GeoJSON geometry
|
|
10
|
-
*
|
|
11
|
-
* @private
|
|
12
|
-
* @param {FeatureCollection<LineString|MultiLineString|Polygon|MultiPolygon>} geojson Features to dissolved
|
|
13
|
-
* @param {Object} [options={}] Optional parameters
|
|
14
|
-
* @param {boolean} [options.mutate=false] Prevent input mutation
|
|
15
|
-
* @returns {Feature<MultiLineString|MultiPolygon>} Dissolved Features
|
|
16
|
-
*/
|
|
17
|
-
function dissolve(geojson, options = {}) {
|
|
18
|
-
// Optional parameters
|
|
19
|
-
options = options || {};
|
|
20
|
-
if (!isObject(options)) {
|
|
21
|
-
throw new Error("options is invalid");
|
|
22
|
-
}
|
|
23
|
-
const mutate = options.mutate;
|
|
24
|
-
// Validation
|
|
25
|
-
if (getType(geojson) !== "FeatureCollection") {
|
|
26
|
-
throw new Error("geojson must be a FeatureCollection");
|
|
27
|
-
}
|
|
28
|
-
if (!geojson.features.length) {
|
|
29
|
-
throw new Error("geojson is empty");
|
|
30
|
-
}
|
|
31
|
-
// Clone geojson to avoid side effects
|
|
32
|
-
// Topojson modifies in place, so we need to deep clone first
|
|
33
|
-
if (mutate === false || mutate === undefined) {
|
|
34
|
-
geojson = clone(geojson);
|
|
35
|
-
}
|
|
36
|
-
// Assert homogenity
|
|
37
|
-
const type = getHomogenousType(geojson);
|
|
38
|
-
if (!type) {
|
|
39
|
-
throw new Error("geojson must be homogenous");
|
|
40
|
-
}
|
|
41
|
-
// Data => Typescript hack
|
|
42
|
-
const data = geojson;
|
|
43
|
-
switch (type) {
|
|
44
|
-
case "LineString":
|
|
45
|
-
return lineDissolve(data, options);
|
|
46
|
-
case "Polygon":
|
|
47
|
-
return polygonDissolve(data, options);
|
|
48
|
-
default:
|
|
49
|
-
throw new Error(type + " is not supported");
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Checks if GeoJSON is Homogenous
|
|
54
|
-
*
|
|
55
|
-
* @private
|
|
56
|
-
* @param {GeoJSON} geojson GeoJSON
|
|
57
|
-
* @returns {string|null} Homogenous type or null if multiple types
|
|
58
|
-
*/
|
|
59
|
-
function getHomogenousType(geojson) {
|
|
60
|
-
const types = {};
|
|
61
|
-
flattenEach(geojson, (feature) => {
|
|
62
|
-
types[feature.geometry.type] = true;
|
|
63
|
-
});
|
|
64
|
-
const keys = Object.keys(types);
|
|
65
|
-
if (keys.length === 1) {
|
|
66
|
-
return keys[0];
|
|
67
|
-
}
|
|
68
|
-
return null;
|
|
69
|
-
}
|
|
70
|
-
export default dissolve;
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import clone from "@turf/clone";
|
|
2
|
-
import { isObject, lineString, multiLineString } from "@turf/helpers";
|
|
3
|
-
import { getType } from "@turf/invariant";
|
|
4
|
-
import { lineReduce } from "@turf/meta";
|
|
5
|
-
/**
|
|
6
|
-
* Merges all connected (non-forking, non-junctioning) line strings into single lineStrings.
|
|
7
|
-
* [LineString] -> LineString|MultiLineString
|
|
8
|
-
*
|
|
9
|
-
* @param {FeatureCollection<LineString|MultiLineString>} geojson Lines to dissolve
|
|
10
|
-
* @param {Object} [options={}] Optional parameters
|
|
11
|
-
* @param {boolean} [options.mutate=false] Prevent input mutation
|
|
12
|
-
* @returns {Feature<LineString|MultiLineString>} Dissolved lines
|
|
13
|
-
*/
|
|
14
|
-
function lineDissolve(geojson, options = {}) {
|
|
15
|
-
// Optional parameters
|
|
16
|
-
options = options || {};
|
|
17
|
-
if (!isObject(options)) {
|
|
18
|
-
throw new Error("options is invalid");
|
|
19
|
-
}
|
|
20
|
-
const mutate = options.mutate;
|
|
21
|
-
// Validation
|
|
22
|
-
if (getType(geojson) !== "FeatureCollection") {
|
|
23
|
-
throw new Error("geojson must be a FeatureCollection");
|
|
24
|
-
}
|
|
25
|
-
if (!geojson.features.length) {
|
|
26
|
-
throw new Error("geojson is empty");
|
|
27
|
-
}
|
|
28
|
-
// Clone geojson to avoid side effects
|
|
29
|
-
if (mutate === false || mutate === undefined) {
|
|
30
|
-
geojson = clone(geojson);
|
|
31
|
-
}
|
|
32
|
-
const result = [];
|
|
33
|
-
const lastLine = lineReduce(geojson, (previousLine, currentLine) => {
|
|
34
|
-
// Attempt to merge this LineString with the other LineStrings, updating
|
|
35
|
-
// the reference as it is merged with others and grows.
|
|
36
|
-
const merged = mergeLineStrings(previousLine, currentLine);
|
|
37
|
-
// Accumulate the merged LineString
|
|
38
|
-
if (merged) {
|
|
39
|
-
return merged;
|
|
40
|
-
// Put the unmerged LineString back into the list
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
result.push(previousLine);
|
|
44
|
-
return currentLine;
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
// Append the last line
|
|
48
|
-
if (lastLine) {
|
|
49
|
-
result.push(lastLine);
|
|
50
|
-
}
|
|
51
|
-
// Return null if no lines were dissolved
|
|
52
|
-
if (!result.length) {
|
|
53
|
-
return null;
|
|
54
|
-
// Return LineString if only 1 line was dissolved
|
|
55
|
-
}
|
|
56
|
-
else if (result.length === 1) {
|
|
57
|
-
return result[0];
|
|
58
|
-
// Return MultiLineString if multiple lines were dissolved with gaps
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
return multiLineString(result.map((line) => {
|
|
62
|
-
return line.coordinates;
|
|
63
|
-
}));
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
// [Number, Number] -> String
|
|
67
|
-
function coordId(coord) {
|
|
68
|
-
return coord[0].toString() + "," + coord[1].toString();
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* LineString, LineString -> LineString
|
|
72
|
-
*
|
|
73
|
-
* @private
|
|
74
|
-
* @param {Feature<LineString>} a line1
|
|
75
|
-
* @param {Feature<LineString>} b line2
|
|
76
|
-
* @returns {Feature<LineString>|null} Merged LineString
|
|
77
|
-
*/
|
|
78
|
-
function mergeLineStrings(a, b) {
|
|
79
|
-
const coords1 = a.geometry.coordinates;
|
|
80
|
-
const coords2 = b.geometry.coordinates;
|
|
81
|
-
const s1 = coordId(coords1[0]);
|
|
82
|
-
const e1 = coordId(coords1[coords1.length - 1]);
|
|
83
|
-
const s2 = coordId(coords2[0]);
|
|
84
|
-
const e2 = coordId(coords2[coords2.length - 1]);
|
|
85
|
-
// TODO: handle case where more than one of these is true!
|
|
86
|
-
let coords;
|
|
87
|
-
if (s1 === e2) {
|
|
88
|
-
coords = coords2.concat(coords1.slice(1));
|
|
89
|
-
}
|
|
90
|
-
else if (s2 === e1) {
|
|
91
|
-
coords = coords1.concat(coords2.slice(1));
|
|
92
|
-
}
|
|
93
|
-
else if (s1 === s2) {
|
|
94
|
-
coords = coords1.slice(1).reverse().concat(coords2);
|
|
95
|
-
}
|
|
96
|
-
else if (e1 === e2) {
|
|
97
|
-
coords = coords1.concat(coords2.reverse().slice(1));
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
return lineString(coords);
|
|
103
|
-
}
|
|
104
|
-
export default lineDissolve;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import clone from "@turf/clone";
|
|
2
|
-
import { geometryCollection } from "@turf/helpers";
|
|
3
|
-
import { getType } from "@turf/invariant";
|
|
4
|
-
import { flattenEach } from "@turf/meta";
|
|
5
|
-
import { merge } from "topojson-client";
|
|
6
|
-
import { topology } from "topojson-server";
|
|
7
|
-
/**
|
|
8
|
-
* Dissolves all overlapping (Multi)Polygon
|
|
9
|
-
*
|
|
10
|
-
* @param {FeatureCollection<Polygon|MultiPolygon>} geojson Polygons to dissolve
|
|
11
|
-
* @param {Object} [options={}] Optional parameters
|
|
12
|
-
* @param {boolean} [options.mutate=false] Prevent input mutation
|
|
13
|
-
* @returns {Feature<Polygon|MultiPolygon>} Dissolved Polygons
|
|
14
|
-
*/
|
|
15
|
-
export default function polygonDissolve(geojson, options = {}) {
|
|
16
|
-
// Validation
|
|
17
|
-
if (getType(geojson) !== "FeatureCollection") {
|
|
18
|
-
throw new Error("geojson must be a FeatureCollection");
|
|
19
|
-
}
|
|
20
|
-
if (!geojson.features.length) {
|
|
21
|
-
throw new Error("geojson is empty");
|
|
22
|
-
}
|
|
23
|
-
// Clone geojson to avoid side effects
|
|
24
|
-
// Topojson modifies in place, so we need to deep clone first
|
|
25
|
-
if (options.mutate === false || options.mutate === undefined) {
|
|
26
|
-
geojson = clone(geojson);
|
|
27
|
-
}
|
|
28
|
-
const geoms = [];
|
|
29
|
-
flattenEach(geojson, (feature) => {
|
|
30
|
-
geoms.push(feature.geometry);
|
|
31
|
-
});
|
|
32
|
-
const topo = topology({ geoms: geometryCollection(geoms).geometry });
|
|
33
|
-
const merged = merge(topo, topo.objects.geoms.geometries);
|
|
34
|
-
return merged;
|
|
35
|
-
}
|
package/dist/es/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module"}
|
package/dist/js/index.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const distance_1 = tslib_1.__importDefault(require("@turf/distance"));
|
|
5
|
-
const helpers_1 = require("@turf/helpers");
|
|
6
|
-
const meta_1 = require("@turf/meta");
|
|
7
|
-
const tin_1 = tslib_1.__importDefault(require("@turf/tin"));
|
|
8
|
-
const turf_dissolve_1 = tslib_1.__importDefault(require("./lib/turf-dissolve"));
|
|
9
|
-
/**
|
|
10
|
-
* Takes a set of {@link Point|points} and returns a concave hull Polygon or MultiPolygon.
|
|
11
|
-
* Internally, this uses [turf-tin](https://github.com/Turfjs/turf-tin) to generate geometries.
|
|
12
|
-
*
|
|
13
|
-
* @name concave
|
|
14
|
-
* @param {FeatureCollection<Point>} points input points
|
|
15
|
-
* @param {Object} [options={}] Optional parameters
|
|
16
|
-
* @param {number} [options.maxEdge=Infinity] the length (in 'units') of an edge necessary for part of the
|
|
17
|
-
* hull to become concave.
|
|
18
|
-
* @param {string} [options.units='kilometers'] can be degrees, radians, miles, or kilometers
|
|
19
|
-
* @returns {Feature<(Polygon|MultiPolygon)>|null} a concave hull (null value is returned if unable to compute hull)
|
|
20
|
-
* @example
|
|
21
|
-
* var points = turf.featureCollection([
|
|
22
|
-
* turf.point([-63.601226, 44.642643]),
|
|
23
|
-
* turf.point([-63.591442, 44.651436]),
|
|
24
|
-
* turf.point([-63.580799, 44.648749]),
|
|
25
|
-
* turf.point([-63.573589, 44.641788]),
|
|
26
|
-
* turf.point([-63.587665, 44.64533]),
|
|
27
|
-
* turf.point([-63.595218, 44.64765])
|
|
28
|
-
* ]);
|
|
29
|
-
* var options = {units: 'miles', maxEdge: 1};
|
|
30
|
-
*
|
|
31
|
-
* var hull = turf.concave(points, options);
|
|
32
|
-
*
|
|
33
|
-
* //addToMap
|
|
34
|
-
* var addToMap = [points, hull]
|
|
35
|
-
*/
|
|
36
|
-
function concave(points, options = {}) {
|
|
37
|
-
const maxEdge = options.maxEdge || Infinity;
|
|
38
|
-
const cleaned = removeDuplicates(points);
|
|
39
|
-
const tinPolys = tin_1.default(cleaned);
|
|
40
|
-
// calculate length of all edges and area of all triangles
|
|
41
|
-
// and remove triangles that fail the max length test
|
|
42
|
-
tinPolys.features = tinPolys.features.filter((triangle) => {
|
|
43
|
-
const pt1 = triangle.geometry.coordinates[0][0];
|
|
44
|
-
const pt2 = triangle.geometry.coordinates[0][1];
|
|
45
|
-
const pt3 = triangle.geometry.coordinates[0][2];
|
|
46
|
-
const dist1 = distance_1.default(pt1, pt2, options);
|
|
47
|
-
const dist2 = distance_1.default(pt2, pt3, options);
|
|
48
|
-
const dist3 = distance_1.default(pt1, pt3, options);
|
|
49
|
-
return dist1 <= maxEdge && dist2 <= maxEdge && dist3 <= maxEdge;
|
|
50
|
-
});
|
|
51
|
-
if (tinPolys.features.length < 1) {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
// merge the adjacent triangles
|
|
55
|
-
const dissolved = turf_dissolve_1.default(tinPolys);
|
|
56
|
-
// geojson-dissolve always returns a MultiPolygon
|
|
57
|
-
if (dissolved.coordinates.length === 1) {
|
|
58
|
-
dissolved.coordinates = dissolved.coordinates[0];
|
|
59
|
-
dissolved.type = "Polygon";
|
|
60
|
-
}
|
|
61
|
-
return helpers_1.feature(dissolved);
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Removes duplicated points in a collection returning a new collection
|
|
65
|
-
*
|
|
66
|
-
* @private
|
|
67
|
-
* @param {FeatureCollection<Point>} points to be cleaned
|
|
68
|
-
* @returns {FeatureCollection<Point>} cleaned set of points
|
|
69
|
-
*/
|
|
70
|
-
function removeDuplicates(points) {
|
|
71
|
-
const cleaned = [];
|
|
72
|
-
const existing = {};
|
|
73
|
-
meta_1.featureEach(points, (pt) => {
|
|
74
|
-
if (!pt.geometry) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
const key = pt.geometry.coordinates.join("-");
|
|
78
|
-
if (!Object.prototype.hasOwnProperty.call(existing, key)) {
|
|
79
|
-
cleaned.push(pt);
|
|
80
|
-
existing[key] = true;
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
return helpers_1.featureCollection(cleaned);
|
|
84
|
-
}
|
|
85
|
-
exports.default = concave;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Feature, FeatureCollection, LineString, MultiLineString, MultiPolygon, Polygon } from "geojson";
|
|
2
|
-
/**
|
|
3
|
-
* Transform function: attempts to dissolve geojson objects where possible
|
|
4
|
-
* [GeoJSON] -> GeoJSON geometry
|
|
5
|
-
*
|
|
6
|
-
* @private
|
|
7
|
-
* @param {FeatureCollection<LineString|MultiLineString|Polygon|MultiPolygon>} geojson Features to dissolved
|
|
8
|
-
* @param {Object} [options={}] Optional parameters
|
|
9
|
-
* @param {boolean} [options.mutate=false] Prevent input mutation
|
|
10
|
-
* @returns {Feature<MultiLineString|MultiPolygon>} Dissolved Features
|
|
11
|
-
*/
|
|
12
|
-
declare function dissolve(geojson: FeatureCollection<LineString | MultiLineString | Polygon | MultiPolygon>, options?: {
|
|
13
|
-
mutate?: boolean;
|
|
14
|
-
}): Feature<LineString | MultiLineString | Polygon | MultiPolygon> | null;
|
|
15
|
-
export default dissolve;
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const clone_1 = tslib_1.__importDefault(require("@turf/clone"));
|
|
5
|
-
const helpers_1 = require("@turf/helpers");
|
|
6
|
-
const invariant_1 = require("@turf/invariant");
|
|
7
|
-
const meta_1 = require("@turf/meta");
|
|
8
|
-
const turf_line_dissolve_1 = tslib_1.__importDefault(require("./turf-line-dissolve"));
|
|
9
|
-
const turf_polygon_dissolve_1 = tslib_1.__importDefault(require("./turf-polygon-dissolve"));
|
|
10
|
-
/**
|
|
11
|
-
* Transform function: attempts to dissolve geojson objects where possible
|
|
12
|
-
* [GeoJSON] -> GeoJSON geometry
|
|
13
|
-
*
|
|
14
|
-
* @private
|
|
15
|
-
* @param {FeatureCollection<LineString|MultiLineString|Polygon|MultiPolygon>} geojson Features to dissolved
|
|
16
|
-
* @param {Object} [options={}] Optional parameters
|
|
17
|
-
* @param {boolean} [options.mutate=false] Prevent input mutation
|
|
18
|
-
* @returns {Feature<MultiLineString|MultiPolygon>} Dissolved Features
|
|
19
|
-
*/
|
|
20
|
-
function dissolve(geojson, options = {}) {
|
|
21
|
-
// Optional parameters
|
|
22
|
-
options = options || {};
|
|
23
|
-
if (!helpers_1.isObject(options)) {
|
|
24
|
-
throw new Error("options is invalid");
|
|
25
|
-
}
|
|
26
|
-
const mutate = options.mutate;
|
|
27
|
-
// Validation
|
|
28
|
-
if (invariant_1.getType(geojson) !== "FeatureCollection") {
|
|
29
|
-
throw new Error("geojson must be a FeatureCollection");
|
|
30
|
-
}
|
|
31
|
-
if (!geojson.features.length) {
|
|
32
|
-
throw new Error("geojson is empty");
|
|
33
|
-
}
|
|
34
|
-
// Clone geojson to avoid side effects
|
|
35
|
-
// Topojson modifies in place, so we need to deep clone first
|
|
36
|
-
if (mutate === false || mutate === undefined) {
|
|
37
|
-
geojson = clone_1.default(geojson);
|
|
38
|
-
}
|
|
39
|
-
// Assert homogenity
|
|
40
|
-
const type = getHomogenousType(geojson);
|
|
41
|
-
if (!type) {
|
|
42
|
-
throw new Error("geojson must be homogenous");
|
|
43
|
-
}
|
|
44
|
-
// Data => Typescript hack
|
|
45
|
-
const data = geojson;
|
|
46
|
-
switch (type) {
|
|
47
|
-
case "LineString":
|
|
48
|
-
return turf_line_dissolve_1.default(data, options);
|
|
49
|
-
case "Polygon":
|
|
50
|
-
return turf_polygon_dissolve_1.default(data, options);
|
|
51
|
-
default:
|
|
52
|
-
throw new Error(type + " is not supported");
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Checks if GeoJSON is Homogenous
|
|
57
|
-
*
|
|
58
|
-
* @private
|
|
59
|
-
* @param {GeoJSON} geojson GeoJSON
|
|
60
|
-
* @returns {string|null} Homogenous type or null if multiple types
|
|
61
|
-
*/
|
|
62
|
-
function getHomogenousType(geojson) {
|
|
63
|
-
const types = {};
|
|
64
|
-
meta_1.flattenEach(geojson, (feature) => {
|
|
65
|
-
types[feature.geometry.type] = true;
|
|
66
|
-
});
|
|
67
|
-
const keys = Object.keys(types);
|
|
68
|
-
if (keys.length === 1) {
|
|
69
|
-
return keys[0];
|
|
70
|
-
}
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
exports.default = dissolve;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Feature, FeatureCollection, LineString, MultiLineString } from "geojson";
|
|
2
|
-
/**
|
|
3
|
-
* Merges all connected (non-forking, non-junctioning) line strings into single lineStrings.
|
|
4
|
-
* [LineString] -> LineString|MultiLineString
|
|
5
|
-
*
|
|
6
|
-
* @param {FeatureCollection<LineString|MultiLineString>} geojson Lines to dissolve
|
|
7
|
-
* @param {Object} [options={}] Optional parameters
|
|
8
|
-
* @param {boolean} [options.mutate=false] Prevent input mutation
|
|
9
|
-
* @returns {Feature<LineString|MultiLineString>} Dissolved lines
|
|
10
|
-
*/
|
|
11
|
-
declare function lineDissolve(geojson: FeatureCollection<LineString | MultiLineString>, options?: {
|
|
12
|
-
mutate?: boolean;
|
|
13
|
-
}): Feature<LineString | MultiLineString> | null;
|
|
14
|
-
export default lineDissolve;
|