Algorithm for determining whether a point is inside a polygon. Normally calculated by counting the number of polygon line segments that a ray from the point intersects.
Questions tagged [point-in-polygon]
275 questions
601
votes
42 answers
How can I determine whether a 2D Point is within a Polygon?
I'm trying to create a fast 2D point inside polygon algorithm, for use in hit-testing (e.g. Polygon.contains(p:Point)). Suggestions for effective techniques would be appreciated.

Scott Evernden
- 39,136
- 15
- 78
- 84
64
votes
6 answers
SciPy Create 2D Polygon Mask
I need to create a numpy 2D array which represents a binary mask of a polygon, using standard Python packages.
input: polygon vertices, image dimensions
output: binary mask of polygon (numpy 2D array)
(Larger context: I want to get the distance…

Isaac Sutherland
- 3,082
- 4
- 28
- 37
62
votes
4 answers
Check if geo-point is inside or outside of polygon
I am using python and I have defined the latitudes and longitudes (in degrees) of a polygon on the map.
My goal is to check if a generic point P of coordinates x,y falls within such polygon. I would like therefore to have a function that allows me…

Federico Gentile
- 5,650
- 10
- 47
- 102
33
votes
6 answers
How to draw a n sided regular polygon in cartesian coordinates?
I have been trying to figure out how to write a simple program to compute the x,y points for creating a regular polygon of n sides. Can someone give me some code examples that don't use preexisting functions that draw polygons? I want to understand…

alphablender
- 2,168
- 5
- 27
- 42
33
votes
1 answer
geopandas point in polygon
I have a GeoDataFrame of polygons (~30) and a GeoDataFrame of Points (~10k)
I'm looking to create 30 new columns (with appropriate polygon names) in my GeoDataFrame of Points with a simple boolean True/False if the point is present in the…

Kvothe
- 1,341
- 7
- 20
- 33
31
votes
8 answers
Find Point in polygon PHP
i have a typical question with the Geometric datatype of mysql, polygon.
I have the polygon data, in the form of an array of latitudes and longitudes, ex:
[["x":37.628134, "y":-77.458334],
["x":37.629867, "y":-77.449021],
["x":37.62324, …

shasi kanth
- 6,987
- 24
- 106
- 158
31
votes
3 answers
Determine if a point reside inside a leaflet polygon
Suppose I Draw a polygan using leaflet like in the follow demo:
http://leaflet.github.io/Leaflet.draw/
My question is how I can determine if a given point reside inside the polygon or not.

Majdi Taleb
- 731
- 3
- 9
- 26
30
votes
3 answers
Is it possible to determine if a GeoJSON point is inside a GeoJSON polygon using JavasScript?
Is it possible to determine whether a GeoJSON point at a given lat,lon lies within a given GeoJSON polygon using only JavaScript (either through d3, topojson, or any other way)?
For example, I can draw a map showing countries in the UK based on the…

user5325596
- 2,310
- 4
- 25
- 42
17
votes
2 answers
Check if point is in spatial object which consists of multiple polygons/holes
I have a SpatialPolygonsDataFrame with 11589 objects of class "polygons". 10699 of those objects consists of exactly 1 polygon, however the rest of those objects consists of multiple polygons (2 to 22).
If an object of consists of multiple…

majom
- 7,863
- 7
- 55
- 88
15
votes
7 answers
Polygon Touch detection Google Map API V2
I'm trying to figure out how best to do this, I have a map with one Polygon drawn on it. Since it doesn't seem as though the Google Maps API V2 has a touch detection on a Polygon. I was wonder if it is possible to detect whether the touch point is…

Dwill
- 506
- 1
- 5
- 22
14
votes
7 answers
MySQL implementation of ray-casting Algorithm?
We need to figure out a quick and fairly accurate method for point-in-polygon for lat/long values and polygons over google maps. After some research - came across some posts about mysql geometric extensions, and did implement that too -
SELECT id,…

zarun
- 910
- 9
- 26
13
votes
3 answers
Extend MySQL implementation of PiP Algorithm?
I need to make a point in polygon MySQL query.
I already found these two great solutions:
http://forums.mysql.com/read.php?23,286574,286574
MySQL implementation of ray-casting Algorithm?
But these functions can only check if one point is inside a…

Mike
- 5,416
- 4
- 40
- 73
12
votes
1 answer
Mysql function MBRContains is not accurate
I have the following POLYGON (in the image you can see the area it covers)
POLYGON((-74.05100448502202 4.7239278424321,-74.05092938316898 4.7241416902206,-74.04830618275201 4.7237460717602,-74.04643668306903 4.7234306460692,-74.04635688735101…

Oscar Gallardo
- 2,240
- 3
- 27
- 47
12
votes
1 answer
Finding largest inscribed rectangle of a polygon with Shapely
I am trying to locate millions of points inside a half-dozen polygons. Here's my code:
def find_shape(longitude,latitude):
if longitude != 0 and latitude != 0:
point = shapely.geometry.Point(longitude,latitude)
else:
return…

Martin Burch
- 2,726
- 4
- 31
- 59
12
votes
1 answer
Node.js/Javascript library to test if point is in geojson multipolygon
Is there some library for node.js or javascript in general that provides a function to check if a coordinate is in a geojson multipolygon?
I'm trying to create a small HTTP API that tells me which multipolygons (representing countries, counties,…

Van Coding
- 24,244
- 24
- 88
- 132