@turf/difference
Advanced tools
Comparing version
@@ -1,13 +0,10 @@ | ||
/// <reference types="geojson" /> | ||
import { Polygon, MultiPolygon, Feature } from '@turf/helpers' | ||
import {Polygon, MultiPolygon, Feature} from '@turf/meta' | ||
type Input = Feature<Polygon|MultiPolygon> | Polygon | MultiPolygon; | ||
type Output = Feature<Polygon|MultiPolygon> | null; | ||
/** | ||
* http://turfjs.org/docs/#difference | ||
*/ | ||
declare function difference(polygon1: Input, polygon2: Input): Output; | ||
declare namespace difference { } | ||
export = difference; | ||
export default function difference( | ||
polygon1: Feature<Polygon | MultiPolygon> | Polygon | MultiPolygon, | ||
polygon2: Feature<Polygon | MultiPolygon> | Polygon | MultiPolygon | ||
): Feature<Polygon | MultiPolygon> | null; | ||
23
index.js
@@ -1,7 +0,6 @@ | ||
// depend on jsts for now https://github.com/bjornharrtell/jsts/blob/master/examples/overlay.html | ||
var jsts = require('jsts'); | ||
var area = require('@turf/area'); | ||
var feature = require('@turf/helpers').feature; | ||
var getGeom = require('@turf/invariant').getGeom; | ||
var flattenEach = require('@turf/meta').flattenEach; | ||
import { GeoJSONReader, GeoJSONWriter, OverlayOp } from 'jsts-es'; | ||
import area from '@turf/area'; | ||
import { feature } from '@turf/helpers'; | ||
import { getGeom } from '@turf/invariant'; | ||
import { flattenEach } from '@turf/meta'; | ||
@@ -42,3 +41,3 @@ /** | ||
*/ | ||
module.exports = function (polygon1, polygon2) { | ||
function difference(polygon1, polygon2) { | ||
var geom1 = getGeom(polygon1); | ||
@@ -55,12 +54,12 @@ var geom2 = getGeom(polygon2); | ||
// JSTS difference operation | ||
var reader = new jsts.io.GeoJSONReader(); | ||
var reader = new GeoJSONReader(); | ||
var a = reader.read(geom1); | ||
var b = reader.read(geom2); | ||
var differenced = a.difference(b); | ||
var differenced = OverlayOp.difference(a, b); | ||
if (differenced.isEmpty()) return null; | ||
var writer = new jsts.io.GeoJSONWriter(); | ||
var writer = new GeoJSONWriter(); | ||
var geom = writer.write(differenced); | ||
return feature(geom, properties); | ||
}; | ||
} | ||
@@ -87,1 +86,3 @@ /** | ||
} | ||
export default difference; |
{ | ||
"name": "@turf/difference", | ||
"version": "4.7.4", | ||
"version": "5.0.0", | ||
"description": "turf difference module", | ||
"main": "index.js", | ||
"main": "main", | ||
"module": "index", | ||
"jsnext:main": "index", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"index.js", | ||
"index.d.ts" | ||
"index.d.ts", | ||
"main.js" | ||
], | ||
"scripts": { | ||
"test": "node test.js", | ||
"bench": "node bench.js" | ||
"pretest": "rollup -c ../../rollup.config.js", | ||
"test": "node -r @std/esm test.js", | ||
"bench": "node -r @std/esm bench.js" | ||
}, | ||
@@ -30,15 +34,21 @@ "repository": { | ||
"devDependencies": { | ||
"benchmark": "^2.1.4", | ||
"glob": "~5.0.5", | ||
"load-json-file": "^2.0.0", | ||
"tape": "^4.6.3", | ||
"write-json-file": "^2.0.0" | ||
"benchmark": "*", | ||
"glob": "*", | ||
"load-json-file": "*", | ||
"rollup": "*", | ||
"tape": "*", | ||
"write-json-file": "*", | ||
"@std/esm": "*" | ||
}, | ||
"dependencies": { | ||
"@turf/area": "^4.7.3", | ||
"@turf/helpers": "^4.7.3", | ||
"@turf/invariant": "^4.7.3", | ||
"@turf/meta": "^4.7.3", | ||
"jsts": "1.3.0" | ||
"@turf/helpers": "5.x", | ||
"@turf/invariant": "5.x", | ||
"@turf/meta": "5.x", | ||
"jsts-es": "*" | ||
}, | ||
"@std/esm": { | ||
"esm": "js", | ||
"cjs": true | ||
} | ||
} |
# @turf/difference | ||
# difference | ||
<!-- Generated by documentation.js. Update this documentation by updating the source code. --> | ||
## difference | ||
Finds the difference between two [polygons](http://geojson.org/geojson-spec.html#polygon) by clipping the second polygon from the first. | ||
@@ -42,3 +44,3 @@ | ||
Returns **([Feature](http://geojson.org/geojson-spec.html#feature-objects)<([Polygon](http://geojson.org/geojson-spec.html#polygon) \| [MultiPolygon](http://geojson.org/geojson-spec.html#multipolygon))> | [null](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/null))** a Polygon or MultiPolygon feature showing the area of `polygon1` excluding the area of `polygon2` (if empty returns `null`) | ||
Returns **([Feature](http://geojson.org/geojson-spec.html#feature-objects)<([Polygon](http://geojson.org/geojson-spec.html#polygon) \| [MultiPolygon](http://geojson.org/geojson-spec.html#multipolygon))> | null)** a Polygon or MultiPolygon feature showing the area of `polygon1` excluding the area of `polygon2` (if empty returns `null`) | ||
@@ -45,0 +47,0 @@ <!-- This file is automatically generated. Please don't edit it directly: |
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
10114
39.89%6
20%169
89.89%70
2.94%7
40%1
Infinity%+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
Updated
Updated
Updated