@turf/union
Advanced tools
Comparing version 7.1.0 to 7.2.0
import { GeoJsonProperties, FeatureCollection, Polygon, MultiPolygon, Feature } from 'geojson'; | ||
/** | ||
* Takes input {@link (Multi)Polygon(s)} and returns a combined polygon. If the input polygons are not contiguous, this function returns a {@link MultiPolygon} feature. | ||
* Takes a collection of input polygons and returns a combined polygon. If the | ||
* input polygons are not contiguous, this function returns a multi-polygon | ||
* feature. | ||
* | ||
* @name union | ||
* @param {Feature<Polygon|MultiPolygon>} polygon1 input Polygon features | ||
* @function | ||
* @param {FeatureCollection<Polygon|MultiPolygon>} features input polygon features | ||
* @param {Object} [options={}] Optional Parameters | ||
* @param {Object} [options.properties={}] Translate Properties to output Feature | ||
* @returns {Feature<(Polygon|MultiPolygon)>} a combined {@link Polygon} or {@link MultiPolygon} feature, or null if the inputs are empty | ||
* @param {GeoJsonProperties} [options.properties={}] properties to assign to output feature | ||
* @returns {Feature<(Polygon|MultiPolygon)>|null} a combined polygon or multi-polygon feature, or null if there were no input polygons to combine | ||
* @example | ||
* var poly1 = turf.polygon([[ | ||
* [-82.574787, 35.594087], | ||
* [-82.574787, 35.615581], | ||
* [-82.545261, 35.615581], | ||
* [-82.545261, 35.594087], | ||
* [-82.574787, 35.594087] | ||
* ]], {"fill": "#0f0"}); | ||
* var poly2 = turf.polygon([[ | ||
* [-82.560024, 35.585153], | ||
* [-82.560024, 35.602602], | ||
* [-82.52964, 35.602602], | ||
* [-82.52964, 35.585153], | ||
* [-82.560024, 35.585153] | ||
* ]], {"fill": "#00f"}); | ||
* | ||
* var union = turf.union(turf.featureCollection([poly1, poly2])); | ||
* const poly1 = turf.polygon( | ||
* [ | ||
* [ | ||
* [-82.574787, 35.594087], | ||
* [-82.574787, 35.615581], | ||
* [-82.545261, 35.615581], | ||
* [-82.545261, 35.594087], | ||
* [-82.574787, 35.594087], | ||
* ], | ||
* ], | ||
* { fill: "#0f0" } | ||
* ); | ||
* | ||
* const poly2 = turf.polygon( | ||
* [ | ||
* [ | ||
* [-82.560024, 35.585153], | ||
* [-82.560024, 35.602602], | ||
* [-82.52964, 35.602602], | ||
* [-82.52964, 35.585153], | ||
* [-82.560024, 35.585153], | ||
* ], | ||
* ], | ||
* ); | ||
* | ||
* const union = turf.union(turf.featureCollection([poly1, poly2])); | ||
* | ||
* //addToMap | ||
* var addToMap = [poly1, poly2, union]; | ||
* const addToMap = { poly1, poly2, union }; | ||
* | ||
* poly1.properties.fill = "#0f0"; | ||
* poly2.properties.fill = "#00f"; | ||
* union.properties.stroke = "red"; | ||
* union.properties["stroke-width"] = 4; | ||
* union.properties.fill = "transparent"; | ||
*/ | ||
@@ -32,0 +51,0 @@ declare function union<P extends GeoJsonProperties = GeoJsonProperties>(features: FeatureCollection<Polygon | MultiPolygon>, options?: { |
// index.ts | ||
import polygonClipping from "polygon-clipping"; | ||
import * as polyclip from "polyclip-ts"; | ||
import { multiPolygon, polygon } from "@turf/helpers"; | ||
import { geomEach } from "@turf/meta"; | ||
function union(features, options = {}) { | ||
function union2(features, options = {}) { | ||
const geoms = []; | ||
@@ -13,15 +13,12 @@ geomEach(features, (geom) => { | ||
} | ||
const unioned = polygonClipping.union(geoms[0], ...geoms.slice(1)); | ||
if (unioned.length === 0) | ||
return null; | ||
if (unioned.length === 1) | ||
return polygon(unioned[0], options.properties); | ||
else | ||
return multiPolygon(unioned, options.properties); | ||
const unioned = polyclip.union(geoms[0], ...geoms.slice(1)); | ||
if (unioned.length === 0) return null; | ||
if (unioned.length === 1) return polygon(unioned[0], options.properties); | ||
else return multiPolygon(unioned, options.properties); | ||
} | ||
var turf_union_default = union; | ||
var turf_union_default = union2; | ||
export { | ||
turf_union_default as default, | ||
union | ||
union2 as union | ||
}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@turf/union", | ||
"version": "7.1.0", | ||
"version": "7.2.0", | ||
"description": "turf union module", | ||
@@ -54,3 +54,3 @@ "author": "Turf Authors", | ||
"@types/benchmark": "^2.1.5", | ||
"@types/tape": "^4.2.32", | ||
"@types/tape": "^4.13.4", | ||
"benchmark": "^2.1.4", | ||
@@ -60,16 +60,16 @@ "glob": "^10.3.10", | ||
"npm-run-all": "^4.1.5", | ||
"tape": "^5.7.2", | ||
"tsup": "^8.0.1", | ||
"tsx": "^4.6.2", | ||
"typescript": "^5.2.2", | ||
"tape": "^5.9.0", | ||
"tsup": "^8.3.5", | ||
"tsx": "^4.19.2", | ||
"typescript": "^5.5.4", | ||
"write-json-file": "^5.0.0" | ||
}, | ||
"dependencies": { | ||
"@turf/helpers": "^7.1.0", | ||
"@turf/meta": "^7.1.0", | ||
"@turf/helpers": "^7.2.0", | ||
"@turf/meta": "^7.2.0", | ||
"@types/geojson": "^7946.0.10", | ||
"polygon-clipping": "^0.15.3", | ||
"tslib": "^2.6.2" | ||
"polyclip-ts": "^0.16.8", | ||
"tslib": "^2.8.1" | ||
}, | ||
"gitHead": "68915eeebc9278bb40dec3f1034499698a0561ef" | ||
"gitHead": "7b0f0374c4668cd569f8904c71e2ae7d941be867" | ||
} |
@@ -7,10 +7,12 @@ # @turf/union | ||
Takes input [(Multi)Polygon(s)][1] and returns a combined polygon. If the input polygons are not contiguous, this function returns a [MultiPolygon][2] feature. | ||
Takes a collection of input polygons and returns a combined polygon. If the | ||
input polygons are not contiguous, this function returns a multi-polygon | ||
feature. | ||
### Parameters | ||
* `polygon1` **[Feature][3]<([Polygon][1] | [MultiPolygon][2])>** input Polygon features | ||
* `features` **[FeatureCollection][1]<([Polygon][2] | [MultiPolygon][3])>** input polygon features | ||
* `options` **[Object][4]** Optional Parameters (optional, default `{}`) | ||
* `options.properties` **[Object][4]** Translate Properties to output Feature (optional, default `{}`) | ||
* `options.properties` **[GeoJsonProperties][5]** properties to assign to output feature (optional, default `{}`) | ||
@@ -20,33 +22,51 @@ ### Examples | ||
```javascript | ||
var poly1 = turf.polygon([[ | ||
[-82.574787, 35.594087], | ||
[-82.574787, 35.615581], | ||
[-82.545261, 35.615581], | ||
[-82.545261, 35.594087], | ||
[-82.574787, 35.594087] | ||
]], {"fill": "#0f0"}); | ||
var poly2 = turf.polygon([[ | ||
[-82.560024, 35.585153], | ||
[-82.560024, 35.602602], | ||
[-82.52964, 35.602602], | ||
[-82.52964, 35.585153], | ||
[-82.560024, 35.585153] | ||
]], {"fill": "#00f"}); | ||
const poly1 = turf.polygon( | ||
[ | ||
[ | ||
[-82.574787, 35.594087], | ||
[-82.574787, 35.615581], | ||
[-82.545261, 35.615581], | ||
[-82.545261, 35.594087], | ||
[-82.574787, 35.594087], | ||
], | ||
], | ||
{ fill: "#0f0" } | ||
); | ||
var union = turf.union(turf.featureCollection([poly1, poly2])); | ||
const poly2 = turf.polygon( | ||
[ | ||
[ | ||
[-82.560024, 35.585153], | ||
[-82.560024, 35.602602], | ||
[-82.52964, 35.602602], | ||
[-82.52964, 35.585153], | ||
[-82.560024, 35.585153], | ||
], | ||
], | ||
); | ||
const union = turf.union(turf.featureCollection([poly1, poly2])); | ||
//addToMap | ||
var addToMap = [poly1, poly2, union]; | ||
const addToMap = { poly1, poly2, union }; | ||
poly1.properties.fill = "#0f0"; | ||
poly2.properties.fill = "#00f"; | ||
union.properties.stroke = "red"; | ||
union.properties["stroke-width"] = 4; | ||
union.properties.fill = "transparent"; | ||
``` | ||
Returns **[Feature][3]<([Polygon][1] | [MultiPolygon][2])>** a combined [Polygon][1] or [MultiPolygon][2] feature, or null if the inputs are empty | ||
Returns **([Feature][5]<([Polygon][2] | [MultiPolygon][3])> | null)** a combined polygon or multi-polygon feature, or null if there were no input polygons to combine | ||
[1]: https://tools.ietf.org/html/rfc7946#section-3.1.6 | ||
[1]: https://tools.ietf.org/html/rfc7946#section-3.3 | ||
[2]: https://tools.ietf.org/html/rfc7946#section-3.1.7 | ||
[2]: https://tools.ietf.org/html/rfc7946#section-3.1.6 | ||
[3]: https://tools.ietf.org/html/rfc7946#section-3.2 | ||
[3]: https://tools.ietf.org/html/rfc7946#section-3.1.7 | ||
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object | ||
[5]: https://tools.ietf.org/html/rfc7946#section-3.2 | ||
<!-- 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. --> | ||
@@ -53,0 +73,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17384
95
89
+ Addedpolyclip-ts@^0.16.8
+ Addedbignumber.js@9.1.2(transitive)
+ Addedpolyclip-ts@0.16.8(transitive)
+ Addedsplaytree-ts@1.0.2(transitive)
- Removedpolygon-clipping@^0.15.3
- Removedpolygon-clipping@0.15.7(transitive)
- Removedrobust-predicates@3.0.2(transitive)
- Removedsplaytree@3.1.2(transitive)
Updated@turf/helpers@^7.2.0
Updated@turf/meta@^7.2.0
Updatedtslib@^2.8.1