@turf/union
Advanced tools
Comparing version 6.5.0 to 7.0.0-alpha.0
import polygonClipping from "polygon-clipping"; | ||
import { getGeom } from "@turf/invariant"; | ||
import { multiPolygon, polygon } from "@turf/helpers"; | ||
import { geomEach } from "@turf/meta"; | ||
/** | ||
* Takes two {@link (Multi)Polygon(s)} and returns a combined polygon. If the input polygons are not contiguous, this function returns a {@link MultiPolygon} feature. | ||
* 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. | ||
* | ||
* @name union | ||
* @param {Feature<Polygon|MultiPolygon>} polygon1 input Polygon feature | ||
* @param {Feature<Polygon|MultiPolygon>} polygon2 Polygon feature to difference from polygon1 | ||
* @param {Feature<Polygon|MultiPolygon>} polygon1 input Polygon features | ||
* @param {Object} [options={}] Optional Parameters | ||
@@ -29,3 +28,3 @@ * @param {Object} [options.properties={}] Translate Properties to output Feature | ||
* | ||
* var union = turf.union(poly1, poly2); | ||
* var union = turf.union(turf.featureCollection([poly1, poly2])); | ||
* | ||
@@ -35,7 +34,11 @@ * //addToMap | ||
*/ | ||
function union(poly1, poly2, options) { | ||
if (options === void 0) { options = {}; } | ||
var geom1 = getGeom(poly1); | ||
var geom2 = getGeom(poly2); | ||
var unioned = polygonClipping.union(geom1.coordinates, geom2.coordinates); | ||
function union(features, options = {}) { | ||
const geoms = []; | ||
geomEach(features, (geom) => { | ||
geoms.push(geom.coordinates); | ||
}); | ||
if (geoms.length < 2) { | ||
throw new Error("Must have at least 2 geometries"); | ||
} | ||
const unioned = polygonClipping.union(geoms[0], ...geoms.slice(1)); | ||
if (unioned.length === 0) | ||
@@ -42,0 +45,0 @@ return null; |
@@ -1,8 +0,7 @@ | ||
import { Feature, Polygon, MultiPolygon, Properties } from "@turf/helpers"; | ||
import { FeatureCollection, Feature, Polygon, MultiPolygon, GeoJsonProperties } from "geojson"; | ||
/** | ||
* Takes two {@link (Multi)Polygon(s)} and returns a combined polygon. If the input polygons are not contiguous, this function returns a {@link MultiPolygon} feature. | ||
* 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. | ||
* | ||
* @name union | ||
* @param {Feature<Polygon|MultiPolygon>} polygon1 input Polygon feature | ||
* @param {Feature<Polygon|MultiPolygon>} polygon2 Polygon feature to difference from polygon1 | ||
* @param {Feature<Polygon|MultiPolygon>} polygon1 input Polygon features | ||
* @param {Object} [options={}] Optional Parameters | ||
@@ -27,3 +26,3 @@ * @param {Object} [options.properties={}] Translate Properties to output Feature | ||
* | ||
* var union = turf.union(poly1, poly2); | ||
* var union = turf.union(turf.featureCollection([poly1, poly2])); | ||
* | ||
@@ -33,5 +32,5 @@ * //addToMap | ||
*/ | ||
declare function union<P = Properties>(poly1: Feature<Polygon | MultiPolygon> | Polygon | MultiPolygon, poly2: Feature<Polygon | MultiPolygon> | Polygon | MultiPolygon, options?: { | ||
declare function union<P = GeoJsonProperties>(features: FeatureCollection<Polygon | MultiPolygon>, options?: { | ||
properties?: P; | ||
}): Feature<Polygon | MultiPolygon, P> | null; | ||
export default union; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var polygon_clipping_1 = __importDefault(require("polygon-clipping")); | ||
var invariant_1 = require("@turf/invariant"); | ||
var helpers_1 = require("@turf/helpers"); | ||
const tslib_1 = require("tslib"); | ||
const polygon_clipping_1 = tslib_1.__importDefault(require("polygon-clipping")); | ||
const helpers_1 = require("@turf/helpers"); | ||
const meta_1 = require("@turf/meta"); | ||
/** | ||
* Takes two {@link (Multi)Polygon(s)} and returns a combined polygon. If the input polygons are not contiguous, this function returns a {@link MultiPolygon} feature. | ||
* 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. | ||
* | ||
* @name union | ||
* @param {Feature<Polygon|MultiPolygon>} polygon1 input Polygon feature | ||
* @param {Feature<Polygon|MultiPolygon>} polygon2 Polygon feature to difference from polygon1 | ||
* @param {Feature<Polygon|MultiPolygon>} polygon1 input Polygon features | ||
* @param {Object} [options={}] Optional Parameters | ||
@@ -34,3 +31,3 @@ * @param {Object} [options.properties={}] Translate Properties to output Feature | ||
* | ||
* var union = turf.union(poly1, poly2); | ||
* var union = turf.union(turf.featureCollection([poly1, poly2])); | ||
* | ||
@@ -40,7 +37,11 @@ * //addToMap | ||
*/ | ||
function union(poly1, poly2, options) { | ||
if (options === void 0) { options = {}; } | ||
var geom1 = invariant_1.getGeom(poly1); | ||
var geom2 = invariant_1.getGeom(poly2); | ||
var unioned = polygon_clipping_1.default.union(geom1.coordinates, geom2.coordinates); | ||
function union(features, options = {}) { | ||
const geoms = []; | ||
meta_1.geomEach(features, (geom) => { | ||
geoms.push(geom.coordinates); | ||
}); | ||
if (geoms.length < 2) { | ||
throw new Error("Must have at least 2 geometries"); | ||
} | ||
const unioned = polygon_clipping_1.default.union(geoms[0], ...geoms.slice(1)); | ||
if (unioned.length === 0) | ||
@@ -47,0 +48,0 @@ return null; |
{ | ||
"name": "@turf/union", | ||
"version": "6.5.0", | ||
"version": "7.0.0-alpha.0", | ||
"description": "turf union module", | ||
@@ -45,6 +45,5 @@ "author": "Turf Authors", | ||
"test:tape": "ts-node -r esm test.js", | ||
"test:types": "tsc --esModuleInterop --noEmit types.ts" | ||
"test:types": "tsc --esModuleInterop --noEmit --strict types.ts" | ||
}, | ||
"devDependencies": { | ||
"@turf/combine": "^6.5.0", | ||
"@types/tape": "*", | ||
@@ -62,7 +61,8 @@ "benchmark": "*", | ||
"dependencies": { | ||
"@turf/helpers": "^6.5.0", | ||
"@turf/invariant": "^6.5.0", | ||
"polygon-clipping": "^0.15.3" | ||
"@turf/helpers": "^7.0.0-alpha.0", | ||
"@turf/meta": "^7.0.0-alpha.0", | ||
"polygon-clipping": "^0.15.3", | ||
"tslib": "^2.3.0" | ||
}, | ||
"gitHead": "5375941072b90d489389db22b43bfe809d5e451e" | ||
"gitHead": "0edc4c491b999e5ace770a61e1cf549f7c004189" | ||
} |
@@ -7,13 +7,13 @@ # @turf/union | ||
Takes two [(Multi)Polygon(s)][1] and returns a combined polygon. If the input polygons are not contiguous, this function returns a [MultiPolygon][2] feature. | ||
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. | ||
**Parameters** | ||
### Parameters | ||
- `polygon1` **[Feature][3]<([Polygon][4] \| [MultiPolygon][5])>** input Polygon feature | ||
- `polygon2` **[Feature][3]<([Polygon][4] \| [MultiPolygon][5])>** Polygon feature to difference from polygon1 | ||
- `options` **[Object][6]** Optional Parameters (optional, default `{}`) | ||
- `options.properties` **[Object][6]** Translate Properties to output Feature (optional, default `{}`) | ||
* `polygon1` **[Feature][3]<([Polygon][4] | [MultiPolygon][5])>** input Polygon features | ||
* `options` **[Object][6]** Optional Parameters (optional, default `{}`) | ||
**Examples** | ||
* `options.properties` **[Object][6]** Translate Properties to output Feature (optional, default `{}`) | ||
### Examples | ||
```javascript | ||
@@ -35,3 +35,3 @@ var poly1 = turf.polygon([[ | ||
var union = turf.union(poly1, poly2); | ||
var union = turf.union(turf.featureCollection([poly1, poly2])); | ||
@@ -42,3 +42,3 @@ //addToMap | ||
Returns **[Feature][3]<([Polygon][4] \| [MultiPolygon][5])>** a combined [Polygon][1] or [MultiPolygon][2] feature | ||
Returns **[Feature][3]<([Polygon][4] | [MultiPolygon][5])>** a combined [Polygon][1] or [MultiPolygon][2] feature, or null if the inputs are empty | ||
@@ -45,0 +45,0 @@ [1]: https://tools.ietf.org/html/rfc7946#section-3.1.6 |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
10
135
10213
4
1
+ Added@turf/meta@^7.0.0-alpha.0
+ Addedtslib@^2.3.0
+ Added@turf/helpers@7.2.0(transitive)
+ Added@turf/meta@7.2.0(transitive)
+ Added@types/geojson@7946.0.15(transitive)
+ Addedtslib@2.8.1(transitive)
- Removed@turf/invariant@^6.5.0
- Removed@turf/helpers@6.5.0(transitive)
- Removed@turf/invariant@6.5.0(transitive)
Updated@turf/helpers@^7.0.0-alpha.0