I am working with shapefiles and DataFrames that contain longitude and latitude coordinates. What I want to do is see if the coordinates within the DataFrames fall outside of the shapefile polygons and select those to a new DataFrame. I converted the DataFrame latitude and longitude column values into Point
values using shapely
first and then converted the shapefile latitude and longitude values into a Polygon
using shapely
(I had earlier in my code had to convert the shapely
file coordinates into separate DataFrame columns for latitude and longitude). Here's some of the code I'm working with:
point_coords['geometry'] = [Point(xy) for xy in zip(point_coords.lon, point_coords.lat)] #converting the latitude and longitude coordinates into points
point_geom = point_coords['geometry']
point_geom = pd.DataFrame(point_geom)
shape_coords = coords[['lat','lon']]
shape_coords = shape_coords.values.tolist()
poly = Polygon(shape_coords)
coord_contain = poly.contains(point_geom)
I tried using the contians
method from shapely
but that didn't work, giving the following error: AttributeError: 'DataFrame' object has no attribute '_geom'
.
What is the best possible method to determine which point_geom
coordinates fall inside/outside of the poly
?