turf-intersect
Advanced tools
Comparing version 1.3.2 to 1.4.0
66
index.js
@@ -5,22 +5,50 @@ // depend on jsts for now https://github.com/bjornharrtell/jsts/blob/master/examples/overlay.html | ||
/** | ||
* Takes two {@link Polygon} features and finds their intersection. | ||
* | ||
* @module turf/intersect | ||
* @category transformation | ||
* @param {Polygon} poly1 the first Polygon | ||
* @param {Polygon} poly2 the second Polygon | ||
* @return {Polygon} a Polygon feature representing the area where `poly1` and `poly2` overlap | ||
* @example | ||
* var poly1 = turf.polygon([[ | ||
* [-122.801742, 45.48565], | ||
* [-122.801742, 45.60491], | ||
* [-122.584762, 45.60491], | ||
* [-122.584762, 45.48565], | ||
* [-122.801742, 45.48565] | ||
* ]]); | ||
* poly1.properties.fill = '#0f0'; | ||
* var poly2 = turf.polygon([[ | ||
* [-122.520217, 45.535693], | ||
* [-122.64038, 45.553967], | ||
* [-122.720031, 45.526554], | ||
* [-122.669906, 45.507309], | ||
* [-122.723464, 45.446643], | ||
* [-122.532577, 45.408574], | ||
* [-122.487258, 45.477466], | ||
* [-122.520217, 45.535693] | ||
* ]]); | ||
* poly2.properties.fill = '#00f'; | ||
* var polygons = turf.featurecollection([poly1, poly2]); | ||
* | ||
* var intersection = turf.intersect(poly1, poly2); | ||
* | ||
* //=polygons | ||
* | ||
* //=intersection | ||
*/ | ||
module.exports = function(poly1, poly2){ | ||
if(poly1.type !== 'Feature') { | ||
poly1 = { | ||
type: 'Feature', | ||
geometry: poly1 | ||
}; | ||
} | ||
if(poly2.type !== 'Feature') { | ||
poly2 = { | ||
type: 'Feature', | ||
geometry: poly2 | ||
}; | ||
} | ||
var geom1; | ||
if(poly1.type === 'Feature') geom1 = poly1.geometry; | ||
else geom1 = poly1; | ||
if(poly2.type === 'Feature') geom2 = poly2.geometry; | ||
else geom2 = poly2; | ||
var reader = new jsts.io.GeoJSONReader(); | ||
var a = reader.read(JSON.stringify(geom1)); | ||
var b = reader.read(JSON.stringify(geom2)); | ||
var intersection = a.intersection(b); | ||
var parser = new jsts.io.GeoJSONParser(); | ||
var reader = new jsts.io.GeoJSONReader(), | ||
a = reader.read(JSON.stringify(poly1.geometry)), | ||
b = reader.read(JSON.stringify(poly2.geometry)), | ||
intersection = a.intersection(b), | ||
parser = new jsts.io.GeoJSONParser(); | ||
intersection = parser.write(intersection); | ||
@@ -36,2 +64,2 @@ if(intersection.type === 'GeometryCollection' && intersection.geometries.length === 0) { | ||
} | ||
} | ||
}; |
{ | ||
"name": "turf-intersect", | ||
"version": "1.3.2", | ||
"version": "1.4.0", | ||
"description": "find the intersection of spatial features", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "node test/test.js" | ||
"test": "node test/test.js", | ||
"doc": "dox -r < index.js | doxme --readme > README.md" | ||
}, | ||
@@ -26,9 +27,11 @@ "repository": { | ||
"benchmark": "^1.0.0", | ||
"glob": "~4.3.1", | ||
"tape": "~3.0.3" | ||
"glob": "~4.3.5", | ||
"tape": "~3.5.0", | ||
"dox": "^0.6.1", | ||
"doxme": "^1.4.3" | ||
}, | ||
"dependencies": { | ||
"jsts": "~0.15.0", | ||
"turf-featurecollection": "~1.0.0" | ||
"turf-featurecollection": "^1.0.0" | ||
} | ||
} |
@@ -1,35 +0,65 @@ | ||
turf-intersect | ||
=== | ||
# turf-intersect | ||
[![build status](https://secure.travis-ci.org/Turfjs/turf-intersect.png)](http://travis-ci.org/Turfjs/turf-intersect) | ||
Find the intersection of two Polygon Features. | ||
find the intersection of spatial features | ||
##Install | ||
```sh | ||
npm install turf-intersect | ||
``` | ||
### `turf.intersect(poly1, poly2)` | ||
##Parameters | ||
name|description | ||
---|--- | ||
feature1|Geometry or Feature | ||
feature2|Geometry or Feature | ||
Takes two Polygon features and finds their intersection. | ||
##Usage | ||
### Parameters | ||
| parameter | type | description | | ||
| --------- | ------- | ------------------ | | ||
| `poly1` | Polygon | the first Polygon | | ||
| `poly2` | Polygon | the second Polygon | | ||
### Example | ||
```js | ||
intersect(poly1, poly2) | ||
var poly1 = turf.polygon([[ | ||
[-122.801742, 45.48565], | ||
[-122.801742, 45.60491], | ||
[-122.584762, 45.60491], | ||
[-122.584762, 45.48565], | ||
[-122.801742, 45.48565] | ||
]]); | ||
poly1.properties.fill = '#0f0'; | ||
var poly2 = turf.polygon([[ | ||
[-122.520217, 45.535693], | ||
[-122.64038, 45.553967], | ||
[-122.720031, 45.526554], | ||
[-122.669906, 45.507309], | ||
[-122.723464, 45.446643], | ||
[-122.532577, 45.408574], | ||
[-122.487258, 45.477466], | ||
[-122.520217, 45.535693] | ||
]]); | ||
poly2.properties.fill = '#00f'; | ||
var polygons = turf.featurecollection([poly1, poly2]); | ||
var intersection = turf.intersect(poly1, poly2); | ||
//=polygons | ||
//=intersection | ||
``` | ||
###Example | ||
## Installation | ||
```js | ||
var intersect = require('turf-intersect'); | ||
var park = require('park.json'); | ||
var lake = require('lake.json'); | ||
Requires [nodejs](http://nodejs.org/). | ||
var intersection = intersect(park, lake); | ||
console.log(intersection); | ||
```sh | ||
$ npm install turf-intersect | ||
``` | ||
## Tests | ||
```sh | ||
$ npm test | ||
``` | ||
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
15276
489
66
5