@turf/dissolve 7.1.0-alpha.70 → 7.2.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
@@ -4,15 +4,16 @@
4
4
 
5
5
  ## dissolve
6
6
 
7
- Dissolves a FeatureCollection of [polygon][1] features, filtered by an optional property name:value.
8
- Note that [mulitpolygon][2] features within the collection are not supported
7
+ Dissolves a FeatureCollection of [Polygon][1] features, filtered by an optional property name:value.
8
+ Note that [MultiPolygon][2] features within the collection are not supported
9
9
 
10
10
  ### Parameters
11
11
 
12
- * `featureCollection` **[FeatureCollection][3]<[Polygon][4]>** input feature collection to be dissolved
13
- * `options` **[Object][5]** Optional parameters (optional, default `{}`)
12
+ * `fc` **[FeatureCollection][3]<[Polygon][1]>**&#x20;
13
+ * `options` **[Object][4]** Optional parameters (optional, default `{}`)
14
14
 
15
- * `options.propertyName` **[string][6]?** features with the same `propertyName` value will be dissolved.
15
+ * `options.propertyName` **[string][5]?** features with the same `propertyName` value will be dissolved.
16
+ * `featureCollection` **[FeatureCollection][3]<[Polygon][1]>** input feature collection to be dissolved
16
17
 
17
18
  ### Examples
18
19
 
@@ -29,19 +30,17 @@ var dissolved = turf.dissolve(features, {propertyName: 'combine'});
29
30
  var addToMap = [features, dissolved]
