@turf/dissolve 7.0.0-alpha.2 → 7.0.0

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 CHANGED
@@ -43,26 +43,21 @@ Returns **[FeatureCollection][3]<[Polygon][4]>** a FeatureCollection containing
43
43
 
44
44
  [6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
45
45
 
46
- <!-- This file is automatically generated. Please don't edit it directly:
47
- if you find an error, edit the source file (likely index.js), and re-run
48
- ./scripts/generate-readmes in the turf project. -->
46
+ <!-- This file is automatically generated. Please don't edit it directly. If you find an error, edit the source file of the module in question (likely index.js or index.ts), and re-run "yarn docs" from the root of the turf project. -->
49
47
 
50
48
  ---
51
49
 
52
- This module is part of the [Turfjs project](http://turfjs.org/), an open source
53
- module collection dedicated to geographic algorithms. It is maintained in the
54
- [Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
55
- PRs and issues.
50
+ This module is part of the [Turfjs project](https://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.
56
51
 
57
52
  ### Installation
58
53
 
59
- Install this module individually:
54
+ Install this single module individually:
60
55
 
61
56
  ```sh
62
57
  $ npm install @turf/dissolve
63
58
  ```
64
59
 
65
- Or install the Turf module that includes it as a function:
60
+ Or install the all-encompassing @turf/turf module that includes all modules as functions:
66
61
 
67
62
  ```sh
68
63
  $ npm install @turf/turf
@@ -0,0 +1,67 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // index.ts
5
+ var _helpers = require('@turf/helpers');
6
+ var _invariant = require('@turf/invariant');
7
+ var _meta = require('@turf/meta');
8
+ var _flatten = require('@turf/flatten');
9
+ var _polygonclipping = require('polygon-clipping'); var _polygonclipping2 = _interopRequireDefault(_polygonclipping);
10
+ function dissolve(fc, options = {}) {
11
+ options = options || {};
12
+ if (!_helpers.isObject.call(void 0, options))
13
+ throw new Error("options is invalid");
14
+ const { propertyName } = options;
15
+ _invariant.collectionOf.call(void 0, fc, "Polygon", "dissolve");
16
+ const outFeatures = [];
17
+ if (!propertyName) {
18
+ return _flatten.flatten.call(void 0,
19
+ _helpers.multiPolygon.call(void 0,
20
+ _polygonclipping2.default.union.apply(
21
+ null,
22
+ // List of polygons expressed as Position[][][] a.k.a. Geom[]
23
+ fc.features.map(function(f) {
24
+ return f.geometry.coordinates;
25
+ })
26
+ )
27
+ )
28
+ );
29
+ } else {
30
+ const uniquePropertyVals = {};
31
+ _meta.featureEach.call(void 0, fc, function(feature) {
32
+ if (feature.properties) {
33
+ if (!Object.prototype.hasOwnProperty.call(
34
+ uniquePropertyVals,
35
+ feature.properties[propertyName]
36
+ )) {
37
+ uniquePropertyVals[feature.properties[propertyName]] = [];
38
+ }
39
+ uniquePropertyVals[feature.properties[propertyName]].push(feature);
40
+ }
41
+ });
42
+ const vals = Object.keys(uniquePropertyVals);
43
+ for (let i = 0; i < vals.length; i++) {
44
+ const mp = _helpers.multiPolygon.call(void 0,
45
+ _polygonclipping2.default.union.apply(
46
+ null,
47
+ // List of polygons expressed as Position[][][] a.k.a. Geom[]
48
+ uniquePropertyVals[vals[i]].map(function(f) {
49
+ return f.geometry.coordinates;
50
+ })
51
+ )
52
+ );
53
+ if (mp && mp.properties) {
54
+ mp.properties[propertyName] = vals[i];
55
+ outFeatures.push(mp);
56
+ }
57
+ }
58
+ }
59
+ return _flatten.flatten.call(void 0, _helpers.featureCollection.call(void 0, outFeatures));
60
+ }
61
+ __name(dissolve, "dissolve");
62
+ var turf_dissolve_default = dissolve;
63
+
64
+
65
+
66
+ exports.default = turf_dissolve_default; exports.dissolve = dissolve;
67
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../index.ts"],"names":[],"mappings":";;;;AACA,SAAS,mBAAmB,UAAU,oBAAoB;AAC1D,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB;AAC5B,SAAS,eAAe;AACxB,OAAO,qBAA+B;AAuBtC,SAAS,SACP,IACA,UAEI,CAAC,GACuB;AAE5B,YAAU,WAAW,CAAC;AACtB,MAAI,CAAC,SAAS,OAAO;AAAG,UAAM,IAAI,MAAM,oBAAoB;AAC5D,QAAM,EAAE,aAAa,IAAI;AAGzB,eAAa,IAAI,WAAW,UAAU;AAGtC,QAAM,cAAc,CAAC;AACrB,MAAI,CAAC,cAAc;AACjB,WAAO;AAAA,MACL;AAAA,QACE,gBAAgB,MAAM;AAAA,UACpB;AAAA;AAAA,UAEA,GAAG,SAAS,IAAI,SAAU,GAAG;AAC3B,mBAAO,EAAE,SAAS;AAAA,UACpB,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,EACF,OAAO;AAEL,UAAM,qBAAmD,CAAC;AAC1D,gBAAY,IAAI,SAAU,SAAS;AACjC,UAAI,QAAQ,YAAY;AACtB,YACE,CAAC,OAAO,UAAU,eAAe;AAAA,UAC/B;AAAA,UACA,QAAQ,WAAW,YAAY;AAAA,QACjC,GACA;AACA,6BAAmB,QAAQ,WAAW,YAAY,CAAC,IACjD,CAAC;AAAA,QACL;AACA,2BAAmB,QAAQ,WAAW,YAAY,CAAC,EAAE,KAAK,OAAO;AAAA,MACnE;AAAA,IACF,CAAC;AACD,UAAM,OAAO,OAAO,KAAK,kBAAkB;AAG3C,aAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,YAAM,KAAK;AAAA,QACT,gBAAgB,MAAM;AAAA,UACpB;AAAA;AAAA,UAEC,mBAAmB,KAAK,CAAC,CAAC,EAAyB,IAAI,SAAU,GAAG;AACnE,mBAAO,EAAE,SAAS;AAAA,UACpB,CAAC;AAAA,QACH;AAAA,MACF;AACA,UAAI,MAAM,GAAG,YAAY;AACvB,WAAG,WAAW,YAAY,IAAI,KAAK,CAAC;AACpC,oBAAY,KAAK,EAAE;AAAA,MACrB;AAAA,IACF;AAAA,EACF;AAEA,SAAO,QAAQ,kBAAkB,WAAW,CAAC;AAC/C;AAlES;AAqET,IAAO,wBAAQ","sourcesContent":["import { Feature, FeatureCollection, Polygon } from \"geojson\";\nimport { featureCollection, isObject, multiPolygon } from \"@turf/helpers\";\nimport { collectionOf } from \"@turf/invariant\";\nimport { featureEach } from \"@turf/meta\";\nimport { flatten } from \"@turf/flatten\";\nimport polygonClipping, { Geom } from \"polygon-clipping\";\n\n/**\n * Dissolves a FeatureCollection of {@link polygon} features, filtered by an optional property name:value.\n * Note that {@link mulitpolygon} features within the collection are not supported\n *\n * @name dissolve\n * @param {FeatureCollection<Polygon>} featureCollection input feature collection to be dissolved\n * @param {Object} [options={}] Optional parameters\n * @param {string} [options.propertyName] features with the same `propertyName` value will be dissolved.\n * @returns {FeatureCollection<Polygon>} a FeatureCollection containing the dissolved polygons\n * @example\n * var features = turf.featureCollection([\n * turf.polygon([[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]], {combine: 'yes'}),\n * turf.polygon([[[0, -1], [0, 0], [1, 0], [1, -1], [0,-1]]], {combine: 'yes'}),\n * turf.polygon([[[1,-1],[1, 0], [2, 0], [2, -1], [1, -1]]], {combine: 'no'}),\n * ]);\n *\n * var dissolved = turf.dissolve(features, {propertyName: 'combine'});\n *\n * //addToMap\n * var addToMap = [features, dissolved]\n */\nfunction dissolve(\n fc: FeatureCollection<Polygon>,\n options: {\n propertyName?: string;\n } = {}\n): FeatureCollection<Polygon> {\n // Optional parameters\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n const { propertyName } = options;\n\n // Input validation\n collectionOf(fc, \"Polygon\", \"dissolve\");\n\n // Main\n const outFeatures = [];\n if (!propertyName) {\n return flatten(\n multiPolygon(\n polygonClipping.union.apply(\n null,\n // List of polygons expressed as Position[][][] a.k.a. Geom[]\n fc.features.map(function (f) {\n return f.geometry.coordinates;\n }) as [Geom, ...Geom[]]\n )\n )\n );\n } else {\n // Group polygons by the value of their property named by propertyName\n const uniquePropertyVals: { [key: string]: Feature[] } = {};\n featureEach(fc, function (feature) {\n if (feature.properties) {\n if (\n !Object.prototype.hasOwnProperty.call(\n uniquePropertyVals,\n feature.properties[propertyName]\n )\n ) {\n uniquePropertyVals[feature.properties[propertyName]] =\n [] as Feature[];\n }\n uniquePropertyVals[feature.properties[propertyName]].push(feature);\n }\n });\n const vals = Object.keys(uniquePropertyVals);\n\n // Export each group of polygons as a separate feature.\n for (let i = 0; i < vals.length; i++) {\n const mp = multiPolygon(\n polygonClipping.union.apply(\n null,\n // List of polygons expressed as Position[][][] a.k.a. Geom[]\n (uniquePropertyVals[vals[i]] as Feature<Polygon>[]).map(function (f) {\n return f.geometry.coordinates;\n }) as [Geom, ...Geom[]]\n )\n );\n if (mp && mp.properties) {\n mp.properties[propertyName] = vals[i];\n outFeatures.push(mp);\n }\n }\n }\n\n return flatten(featureCollection(outFeatures));\n}\n\nexport { dissolve };\nexport default dissolve;\n"]}
@@ -0,0 +1,28 @@
1
+ import { FeatureCollection, Polygon } from 'geojson';
2
+
3
+ /**
4
+ * Dissolves a FeatureCollection of {@link polygon} features, filtered by an optional property name:value.
5
+ * Note that {@link mulitpolygon} features within the collection are not supported
6
+ *
7
+ * @name dissolve
8
+ * @param {FeatureCollection<Polygon>} featureCollection input feature collection to be dissolved
9
+ * @param {Object} [options={}] Optional parameters
10
+ * @param {string} [options.propertyName] features with the same `propertyName` value will be dissolved.
11
+ * @returns {FeatureCollection<Polygon>} a FeatureCollection containing the dissolved polygons
12
+ * @example
13
+ * var features = turf.featureCollection([
14
+ * turf.polygon([[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]], {combine: 'yes'}),
15
+ * turf.polygon([[[0, -1], [0, 0], [1, 0], [1, -1], [0,-1]]], {combine: 'yes'}),
16
+ * turf.polygon([[[1,-1],[1, 0], [2, 0], [2, -1], [1, -1]]], {combine: 'no'}),
17
+ * ]);
18
+ *
19
+ * var dissolved = turf.dissolve(features, {propertyName: 'combine'});
20
+ *
21
+ * //addToMap
22
+ * var addToMap = [features, dissolved]
23
+ */
24
+ declare function dissolve(fc: FeatureCollection<Polygon>, options?: {
25
+ propertyName?: string;
26
+ }): FeatureCollection<Polygon>;
27
+
28
+ export { dissolve as default, dissolve };
@@ -0,0 +1,28 @@
1
+ import { FeatureCollection, Polygon } from 'geojson';
2
+
3
+ /**
4
+ * Dissolves a FeatureCollection of {@link polygon} features, filtered by an optional property name:value.
5
+ * Note that {@link mulitpolygon} features within the collection are not supported
6
+ *
7
+ * @name dissolve
8
+ * @param {FeatureCollection<Polygon>} featureCollection input feature collection to be dissolved
9
+ * @param {Object} [options={}] Optional parameters
10
+ * @param {string} [options.propertyName] features with the same `propertyName` value will be dissolved.
11
+ * @returns {FeatureCollection<Polygon>} a FeatureCollection containing the dissolved polygons
12
+ * @example
13
+ * var features = turf.featureCollection([
14
+ * turf.polygon([[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]], {combine: 'yes'}),
15
+ * turf.polygon([[[0, -1], [0, 0], [1, 0], [1, -1], [0,-1]]], {combine: 'yes'}),
16
+ * turf.polygon([[[1,-1],[1, 0], [2, 0], [2, -1], [1, -1]]], {combine: 'no'}),
17
+ * ]);
18
+ *
19
+ * var dissolved = turf.dissolve(features, {propertyName: 'combine'});
20
+ *
21
+ * //addToMap
22
+ * var addToMap = [features, dissolved]
23
+ */
24
+ declare function dissolve(fc: FeatureCollection<Polygon>, options?: {
25
+ propertyName?: string;
26
+ }): FeatureCollection<Polygon>;
27
+
28
+ export { dissolve as default, dissolve };
@@ -0,0 +1,67 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+
4
+ // index.ts
5
+ import { featureCollection, isObject, multiPolygon } from "@turf/helpers";
6
+ import { collectionOf } from "@turf/invariant";
7
+ import { featureEach } from "@turf/meta";
8
+ import { flatten } from "@turf/flatten";
9
+ import polygonClipping from "polygon-clipping";
10
+ function dissolve(fc, options = {}) {
11
+ options = options || {};
12
+ if (!isObject(options))
13
+ throw new Error("options is invalid");
14
+ const { propertyName } = options;
15
+ collectionOf(fc, "Polygon", "dissolve");
16
+ const outFeatures = [];
17
+ if (!propertyName) {
18
+ return flatten(
19
+ multiPolygon(
20
+ polygonClipping.union.apply(
21
+ null,
22
+ // List of polygons expressed as Position[][][] a.k.a. Geom[]
23
+ fc.features.map(function(f) {
24
+ return f.geometry.coordinates;
25
+ })
26
+ )
27
+ )
28
+ );
29
+ } else {
30
+ const uniquePropertyVals = {};
31
+ featureEach(fc, function(feature) {
32
+ if (feature.properties) {
33
+ if (!Object.prototype.hasOwnProperty.call(
34
+ uniquePropertyVals,
35
+ feature.properties[propertyName]
36
+ )) {
37
+ uniquePropertyVals[feature.properties[propertyName]] = [];
38
+ }
39
+ uniquePropertyVals[feature.properties[propertyName]].push(feature);
40
+ }
41
+ });
42
+ const vals = Object.keys(uniquePropertyVals);
43
+ for (let i = 0; i < vals.length; i++) {
44
+ const mp = multiPolygon(
45
+ polygonClipping.union.apply(
46
+ null,
47
+ // List of polygons expressed as Position[][][] a.k.a. Geom[]
48
+ uniquePropertyVals[vals[i]].map(function(f) {
49
+ return f.geometry.coordinates;
50
+ })
51
+ )
52
+ );
53
+ if (mp && mp.properties) {
54
+ mp.properties[propertyName] = vals[i];
55
+ outFeatures.push(mp);
56
+ }
57
+ }
58
+ }
59
+ return flatten(featureCollection(outFeatures));
60
+ }
61
+ __name(dissolve, "dissolve");
62
+ var turf_dissolve_default = dissolve;
63
+ export {
64
+ turf_dissolve_default as default,
65
+ dissolve
66
+ };
67
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../index.ts"],"sourcesContent":["import { Feature, FeatureCollection, Polygon } from \"geojson\";\nimport { featureCollection, isObject, multiPolygon } from \"@turf/helpers\";\nimport { collectionOf } from \"@turf/invariant\";\nimport { featureEach } from \"@turf/meta\";\nimport { flatten } from \"@turf/flatten\";\nimport polygonClipping, { Geom } from \"polygon-clipping\";\n\n/**\n * Dissolves a FeatureCollection of {@link polygon} features, filtered by an optional property name:value.\n * Note that {@link mulitpolygon} features within the collection are not supported\n *\n * @name dissolve\n * @param {FeatureCollection<Polygon>} featureCollection input feature collection to be dissolved\n * @param {Object} [options={}] Optional parameters\n * @param {string} [options.propertyName] features with the same `propertyName` value will be dissolved.\n * @returns {FeatureCollection<Polygon>} a FeatureCollection containing the dissolved polygons\n * @example\n * var features = turf.featureCollection([\n * turf.polygon([[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]], {combine: 'yes'}),\n * turf.polygon([[[0, -1], [0, 0], [1, 0], [1, -1], [0,-1]]], {combine: 'yes'}),\n * turf.polygon([[[1,-1],[1, 0], [2, 0], [2, -1], [1, -1]]], {combine: 'no'}),\n * ]);\n *\n * var dissolved = turf.dissolve(features, {propertyName: 'combine'});\n *\n * //addToMap\n * var addToMap = [features, dissolved]\n */\nfunction dissolve(\n fc: FeatureCollection<Polygon>,\n options: {\n propertyName?: string;\n } = {}\n): FeatureCollection<Polygon> {\n // Optional parameters\n options = options || {};\n if (!isObject(options)) throw new Error(\"options is invalid\");\n const { propertyName } = options;\n\n // Input validation\n collectionOf(fc, \"Polygon\", \"dissolve\");\n\n // Main\n const outFeatures = [];\n if (!propertyName) {\n return flatten(\n multiPolygon(\n polygonClipping.union.apply(\n null,\n // List of polygons expressed as Position[][][] a.k.a. Geom[]\n fc.features.map(function (f) {\n return f.geometry.coordinates;\n }) as [Geom, ...Geom[]]\n )\n )\n );\n } else {\n // Group polygons by the value of their property named by propertyName\n const uniquePropertyVals: { [key: string]: Feature[] } = {};\n featureEach(fc, function (feature) {\n if (feature.properties) {\n if (\n !Object.prototype.hasOwnProperty.call(\n uniquePropertyVals,\n feature.properties[propertyName]\n )\n ) {\n uniquePropertyVals[feature.properties[propertyName]] =\n [] as Feature[];\n }\n uniquePropertyVals[feature.properties[propertyName]].push(feature);\n }\n });\n const vals = Object.keys(uniquePropertyVals);\n\n // Export each group of polygons as a separate feature.\n for (let i = 0; i < vals.length; i++) {\n const mp = multiPolygon(\n polygonClipping.union.apply(\n null,\n // List of polygons expressed as Position[][][] a.k.a. Geom[]\n (uniquePropertyVals[vals[i]] as Feature<Polygon>[]).map(function (f) {\n return f.geometry.coordinates;\n }) as [Geom, ...Geom[]]\n )\n );\n if (mp && mp.properties) {\n mp.properties[propertyName] = vals[i];\n outFeatures.push(mp);\n }\n }\n }\n\n return flatten(featureCollection(outFeatures));\n}\n\nexport { dissolve };\nexport default dissolve;\n"],"mappings":";;;;AACA,SAAS,mBAAmB,UAAU,oBAAoB;AAC1D,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB;AAC5B,SAAS,eAAe;AACxB,OAAO,qBAA+B;AAuBtC,SAAS,SACP,IACA,UAEI,CAAC,GACuB;AAE5B,YAAU,WAAW,CAAC;AACtB,MAAI,CAAC,SAAS,OAAO;AAAG,UAAM,IAAI,MAAM,oBAAoB;AAC5D,QAAM,EAAE,aAAa,IAAI;AAGzB,eAAa,IAAI,WAAW,UAAU;AAGtC,QAAM,cAAc,CAAC;AACrB,MAAI,CAAC,cAAc;AACjB,WAAO;AAAA,MACL;AAAA,QACE,gBAAgB,MAAM;AAAA,UACpB;AAAA;AAAA,UAEA,GAAG,SAAS,IAAI,SAAU,GAAG;AAC3B,mBAAO,EAAE,SAAS;AAAA,UACpB,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,EACF,OAAO;AAEL,UAAM,qBAAmD,CAAC;AAC1D,gBAAY,IAAI,SAAU,SAAS;AACjC,UAAI,QAAQ,YAAY;AACtB,YACE,CAAC,OAAO,UAAU,eAAe;AAAA,UAC/B;AAAA,UACA,QAAQ,WAAW,YAAY;AAAA,QACjC,GACA;AACA,6BAAmB,QAAQ,WAAW,YAAY,CAAC,IACjD,CAAC;AAAA,QACL;AACA,2BAAmB,QAAQ,WAAW,YAAY,CAAC,EAAE,KAAK,OAAO;AAAA,MACnE;AAAA,IACF,CAAC;AACD,UAAM,OAAO,OAAO,KAAK,kBAAkB;AAG3C,aAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,YAAM,KAAK;AAAA,QACT,gBAAgB,MAAM;AAAA,UACpB;AAAA;AAAA,UAEC,mBAAmB,KAAK,CAAC,CAAC,EAAyB,IAAI,SAAU,GAAG;AACnE,mBAAO,EAAE,SAAS;AAAA,UACpB,CAAC;AAAA,QACH;AAAA,MACF;AACA,UAAI,MAAM,GAAG,YAAY;AACvB,WAAG,WAAW,YAAY,IAAI,KAAK,CAAC;AACpC,oBAAY,KAAK,EAAE;AAAA,MACrB;AAAA,IACF;AAAA,EACF;AAEA,SAAO,QAAQ,kBAAkB,WAAW,CAAC;AAC/C;AAlES;AAqET,IAAO,wBAAQ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/dissolve",
3
- "version": "7.0.0-alpha.2",
3
+ "version": "7.0.0",
4
4
  "description": "turf dissolve module",
5
5
  "author": "Turf Authors",
6
6
  "license": "MIT",
@@ -23,44 +23,53 @@
23
23
  "geojson",
24
24
  "polygon"
25
25
  ],
26
- "main": "dist/js/index.js",
27
- "module": "dist/es/index.js",
26
+ "type": "module",
27
+ "main": "dist/cjs/index.cjs",
28
+ "module": "dist/esm/index.js",
29
+ "types": "dist/esm/index.d.ts",
28
30
  "exports": {
29
31
  "./package.json": "./package.json",
30
32
  ".": {
31
- "types": "./index.d.ts",
32
- "import": "./dist/es/index.js",
33
- "require": "./dist/js/index.js"
33
+ "import": {
34
+ "types": "./dist/esm/index.d.ts",
35
+ "default": "./dist/esm/index.js"
36
+ },
37
+ "require": {
38
+ "types": "./dist/cjs/index.d.cts",
39
+ "default": "./dist/cjs/index.cjs"
40
+ }
34
41
  }
35
42
  },
36
- "types": "index.d.ts",
37
43
  "sideEffects": false,
38
44
  "files": [
39
- "dist",
40
- "index.d.ts"
45
+ "dist"
41
46
  ],
42
47
  "scripts": {
43
- "bench": "tsx bench.js",
44
- "build": "rollup -c ../../rollup.config.js && echo '{\"type\":\"module\"}' > dist/es/package.json",
45
- "docs": "tsx ../../scripts/generate-readmes",
46
- "test": "npm-run-all test:*",
47
- "test:tape": "tsx test.js"
48
+ "bench": "tsx bench.ts",
49
+ "build": "tsup --config ../../tsup.config.ts",
50
+ "docs": "tsx ../../scripts/generate-readmes.ts",
51
+ "test": "npm-run-all --npm-path npm test:*",
52
+ "test:tape": "tsx test.ts"
48
53
  },
49
54
  "devDependencies": {
50
- "benchmark": "*",
51
- "load-json-file": "*",
52
- "npm-run-all": "*",
53
- "rollup": "*",
54
- "tape": "*",
55
- "tsx": "*",
56
- "write-json-file": "*"
55
+ "@types/benchmark": "^2.1.5",
56
+ "@types/tape": "^4.2.32",
57
+ "benchmark": "^2.1.4",
58
+ "load-json-file": "^7.0.1",
59
+ "npm-run-all": "^4.1.5",
60
+ "tape": "^5.7.2",
61
+ "tsup": "^8.0.1",
62
+ "tsx": "^4.6.2",
63
+ "typescript": "^5.2.2",
64
+ "write-json-file": "^5.0.0"
57
65
  },
58
66
  "dependencies": {
59
- "@turf/flatten": "^7.0.0-alpha.2",
60
- "@turf/helpers": "^7.0.0-alpha.2",
61
- "@turf/invariant": "^7.0.0-alpha.2",
62
- "@turf/meta": "^7.0.0-alpha.2",
63
- "polygon-clipping": "^0.15.3"
67
+ "@turf/flatten": "^7.0.0",
68
+ "@turf/helpers": "^7.0.0",
69
+ "@turf/invariant": "^7.0.0",
70
+ "@turf/meta": "^7.0.0",
71
+ "polygon-clipping": "^0.15.3",
72
+ "tslib": "^2.6.2"
64
73
  },
65
- "gitHead": "dd35b52725945b4fa29a98d9a550733e06cc222e"
74
+ "gitHead": "3d3a7917025fbabe191dbddbc89754b86f9c7739"
66
75
  }
package/dist/es/index.js DELETED
@@ -1,81 +0,0 @@
1
- import { isObject, multiPolygon, featureCollection } from '@turf/helpers';
2
- import { collectionOf } from '@turf/invariant';
3
- import { featureEach } from '@turf/meta';
4
- import flatten from '@turf/flatten';
5
- import polygonClipping from 'polygon-clipping';
6
-
7
- /**
8
- * Dissolves a FeatureCollection of {@link polygon} features, filtered by an optional property name:value.
9
- * Note that {@link mulitpolygon} features within the collection are not supported
10
- *
11
- * @name dissolve
12
- * @param {FeatureCollection<Polygon>} featureCollection input feature collection to be dissolved
13
- * @param {Object} [options={}] Optional parameters
14
- * @param {string} [options.propertyName] features with the same `propertyName` value will be dissolved.
15
- * @returns {FeatureCollection<Polygon>} a FeatureCollection containing the dissolved polygons
16
- * @example
17
- * var features = turf.featureCollection([
18
- * turf.polygon([[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]], {combine: 'yes'}),
19
- * turf.polygon([[[0, -1], [0, 0], [1, 0], [1, -1], [0,-1]]], {combine: 'yes'}),
20
- * turf.polygon([[[1,-1],[1, 0], [2, 0], [2, -1], [1, -1]]], {combine: 'no'}),
21
- * ]);
22
- *
23
- * var dissolved = turf.dissolve(features, {propertyName: 'combine'});
24
- *
25
- * //addToMap
26
- * var addToMap = [features, dissolved]
27
- */
28
- function dissolve(fc, options) {
29
- // Optional parameters
30
- options = options || {};
31
- if (!isObject(options)) throw new Error("options is invalid");
32
- var propertyName = options.propertyName;
33
-
34
- // Input validation
35
- collectionOf(fc, "Polygon", "dissolve");
36
-
37
- // Main
38
- var outFeatures = [];
39
- if (!options.propertyName) {
40
- return flatten(
41
- multiPolygon(
42
- polygonClipping.union.apply(
43
- null,
44
- fc.features.map(function (f) {
45
- return f.geometry.coordinates;
46
- })
47
- )
48
- )
49
- );
50
- } else {
51
- var uniquePropertyVals = {};
52
- featureEach(fc, function (feature) {
53
- if (
54
- !Object.prototype.hasOwnProperty.call(
55
- uniquePropertyVals,
56
- feature.properties[propertyName]
57
- )
58
- ) {
59
- uniquePropertyVals[feature.properties[propertyName]] = [];
60
- }
61
- uniquePropertyVals[feature.properties[propertyName]].push(feature);
62
- });
63
- var vals = Object.keys(uniquePropertyVals);
64
- for (var i = 0; i < vals.length; i++) {
65
- var mp = multiPolygon(
66
- polygonClipping.union.apply(
67
- null,
68
- uniquePropertyVals[vals[i]].map(function (f) {
69
- return f.geometry.coordinates;
70
- })
71
- )
72
- );
73
- mp.properties[propertyName] = vals[i];
74
- outFeatures.push(mp);
75
- }
76
- }
77
-
78
- return flatten(featureCollection(outFeatures));
79
- }
80
-
81
- export default dissolve;
@@ -1 +0,0 @@
1
- {"type":"module"}
package/dist/js/index.js DELETED
@@ -1,89 +0,0 @@
1
- 'use strict';
2
-
3
- var helpers = require('@turf/helpers');
4
- var invariant = require('@turf/invariant');
5
- var meta = require('@turf/meta');
6
- var flatten = require('@turf/flatten');
7
- var polygonClipping = require('polygon-clipping');
8
-
9
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
-
11
- var flatten__default = /*#__PURE__*/_interopDefaultLegacy(flatten);
12
- var polygonClipping__default = /*#__PURE__*/_interopDefaultLegacy(polygonClipping);
13
-
14
- /**
15
- * Dissolves a FeatureCollection of {@link polygon} features, filtered by an optional property name:value.
16
- * Note that {@link mulitpolygon} features within the collection are not supported
17
- *
18
- * @name dissolve
19
- * @param {FeatureCollection<Polygon>} featureCollection input feature collection to be dissolved
20
- * @param {Object} [options={}] Optional parameters
21
- * @param {string} [options.propertyName] features with the same `propertyName` value will be dissolved.
22
- * @returns {FeatureCollection<Polygon>} a FeatureCollection containing the dissolved polygons
23
- * @example
24
- * var features = turf.featureCollection([
25
- * turf.polygon([[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]], {combine: 'yes'}),
26
- * turf.polygon([[[0, -1], [0, 0], [1, 0], [1, -1], [0,-1]]], {combine: 'yes'}),
27
- * turf.polygon([[[1,-1],[1, 0], [2, 0], [2, -1], [1, -1]]], {combine: 'no'}),
28
- * ]);
29
- *
30
- * var dissolved = turf.dissolve(features, {propertyName: 'combine'});
31
- *
32
- * //addToMap
33
- * var addToMap = [features, dissolved]
34
- */
35
- function dissolve(fc, options) {
36
- // Optional parameters
37
- options = options || {};
38
- if (!helpers.isObject(options)) throw new Error("options is invalid");
39
- var propertyName = options.propertyName;
40
-
41
- // Input validation
42
- invariant.collectionOf(fc, "Polygon", "dissolve");
43
-
44
- // Main
45
- var outFeatures = [];
46
- if (!options.propertyName) {
47
- return flatten__default['default'](
48
- helpers.multiPolygon(
49
- polygonClipping__default['default'].union.apply(
50
- null,
51
- fc.features.map(function (f) {
52
- return f.geometry.coordinates;
53
- })
54
- )
55
- )
56
- );
57
- } else {
58
- var uniquePropertyVals = {};
59
- meta.featureEach(fc, function (feature) {
60
- if (
61
- !Object.prototype.hasOwnProperty.call(
62
- uniquePropertyVals,
63
- feature.properties[propertyName]
64
- )
65
- ) {
66
- uniquePropertyVals[feature.properties[propertyName]] = [];
67
- }
68
- uniquePropertyVals[feature.properties[propertyName]].push(feature);
69
- });
70
- var vals = Object.keys(uniquePropertyVals);
71
- for (var i = 0; i < vals.length; i++) {
72
- var mp = helpers.multiPolygon(
73
- polygonClipping__default['default'].union.apply(
74
- null,
75
- uniquePropertyVals[vals[i]].map(function (f) {
76
- return f.geometry.coordinates;
77
- })
78
- )
79
- );
80
- mp.properties[propertyName] = vals[i];
81
- outFeatures.push(mp);
82
- }
83
- }
84
-
85
- return flatten__default['default'](helpers.featureCollection(outFeatures));
86
- }
87
-
88
- module.exports = dissolve;
89
- module.exports.default = dissolve;
package/index.d.ts DELETED
@@ -1,11 +0,0 @@
1
- import { FeatureCollection, Polygon } from "geojson";
2
-
3
- /**
4
- * http://turfjs.org/docs.html#dissolve
5
- */
6
- export default function dissolve(
7
- featureCollection: FeatureCollection<Polygon>,
8
- options?: {
9
- propertyName?: string;
10
- }
11
- ): FeatureCollection<Polygon>;