I was writing a code to find out whether the coordinates am interested is found inside or outside a rectangle. I found that there is a function "contain_points", which will serve the purpose, equivalent of "inpolygon" in Matlab. I was unable to find any document on implementation or example of this function. Can anyone suggest how this works?
Asked
Active
Viewed 280 times
0
-
check this http://stackoverflow.com/questions/36399381/whats-the-fastest-way-of-checking-if-a-point-is-inside-a-polygon-in-python – itzMEonTV May 17 '17 at 11:51
1 Answers
0
Take a look at shapely library. It is the de facto standard when dealing with 2D polygons in python (and many other languages, since it it a wrapping of GEOS C++ library).
An example of what you want:
from shapely.geometry import Point, Polygon
p = Point(0.0, 0.0)
poly = Polygon([(1, 1), (-1, 1), (-1, -1), (1, -1)])
is_included = poly.contains(p)
is_included
is True
now.

eguaio
- 3,754
- 1
- 24
- 38