检查多边形内的点(加速)

Check if the point within a polygon (speed up)

我有2个数据框。 1) 数据 - 经度和纬度点 2) border = 一个城市的 shapefile


我需要检查 shapefile 中有哪些点并保存它们。这是我的代码:

数据

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
city_point[city_point.geometry.within(border_gdf.iloc[0].geometry)]