turf-inside
Advanced tools
Comparing version 1.1.3 to 1.1.4
59
index.js
@@ -5,2 +5,61 @@ // http://en.wikipedia.org/wiki/Even%E2%80%93odd_rule | ||
/** | ||
* Takes a {@link Point} feature and a {@link Polygon} feature and determines if the Point resides inside the Polygon. The Polygon can | ||
* be convex or concave. The function accepts any valid Polygon or {@link MultiPolygon} | ||
* and accounts for holes. | ||
* | ||
* @module turf/inside | ||
* @category joins | ||
* @param {Point} point a Point feature | ||
* @param {Polygon} polygon a Polygon feature | ||
* @return {Boolean} `true` if the Point is inside the Polygon; `false` if the Point is not inside the Polygon | ||
* @example | ||
* var pt1 = { | ||
* "type": "Feature", | ||
* "properties": { | ||
* "marker-color": "#f00" | ||
* }, | ||
* "geometry": { | ||
* "type": "Point", | ||
* "coordinates": [-111.467285, 40.75766] | ||
* } | ||
* }; | ||
* var pt2 = { | ||
* "type": "Feature", | ||
* "properties": { | ||
* "marker-color": "#0f0" | ||
* }, | ||
* "geometry": { | ||
* "type": "Point", | ||
* "coordinates": [-111.873779, 40.647303] | ||
* } | ||
* }; | ||
* var poly = { | ||
* "type": "Feature", | ||
* "properties": {}, | ||
* "geometry": { | ||
* "type": "Polygon", | ||
* "coordinates": [[ | ||
* [-112.074279, 40.52215], | ||
* [-112.074279, 40.853293], | ||
* [-111.610107, 40.853293], | ||
* [-111.610107, 40.52215], | ||
* [-112.074279, 40.52215] | ||
* ]] | ||
* } | ||
* }; | ||
* | ||
* var features = { | ||
* "type": "FeatureCollection", | ||
* "features": [pt1, pt2, poly] | ||
* }; | ||
* | ||
* //=features | ||
* | ||
* var isInside1 = turf.inside(pt1, poly); | ||
* //=isInside1 | ||
* | ||
* var isInside2 = turf.inside(pt2, poly); | ||
* //=isInside2 | ||
*/ | ||
module.exports = function(point, polygon) { | ||
@@ -7,0 +66,0 @@ var polys = polygon.geometry.coordinates; |
{ | ||
"name": "turf-inside", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"description": "turf inside module", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "tape test.js" | ||
"test": "tape test.js", | ||
"doc": "dox -r < index.js | doxme --readme > README.md" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/morganherlocker/turf-inside.git" | ||
"url": "https://github.com/Turfjs/turf-inside.git" | ||
}, | ||
@@ -24,5 +25,5 @@ "keywords": [ | ||
"bugs": { | ||
"url": "https://github.com/morganherlocker/turf-inside/issues" | ||
"url": "https://github.com/Turfjs/turf-inside/issues" | ||
}, | ||
"homepage": "https://github.com/morganherlocker/turf-inside", | ||
"homepage": "https://github.com/Turfjs/turf-inside", | ||
"bin": {}, | ||
@@ -34,6 +35,8 @@ "dependencies": { | ||
"benchmark": "^1.0.0", | ||
"tape": "^3.0.3", | ||
"turf-point": "^1.2.0", | ||
"turf-polygon": "^0.1.1" | ||
"tape": "^3.5.0", | ||
"turf-point": "^2.0.0", | ||
"turf-polygon": "^1.0.2", | ||
"dox": "^0.6.1", | ||
"doxme": "^1.4.3" | ||
} | ||
} |
@@ -1,39 +0,59 @@ | ||
turf-inside | ||
=========== | ||
[![Build Status](https://travis-ci.org/Turfjs/turf-inside.svg)](https://travis-ci.org/Turfjs/turf-inside) | ||
# turf-inside | ||
Checks to see if a point is inside of a polygon. The polygon can be convex or concave. The function accepts any valid polygon or multipolygon and accounts for holes. | ||
[![build status](https://secure.travis-ci.org/Turfjs/turf-inside.png)](http://travis-ci.org/Turfjs/turf-inside) | ||
###Install | ||
turf inside module | ||
```sh | ||
npm install turf-inside | ||
``` | ||
###Parameters | ||
### `turf.inside(point, polygon)` | ||
|name|description| | ||
|---|---| | ||
|point|A Point Feature| | ||
|polygon|A Polygon or MultiPolygon Feature| | ||
Checks to see if a Point is inside of a Polygon. The Polygon can | ||
be convex or concave. The function accepts any valid Polygon or MultiPolygon | ||
and accounts for holes. | ||
###Usage | ||
### Parameters | ||
| parameter | type | description | | ||
| --------- | ------- | ----------------- | | ||
| `point` | Point | a Point feature | | ||
| `polygon` | Polygon | a Polygon feature | | ||
### Example | ||
```js | ||
inside(pt, poly) | ||
var pt1 = turf.point([-111.467285, 40.75766], {'marker-color': "#f00"}); | ||
var pt2 = turf.point([-111.873779, 40.647303], {'marker-color': "#0f0" }); | ||
var poly = turf.polygon([[ | ||
[-112.074279, 40.52215], | ||
[-112.074279, 40.853293], | ||
[-111.610107, 40.853293], | ||
[-111.610107, 40.52215], | ||
[-112.074279, 40.52215] | ||
]]); | ||
var features = turf.featurecollection([pt1, pt2, poly]); | ||
//=features | ||
var isInside1 = turf.inside(pt1, poly); | ||
//=isInside1 | ||
var isInside2 = turf.inside(pt2, poly); | ||
//=isInside2 | ||
``` | ||
###Example | ||
## Installation | ||
```js | ||
var inside = require('turf-inside') | ||
var point = require('turf-point') | ||
var polygon = require('turf-polygon') | ||
Requires [nodejs](http://nodejs.org/). | ||
var poly = polygon([[[0,0], [50, 50], [0,100], [100,100], [100,0]]]) | ||
var pt = point(75, 75) | ||
```sh | ||
$ npm install turf-inside | ||
``` | ||
var isInside = inside(pt, poly) | ||
## Tests | ||
console.log(isInside) // true | ||
``` | ||
```sh | ||
$ npm test | ||
``` | ||
30
test.js
@@ -9,5 +9,5 @@ var test = require('tape'); | ||
// test for a simple polygon | ||
var poly = polygon([[[0,0], [0,100], [100,100], [100,0]]]); | ||
var ptIn = point(50, 50); | ||
var ptOut = point(140, 150); | ||
var poly = polygon([[[0,0], [0,100], [100,100], [100,0], [0,0]]]); | ||
var ptIn = point([50, 50]); | ||
var ptOut = point([140, 150]); | ||
@@ -18,5 +18,5 @@ t.true(inside(ptIn, poly), 'point inside simple polygon'); | ||
// test for a concave polygon | ||
var concavePoly = polygon([[[0,0], [50, 50], [0,100], [100,100], [100,0]]]); | ||
var ptConcaveIn = point(75, 75); | ||
var ptConcaveOut = point(25, 50); | ||
var concavePoly = polygon([[[0,0], [50, 50], [0,100], [100,100], [100,0], [0,0]]]); | ||
var ptConcaveIn = point([75, 75]); | ||
var ptConcaveOut = point([25, 50]); | ||
@@ -30,6 +30,6 @@ t.true(inside(ptConcaveIn, concavePoly), 'point inside concave polygon'); | ||
test('poly with hole', function (t) { | ||
var ptInHole = point(-86.69208526611328, 36.20373274711739); | ||
var ptInPoly = point(-86.72229766845702, 36.20258997094334); | ||
var ptOutsidePoly = point(-86.75079345703125, 36.18527313913089); | ||
var polyHole = JSON.parse(fs.readFileSync('./fixtures/poly-with-hole.geojson')); | ||
var ptInHole = point([-86.69208526611328, 36.20373274711739]); | ||
var ptInPoly = point([-86.72229766845702, 36.20258997094334]); | ||
var ptOutsidePoly = point([-86.75079345703125, 36.18527313913089]); | ||
var polyHole = JSON.parse(fs.readFileSync(__dirname + '/fixtures/poly-with-hole.geojson')); | ||
@@ -44,7 +44,7 @@ t.false(inside(ptInHole, polyHole)); | ||
test('multipolygon with hole', function (t) { | ||
var ptInHole = point(-86.69208526611328, 36.20373274711739); | ||
var ptInPoly = point(-86.72229766845702, 36.20258997094334); | ||
var ptInPoly2 = point(-86.75079345703125, 36.18527313913089); | ||
var ptOutsidePoly = point(-86.75302505493164, 36.23015046460186); | ||
var multiPolyHole = JSON.parse(fs.readFileSync('./fixtures/multipoly-with-hole.geojson')); | ||
var ptInHole = point([-86.69208526611328, 36.20373274711739]); | ||
var ptInPoly = point([-86.72229766845702, 36.20258997094334]); | ||
var ptInPoly2 = point([-86.75079345703125, 36.18527313913089]); | ||
var ptOutsidePoly = point([-86.75302505493164, 36.23015046460186]); | ||
var multiPolyHole = JSON.parse(fs.readFileSync(__dirname + '/fixtures/multipoly-with-hole.geojson')); | ||
@@ -51,0 +51,0 @@ t.false(inside(ptInHole, multiPolyHole)); |
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
12803
178
60
6