在 GeoPandas 中,select(行字符串)用户定义的纬度经度框中的数据

in GeoPandas, select (line string) data within a latitude longitude box defined by user

我有一个由 LineStrings 和 MultiLineStrings 组合而成的 geopandas 数据框。我想 select 那些 LineStrings 和 MultiLineStrings 包含一个点在纬度经度的框(由我定义)内,我没有几何。换句话说,我有一些映射的 USGS 断层痕迹,我想在距某些 lat/lons 一定距离内选择这些断层线的方形插图。到目前为止,我已经取得了一些成功,仅展开整个数据框中的坐标,并且仅保存落在 lat/lon 框内的点,但随后我不再将原始几何图形或信息保存在数据框中。 (即像这样:)

xvals=[]
yvals=[]
for flt in qfaults['geometry']:
    for coord in flt.coords:
       if coord[1] >= centroid[1]-1 and coord[1] <= centroid[1]+1 and coord[0]<=centroid[0]+1 and coord[0]>=centroid[0]-1:
           xvals.append(coord[0])
           yvals.append(coord[1])

对于如何使用 GeoPandas 数据框执行此操作有任何直觉吗?提前致谢。

GeoPandas 有 .cx 索引器,其工作原理与此完全相同。参见 https://geopandas.readthedocs.io/en/latest/docs/user_guide/indexing.html

语法是gdf.cx[xmin:xmax, ymin:ymax]

world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))
southern_world = world.cx[:, :0]
western_world = world.cx[:0, :]
western_europe = world.cx[1:10, 40:60]