30
31
  ```
31
32
 
32
- Returns **[FeatureCollection][3]<[Polygon][4]>** a FeatureCollection containing the dissolved polygons
33
+ Returns **[FeatureCollection][3]<[Polygon][1]>** a FeatureCollection containing the dissolved polygons
33
34
 
34
- [1]: polygon
35
+ [1]: https://tools.ietf.org/html/rfc7946#section-3.1.6
35
36
 
36
- [2]: mulitpolygon
37
+ [2]: https://tools.ietf.org/html/rfc7946#section-3.1.7
37
38
 
38
39
  [3]: https://tools.ietf.org/html/rfc7946#section-3.3
39
40
 
40
- [4]: https://tools.ietf.org/html/rfc7946#section-3.1.6
41
+ [4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
41
42
 
42
- [5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
43
-
44
- [6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
43
+ [5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
45
44
 
46
45
  <!-- 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. -->
47
46
 
@@ -1,20 +1,19 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// index.ts
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }// index.ts
2
2
  var _helpers = require('@turf/helpers');
3
3
  var _invariant = require('@turf/invariant');
4
4
  var _meta = require('@turf/meta');
5
5
  var _flatten = require('@turf/flatten');
6
- var _polygonclipping = require('polygon-clipping'); var _polygonclipping2 = _interopRequireDefault(_polygonclipping);
6
+ var _polyclipts = require('polyclip-ts'); var polyclip = _interopRequireWildcard(_polyclipts);
7
7
  function dissolve(fc, options = {}) {
8
8
  options = options || {};
9
- if (!_helpers.isObject.call(void 0, options))
10
- throw new Error("options is invalid");
9
+ if (!_helpers.isObject.call(void 0, options)) throw new Error("options is invalid");
11
10
  const { propertyName } = options;
12
11
  _invariant.collectionOf.call(void 0, fc, "Polygon", "dissolve");
13
12
  const outFeatures = [];
14
13
  if (!propertyName) {
15
14
  return _flatten.flatten.call(void 0,
16
15
  _helpers.multiPolygon.call(void 0,
17
- _polygonclipping2.default.union.apply(
16
+ polyclip.union.apply(
18
17
  null,
19
18
  // List of polygons expressed as Position[][][] a.k.a. Geom[]
20
19
  fc.features.map(function(f) {
@@ -39,7 +38,7 @@ function dissolve(fc, options = {}) {
39
38
  const vals = Object.keys(uniquePropertyVals);
40
39
  for (let i = 0; i < vals.length; i++) {
41
40
  const mp = _helpers.multiPolygon.call(void 0,
42
- _polygonclipping2.default.union.apply(
41
+ polyclip.union.apply(
43
42
  null,
44
43
  // List of polygons expressed as Position[][][] a.k.a. Geom[]
45
44
  uniquePropertyVals[vals[i]].map(function(f) {
@@ -1 +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;AAGA,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"]}
1
+ {"version":3,"sources":["/home/runner/work/turf/turf/packages/turf-dissolve/dist/cjs/index.cjs","../../index.ts"],"names":[],"mappings":"AAAA;ACCA,wCAA0D;AAC1D,4CAA6B;AAC7B,kCAA4B;AAC5B,wCAAwB;AACxB,8FAA0B;AAuB1B,SAAS,QAAA,CACP,EAAA,EACA,QAAA,EAEI,CAAC,CAAA,EACuB;AAE5B,EAAA,QAAA,EAAU,QAAA,GAAW,CAAC,CAAA;AACtB,EAAA,GAAA,CAAI,CAAC,+BAAA,OAAgB,CAAA,EAAG,MAAM,IAAI,KAAA,CAAM,oBAAoB,CAAA;AAC5D,EAAA,MAAM,EAAE,aAAa,EAAA,EAAI,OAAA;AAGzB,EAAA,qCAAA,EAAa,EAAI,SAAA,EAAW,UAAU,CAAA;AAGtC,EAAA,MAAM,YAAA,EAAc,CAAC,CAAA;AACrB,EAAA,GAAA,CAAI,CAAC,YAAA,EAAc;AACjB,IAAA,OAAO,8BAAA;AAAA,MACL,mCAAA;AAAA,QACW,QAAA,CAAA,KAAA,CAAM,KAAA;AAAA,UACb,IAAA;AAAA;AAAA,UAEA,EAAA,CAAG,QAAA,CAAS,GAAA,CAAI,QAAA,CAAU,CAAA,EAAG;AAC3B,YAAA,OAAO,CAAA,CAAE,QAAA,CAAS,WAAA;AAAA,UACpB,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF,CAAA;AAAA,EACF,EAAA,KAAO;AAEL,IAAA,MAAM,mBAAA,EAAmD,CAAC,CAAA;AAC1D,IAAA,+BAAA,EAAY,EAAI,QAAA,CAAU,OAAA,EAAS;AACjC,MAAA,GAAA,CAAI,OAAA,CAAQ,UAAA,EAAY;AACtB,QAAA,GAAA,CACE,CAAC,MAAA,CAAO,SAAA,CAAU,cAAA,CAAe,IAAA;AAAA,UAC/B,kBAAA;AAAA,UACA,OAAA,CAAQ,UAAA,CAAW,YAAY;AAAA,QACjC,CAAA,EACA;AACA,UAAA,kBAAA,CAAmB,OAAA,CAAQ,UAAA,CAAW,YAAY,CAAC,EAAA,EACjD,CAAC,CAAA;AAAA,QACL;AACA,QAAA,kBAAA,CAAmB,OAAA,CAAQ,UAAA,CAAW,YAAY,CAAC,CAAA,CAAE,IAAA,CAAK,OAAO,CAAA;AAAA,MACnE;AAAA,IACF,CAAC,CAAA;AACD,IAAA,MAAM,KAAA,EAAO,MAAA,CAAO,IAAA,CAAK,kBAAkB,CAAA;AAG3C,IAAA,IAAA,CAAA,IAAS,EAAA,EAAI,CAAA,EAAG,EAAA,EAAI,IAAA,CAAK,MAAA,EAAQ,CAAA,EAAA,EAAK;AACpC,MAAA,MAAM,GAAA,EAAK,mCAAA;AAAA,QACA,QAAA,CAAA,KAAA,CAAM,KAAA;AAAA,UACb,IAAA;AAAA;AAAA,UAEC,kBAAA,CAAmB,IAAA,CAAK,CAAC,CAAC,CAAA,CAAyB,GAAA,CAAI,QAAA,CAAU,CAAA,EAAG;AACnE,YAAA,OAAO,CAAA,CAAE,QAAA,CAAS,WAAA;AAAA,UACpB,CAAC;AAAA,QACH;AAAA,MACF,CAAA;AACA,MAAA,GAAA,CAAI,GAAA,GAAM,EAAA,CAAG,UAAA,EAAY;AACvB,QAAA,EAAA,CAAG,UAAA,CAAW,YAAY,EAAA,EAAI,IAAA,CAAK,CAAC,CAAA;AACpC,QAAA,WAAA,CAAY,IAAA,CAAK,EAAE,CAAA;AAAA,MACrB;AAAA,IACF;AAAA,EACF;AAEA,EAAA,OAAO,8BAAA,wCAAQ,WAA6B,CAAC,CAAA;AAC/C;AAGA,IAAO,sBAAA,EAAQ,QAAA;ADxCf;AACE;AACA;AACF,qEAAC","file":"/home/runner/work/turf/turf/packages/turf-dissolve/dist/cjs/index.cjs","sourcesContent":[null,"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 * as polyclip from \"polyclip-ts\";\n\n/**\n * Dissolves a FeatureCollection of {@link Polygon} features, filtered by an optional property name:value.\n * Note that {@link MultiPolygon} features within the collection are not supported\n *\n * @function\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 polyclip.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 [polyclip.Geom, ...polyclip.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 polyclip.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 [polyclip.Geom, ...polyclip.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"]}
@@ -1,10 +1,10 @@
1
1
  import { FeatureCollection, Polygon } from 'geojson';
2
2
 
3
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
4
+ * Dissolves a FeatureCollection of {@link Polygon} features, filtered by an optional property name:value.
5
+ * Note that {@link MultiPolygon} features within the collection are not supported
6
6
  *
7
- * @name dissolve
7
+ * @function
8
8
  * @param {FeatureCollection<Polygon>} featureCollection input feature collection to be dissolved
9
9
  * @param {Object} [options={}] Optional parameters
10
10
  * @param {string} [options.propertyName] features with the same `propertyName` value will be dissolved.
@@ -1,10 +1,10 @@
1
1
  import { FeatureCollection, Polygon } from 'geojson';
2
2
 
3
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
4
+ * Dissolves a FeatureCollection of {@link Polygon} features, filtered by an optional property name:value.
5
+ * Note that {@link MultiPolygon} features within the collection are not supported
6
6
  *
7
- * @name dissolve
7
+ * @function
8
8
  * @param {FeatureCollection<Polygon>} featureCollection input feature collection to be dissolved
9
9
  * @param {Object} [options={}] Optional parameters
10
10
  * @param {string} [options.propertyName] features with the same `propertyName` value will be dissolved.
package/dist/esm/index.js CHANGED
@@ -3,18 +3,17 @@ import { featureCollection, isObject, multiPolygon } from "@turf/helpers";
3
3
  import { collectionOf } from "@turf/invariant";
4
4
  import { featureEach } from "@turf/meta";
5
5
  import { flatten } from "@turf/flatten";
6
- import polygonClipping from "polygon-clipping";
6
+ import * as polyclip from "polyclip-ts";
7
7
  function dissolve(fc, options = {}) {
8
8
  options = options || {};
9
- if (!isObject(options))
10
- throw new Error("options is invalid");
9
+ if (!isObject(options)) throw new Error("options is invalid");
11
10
  const { propertyName } = options;
12
11
  collectionOf(fc, "Polygon", "dissolve");
13
12
  const outFeatures = [];
14
13
  if (!propertyName) {
15
14
  return flatten(
16
15
  multiPolygon(
17
- polygonClipping.union.apply(
16
+ polyclip.union.apply(
18
17
  null,
19
18
  // List of polygons expressed as Position[][][] a.k.a. Geom[]
20
19
  fc.features.map(function(f) {
@@ -39,7 +38,7 @@ function dissolve(fc, options = {}) {
39
38
  const vals = Object.keys(uniquePropertyVals);
40
39
  for (let i = 0; i < vals.length; i++) {
41
40
  const mp = multiPolygon(
42
- polygonClipping.union.apply(
41
+ polyclip.union.apply(
43
42
  null,
44
43
  // List of polygons expressed as Position[][][] a.k.a. Geom[]
45
44
  uniquePropertyVals[vals[i]].map(function(f) {
@@ -1 +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;AAGA,IAAO,wBAAQ;","names":[]}
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 * as polyclip from \"polyclip-ts\";\n\n/**\n * Dissolves a FeatureCollection of {@link Polygon} features, filtered by an optional property name:value.\n * Note that {@link MultiPolygon} features within the collection are not supported\n *\n * @function\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 polyclip.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 [polyclip.Geom, ...polyclip.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 polyclip.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 [polyclip.Geom, ...polyclip.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,YAAY,cAAc;AAuB1B,SAAS,SACP,IACA,UAEI,CAAC,GACuB;AAE5B,YAAU,WAAW,CAAC;AACtB,MAAI,CAAC,SAAS,OAAO,EAAG,OAAM,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,QACW,eAAM;AAAA,UACb;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,QACA,eAAM;AAAA,UACb;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;AAGA,IAAO,wBAAQ;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/dissolve",
3
- "version": "7.1.0-alpha.70+948cdafaf",
3
+ "version": "7.2.0",
4
4
  "description": "turf dissolve module",
5
5
  "author": "Turf Authors",
6
6
  "license": "MIT",
@@ -53,24 +53,24 @@
53
53
  },
54
54
  "devDependencies": {
55
55
  "@types/benchmark": "^2.1.5",
56
- "@types/tape": "^4.2.32",
56
+ "@types/tape": "^4.13.4",
57
57
  "benchmark": "^2.1.4",
58
58
  "load-json-file": "^7.0.1",
59
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",
60
+ "tape": "^5.9.0",
61
+ "tsup": "^8.3.5",
62
+ "tsx": "^4.19.2",
63
+ "typescript": "^5.5.4",
64
64
  "write-json-file": "^5.0.0"
65
65
  },
66
66
  "dependencies": {
67
- "@turf/flatten": "^7.1.0-alpha.70+948cdafaf",
68
- "@turf/helpers": "^7.1.0-alpha.70+948cdafaf",
69
- "@turf/invariant": "^7.1.0-alpha.70+948cdafaf",
70
- "@turf/meta": "^7.1.0-alpha.70+948cdafaf",
67
+ "@turf/flatten": "^7.2.0",
68
+ "@turf/helpers": "^7.2.0",
69
+ "@turf/invariant": "^7.2.0",
70
+ "@turf/meta": "^7.2.0",
71
71
  "@types/geojson": "^7946.0.10",
72
- "polygon-clipping": "^0.15.3",
73
- "tslib": "^2.6.2"
72
+ "polyclip-ts": "^0.16.8",
73
+ "tslib": "^2.8.1"
74
74
  },
75
- "gitHead": "948cdafaf70606d2e27fcc79973fa48ee1182067"
75
+ "gitHead": "7b0f0374c4668cd569f8904c71e2ae7d941be867"
76
76
  }