在geopandas中找到线串的X和Y
我在任何地方都找不到它,所以希望我在这里不会太多。
我有一个polyline shapefile,我正在尝试将“开始和结束”作为新列提取,并且似乎找不到如何使用地理杂货店来做到这一点。
我想最终获得四个新列,startx,starty,endx,Endy,
有人会知道如何获得这个吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个 mre 使用100个随机线链接的
数据帧看起来像这样:
您可以使用
gdf.boundary
将Linestring的边界作为多点:然后可以是结合,它将将任何多部分几何形状转换为单个行,然后
unstack
生成的额外索引组以创建新列,0
和1 < /代码>,用于起点和结尾点。每列将包含
shapely.deometry.point
对象:最后,我们可以直接抓住
x
和y
值直接的值:这给出了您正在寻找的最终结果:
Here's a MRE with 100 random-length linestrings
The dataframe looks like this:
You can use
gdf.boundary
to get the bounds of the LineString as a MultiPoint:This can then be combined with
explode()
, which will convert any multi-part geometry into individual rows, thenunstack
the resulting extra index groups to create new columns,0
and1
, for the starting and ending points. Each column will containshapely.geometry.Point
objects:Finally, we can grab the
x
andy
values for these points directly:This gives the final result you were looking for: