I am trying to address the following issue. Let's assume a dataframe (loaded from a txt file) with the following structure (and thousands of rows):
foo.head()
X Y Z 0 125417.5112 536361.8752 -1750.0 1 127517.7647 533925.8644 -1750.0 2 128144.1000 533199.4000 -1750.0 3 128578.8385 532904.9288 -1750.0 4 125417.5112 536361.8752 -1750.0 ....
The data represents X Y and Z coordinates.
I also have a set of points that define a closed polygon. These are in a numpy array:
polypoints
array([[ 125417.5112, 536361.8752],
[ 127517.7647, 533925.8644],
[ 128144.1 , 533199.4 ],
....
[ 125417.5112, 536361.8752]])
How can i filter my dataframe to drop the rows that do NOT fall inside the closed polygon?
I have tried defining the polygon using shapely.geometry
polygon
. By doing:
poly = Polygon(polypoints)
This works fine. But I am at a loss as to how to continue with this.
Help is much appreciated
----EDIT---- Please see below for updated solution