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

时间:2019-12-14 17:58:55

标签: python pandas numpy geopandas

我有2个数据帧。 1)数据-长点和纬度点2)边界=城市的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

1 个答案:

答案 0 :(得分:0)

city_point[city_point.geometry.within(border_gdf.iloc[0].geometry)]