https://github.com/turfjs/turf-inside
Checks to see if a point is inside of a polygon.
https://github.com/turfjs/turf-inside
Last synced: 10 months ago
JSON representation
Checks to see if a point is inside of a polygon.
- Host: GitHub
- URL: https://github.com/turfjs/turf-inside
- Owner: Turfjs
- License: mit
- Archived: true
- Created: 2014-04-02T03:16:10.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2019-05-09T16:26:10.000Z (almost 7 years ago)
- Last Synced: 2025-02-20T21:52:15.553Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 28.3 KB
- Stars: 41
- Watchers: 7
- Forks: 9
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DEPRECATED - replaced by [`@turf/boolean-point-in-polygon`](https://www.npmjs.com/package/@turf/boolean-point-in-polygon)
# turf-inside
[](http://travis-ci.org/Turfjs/turf-inside)
turf inside module
### `turf.inside(point, polygon)`
Takes a Point and a Polygon or MultiPolygon and determines if the point resides inside the polygon. The polygon can
be convex or concave. The function accounts for holes.
### Parameters
| parameter | type | description |
| --------- | --------------------------------- | ----------------------------- |
| `point` | Feature\.\ | input point |
| `polygon` | Feature\.\ | input polygon or multipolygon |
### Example
```js
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
```
**Returns** `Boolean`, `true` if the Point is inside the Polygon; `false` if the Point is not inside the Polygon
## Installation
Requires [nodejs](http://nodejs.org/).
```sh
$ npm install turf-inside
```
## Tests
```sh
$ npm test
```