@turf/union
Advanced tools
Comparing version 5.1.5 to 6.0.0
45
index.js
@@ -1,8 +0,14 @@ | ||
import { GeoJSONReader, GeoJSONWriter, UnionOp } from 'turf-jsts'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var martinez = require("martinez-polygon-clipping"); | ||
var invariant_1 = require("@turf/invariant"); | ||
var helpers_1 = require("@turf/helpers"); | ||
/** | ||
* Takes two or more {@link Polygon|polygons} and returns a combined polygon. If the input polygons are not contiguous, this function returns a {@link MultiPolygon} feature. | ||
* 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. | ||
* | ||
* @name union | ||
* @param {...Feature<Polygon>} A polygon to combine | ||
* @param {Feature<Polygon|MultiPolygon>} polygon1 input Polygon feature | ||
* @param {Feature<Polygon|MultiPolygon>} polygon2 Polygon feature to difference from polygon1 | ||
* @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 | ||
@@ -30,20 +36,15 @@ * @example | ||
*/ | ||
function union() { | ||
var reader = new GeoJSONReader(); | ||
var result = reader.read(JSON.stringify(arguments[0].geometry)); | ||
for (var i = 1; i < arguments.length; i++) { | ||
result = UnionOp.union(result, reader.read(JSON.stringify(arguments[i].geometry))); | ||
} | ||
var writer = new GeoJSONWriter(); | ||
result = writer.write(result); | ||
return { | ||
type: 'Feature', | ||
geometry: result, | ||
properties: arguments[0].properties | ||
}; | ||
function union(polygon1, polygon2, options) { | ||
if (options === void 0) { options = {}; } | ||
var coords1 = invariant_1.getGeom(polygon1).coordinates; | ||
var coords2 = invariant_1.getGeom(polygon2).coordinates; | ||
var unioned = martinez.union(coords1, coords2); | ||
console.log(unioned); | ||
if (unioned.length === 0) | ||
return null; | ||
if (unioned.length === 1) | ||
return helpers_1.polygon(unioned[0], options.properties); | ||
else | ||
return helpers_1.multiPolygon(unioned, options.properties); | ||
} | ||
export default union; | ||
exports.default = union; |
{ | ||
"name": "@turf/union", | ||
"version": "5.1.5", | ||
"version": "6.0.0", | ||
"description": "turf union module", | ||
"main": "main.js", | ||
"module": "main.es.js", | ||
"types": "index.d.ts", | ||
"main": "index", | ||
"files": [ | ||
"index.js", | ||
"index.d.ts", | ||
"main.js", | ||
"main.es.js" | ||
"index.ts" | ||
], | ||
"scripts": { | ||
"pretest": "rollup -c ../../rollup.config.js", | ||
"test": "node -r @std/esm test.js", | ||
"posttest": "node -r @std/esm ../../scripts/validate-es5-dependencies.js", | ||
"bench": "node -r @std/esm bench.js", | ||
"pretest": "tsc", | ||
"test": "node test.js", | ||
"bench": "node bench.js", | ||
"docs": "node ../../scripts/generate-readmes" | ||
@@ -36,18 +31,15 @@ }, | ||
"devDependencies": { | ||
"@std/esm": "*", | ||
"benchmark": "*", | ||
"glob": "*", | ||
"load-json-file": "*", | ||
"rollup": "*", | ||
"typescript": "*", | ||
"tape": "*", | ||
"write-json-file": "*" | ||
"write-json-file": "*", | ||
"@turf/combine": "*" | ||
}, | ||
"dependencies": { | ||
"@turf/helpers": "^5.1.5", | ||
"turf-jsts": "*" | ||
}, | ||
"@std/esm": { | ||
"esm": "js", | ||
"cjs": true | ||
"@turf/helpers": "6.x", | ||
"@turf/invariant": "6.x", | ||
"martinez-polygon-clipping": "*" | ||
} | ||
} |
@@ -7,7 +7,8 @@ # @turf/union | ||
Takes two or more [polygons](https://tools.ietf.org/html/rfc7946#section-3.1.6) and returns a combined polygon. If the input polygons are not contiguous, this function returns a [MultiPolygon](https://tools.ietf.org/html/rfc7946#section-3.1.7) feature. | ||
Takes two or more [(Multi)Polygon(s)](https://tools.ietf.org/html/rfc7946#section-3.1.6) and returns a combined polygon. If the input polygons are not contiguous, this function returns a [MultiPolygon](https://tools.ietf.org/html/rfc7946#section-3.1.7) feature. | ||
**Parameters** | ||
- `A` **...[Feature](https://tools.ietf.org/html/rfc7946#section-3.2)<[Polygon](https://tools.ietf.org/html/rfc7946#section-3.1.6)>** polygon to combine | ||
- `polygon1` **[Feature](https://tools.ietf.org/html/rfc7946#section-3.2)<([Polygon](https://tools.ietf.org/html/rfc7946#section-3.1.6) \| [MultiPolygon](https://tools.ietf.org/html/rfc7946#section-3.1.7))>** input Polygon feature | ||
- `polygon2` **[Feature](https://tools.ietf.org/html/rfc7946#section-3.2)<([Polygon](https://tools.ietf.org/html/rfc7946#section-3.1.6) \| [MultiPolygon](https://tools.ietf.org/html/rfc7946#section-3.1.7))>** Polygon feature to difference from polygon1 | ||
@@ -14,0 +15,0 @@ **Examples** |
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
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
64
8284
3
5
96
1
+ Added@turf/invariant@6.x
+ Addedmartinez-polygon-clipping@*
+ Added@turf/helpers@6.5.0(transitive)
+ Added@turf/invariant@6.5.0(transitive)
+ Addedmartinez-polygon-clipping@0.7.4(transitive)
+ Addedrobust-predicates@2.0.4(transitive)
+ Addedsplaytree@0.1.4(transitive)
+ Addedtinyqueue@1.2.3(transitive)
- Removedturf-jsts@*
- Removed@turf/helpers@5.1.5(transitive)
- Removedturf-jsts@1.2.3(transitive)
Updated@turf/helpers@6.x