@turf/concave 7.0.0-alpha.0 → 7.0.0-alpha.110
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 -32
- 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
|
@@ -1,107 +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
|
-
/**
|
|
9
|
-
* Merges all connected (non-forking, non-junctioning) line strings into single lineStrings.
|
|
10
|
-
* [LineString] -> LineString|MultiLineString
|
|
11
|
-
*
|
|
12
|
-
* @param {FeatureCollection<LineString|MultiLineString>} geojson Lines to dissolve
|
|
13
|
-
* @param {Object} [options={}] Optional parameters
|
|
14
|
-
* @param {boolean} [options.mutate=false] Prevent input mutation
|
|
15
|
-
* @returns {Feature<LineString|MultiLineString>} Dissolved lines
|
|
16
|
-
*/
|
|
17
|
-
function lineDissolve(geojson, options = {}) {
|
|
18
|
-
// Optional parameters
|
|
19
|
-
options = options || {};
|
|
20
|
-
if (!helpers_1.isObject(options)) {
|
|
21
|
-
throw new Error("options is invalid");
|
|
22
|
-
}
|
|
23
|
-
const mutate = options.mutate;
|
|
24
|
-
// Validation
|
|
25
|
-
if (invariant_1.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
|
-
if (mutate === false || mutate === undefined) {
|
|
33
|
-
geojson = clone_1.default(geojson);
|
|
34
|
-
}
|
|
35
|
-
const result = [];
|
|
36
|
-
const lastLine = meta_1.lineReduce(geojson, (previousLine, currentLine) => {
|
|
37
|
-
// Attempt to merge this LineString with the other LineStrings, updating
|
|
38
|
-
// the reference as it is merged with others and grows.
|
|
39
|
-
const merged = mergeLineStrings(previousLine, currentLine);
|
|
40
|
-
// Accumulate the merged LineString
|
|
41
|
-
if (merged) {
|
|
42
|
-
return merged;
|
|
43
|
-
// Put the unmerged LineString back into the list
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
result.push(previousLine);
|
|
47
|
-
return currentLine;
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
// Append the last line
|
|
51
|
-
if (lastLine) {
|
|
52
|
-
result.push(lastLine);
|
|
53
|
-
}
|
|
54
|
-
// Return null if no lines were dissolved
|
|
55
|
-
if (!result.length) {
|
|
56
|
-
return null;
|
|
57
|
-
// Return LineString if only 1 line was dissolved
|
|
58
|
-
}
|
|
59
|
-
else if (result.length === 1) {
|
|
60
|
-
return result[0];
|
|
61
|
-
// Return MultiLineString if multiple lines were dissolved with gaps
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
return helpers_1.multiLineString(result.map((line) => {
|
|
65
|
-
return line.coordinates;
|
|
66
|
-
}));
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
// [Number, Number] -> String
|
|
70
|
-
function coordId(coord) {
|
|
71
|
-
return coord[0].toString() + "," + coord[1].toString();
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* LineString, LineString -> LineString
|
|
75
|
-
*
|
|
76
|
-
* @private
|
|
77
|
-
* @param {Feature<LineString>} a line1
|
|
78
|
-
* @param {Feature<LineString>} b line2
|
|
79
|
-
* @returns {Feature<LineString>|null} Merged LineString
|
|
80
|
-
*/
|
|
81
|
-
function mergeLineStrings(a, b) {
|
|
82
|
-
const coords1 = a.geometry.coordinates;
|
|
83
|
-
const coords2 = b.geometry.coordinates;
|
|
84
|
-
const s1 = coordId(coords1[0]);
|
|
85
|
-
const e1 = coordId(coords1[coords1.length - 1]);
|
|
86
|
-
const s2 = coordId(coords2[0]);
|
|
87
|
-
const e2 = coordId(coords2[coords2.length - 1]);
|
|
88
|
-
// TODO: handle case where more than one of these is true!
|
|
89
|
-
let coords;
|
|
90
|
-
if (s1 === e2) {
|
|
91
|
-
coords = coords2.concat(coords1.slice(1));
|
|
92
|
-
}
|
|
93
|
-
else if (s2 === e1) {
|
|
94
|
-
coords = coords1.concat(coords2.slice(1));
|
|
95
|
-
}
|
|
96
|
-
else if (s1 === s2) {
|
|
97
|
-
coords = coords1.slice(1).reverse().concat(coords2);
|
|
98
|
-
}
|
|
99
|
-
else if (e1 === e2) {
|
|
100
|
-
coords = coords1.concat(coords2.reverse().slice(1));
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
return null;
|
|
104
|
-
}
|
|
105
|
-
return helpers_1.lineString(coords);
|
|
106
|
-
}
|
|
107
|
-
exports.default = lineDissolve;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Feature, FeatureCollection, MultiPolygon, Polygon } from "geojson";
|
|
2
|
-
/**
|
|
3
|
-
* Dissolves all overlapping (Multi)Polygon
|
|
4
|
-
*
|
|
5
|
-
* @param {FeatureCollection<Polygon|MultiPolygon>} geojson Polygons to dissolve
|
|
6
|
-
* @param {Object} [options={}] Optional parameters
|
|
7
|
-
* @param {boolean} [options.mutate=false] Prevent input mutation
|
|
8
|
-
* @returns {Feature<Polygon|MultiPolygon>} Dissolved Polygons
|
|
9
|
-
*/
|
|
10
|
-
export default function polygonDissolve(geojson: FeatureCollection<Polygon | MultiPolygon>, options?: {
|
|
11
|
-
mutate?: boolean;
|
|
12
|
-
}): Feature<Polygon | MultiPolygon> | null;
|
|
@@ -1,39 +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 topojson_client_1 = require("topojson-client");
|
|
9
|
-
const topojson_server_1 = require("topojson-server");
|
|
10
|
-
/**
|
|
11
|
-
* Dissolves all overlapping (Multi)Polygon
|
|
12
|
-
*
|
|
13
|
-
* @param {FeatureCollection<Polygon|MultiPolygon>} geojson Polygons to dissolve
|
|
14
|
-
* @param {Object} [options={}] Optional parameters
|
|
15
|
-
* @param {boolean} [options.mutate=false] Prevent input mutation
|
|
16
|
-
* @returns {Feature<Polygon|MultiPolygon>} Dissolved Polygons
|
|
17
|
-
*/
|
|
18
|
-
function polygonDissolve(geojson, options = {}) {
|
|
19
|
-
// Validation
|
|
20
|
-
if (invariant_1.getType(geojson) !== "FeatureCollection") {
|
|
21
|
-
throw new Error("geojson must be a FeatureCollection");
|
|
22
|
-
}
|
|
23
|
-
if (!geojson.features.length) {
|
|
24
|
-
throw new Error("geojson is empty");
|
|
25
|
-
}
|
|
26
|
-
// Clone geojson to avoid side effects
|
|
27
|
-
// Topojson modifies in place, so we need to deep clone first
|
|
28
|
-
if (options.mutate === false || options.mutate === undefined) {
|
|
29
|
-
geojson = clone_1.default(geojson);
|
|
30
|
-
}
|
|
31
|
-
const geoms = [];
|
|
32
|
-
meta_1.flattenEach(geojson, (feature) => {
|
|
33
|
-
geoms.push(feature.geometry);
|
|
34
|
-
});
|
|
35
|
-
const topo = topojson_server_1.topology({ geoms: helpers_1.geometryCollection(geoms).geometry });
|
|
36
|
-
const merged = topojson_client_1.merge(topo, topo.objects.geoms.geometries);
|
|
37
|
-
return merged;
|
|
38
|
-
}
|
|
39
|
-
exports.default = polygonDissolve;
|