【问题标题】:Check if the point within a polygon (speed up)检查多边形内的点(加速)
【发布时间】:2020-04-07 19:12:55
【问题描述】:

我有 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

【问题讨论】:

  • Yr q v 简洁。数据在哪里?

标签: python pandas numpy geopandas


【解决方案1】:
city_point[city_point.geometry.within(border_gdf.iloc[0].geometry)]

【讨论】:

    猜你喜欢
    • 2015-02-19
    • 2014-04-26
    • 1970-01-01
    • 1970-01-01
    • 2014-10-10
    • 2011-06-17
    • 1970-01-01
    相关资源
    最近更新 更多