Reputation: 772
I have 2 data frames. 1) data - long and lat points 2) border = shapefile of a city
I need to check which points are within the shapefile and save them. Here is my code to do that:
city = pd.read_csv("D:...path.../data.csv")
crs = {'init':'epsg:4326'}
geometry = [Point(xy) for xy in zip(city.longitude,city.latitude)]
city_point = gpd.GeoDataFrame(city,crs=crs,geometry=geometry)
border = gpd.read_file("C:...path.../border.shp")
border_gdf = gpd.GeoDataFrame(border, geometry='geometry')
city_point['inside'] = city_point['geometry'].apply(border_gdf.contains)
city_point = city_point[city_point.inside != True]
import numpy as np
import pandas as pd
import geopandas as gpd
from shapely.geometry import Point, Polygon
Upvotes: 0
Views: 146
Reputation: 757
city_point[city_point.geometry.within(border_gdf.iloc[0].geometry)]
Upvotes: 1