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

2024-04-28 14:58:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个geopandas数据帧,由线串和多线串组成。我想选择那些包含经纬度框(由我定义)内的点的线串和多线串,我没有几何图形。换句话说,我有一些美国地质勘探局的断层图,我想从一些纬度/纬度的一定距离内选取这些断层线的正方形镶嵌图。到目前为止,我已经成功地从整个数据帧中展开坐标,并且只保存位于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数据帧进行此操作,是否有任何直觉?提前谢谢


Tags: and数据infor定义经纬度geopandasappend
1条回答
网友
1楼 · 发布于 2024-04-28 14:58:46

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]

相关问题 更多 >