【问题标题】:Distance Between Linestring Geopandas线串地理熊猫之间的距离
【发布时间】:2018-06-06 21:50:58
【问题描述】:

我有一个 shapefile 数据集。有些道路(线)名称相同,但位于不同的地方,并不相连。

这是我的 geopandas 数据文件中同名道路的图片:

我希望能够测量道​​路块(线串)之间的距离,以便能够在距离高于阈值时重命名道路,这样每条道路都有自己唯一的名称。

因此,您知道如何找到线串之间的距离吗?

【问题讨论】:

  • line1.distance(line2)

标签: python python-3.x geopandas multilinestring


【解决方案1】:

在 geopandas 中,几何图形是有形状的物体。要获得任意两个匀称物体之间的距离,您可以使用巧妙命名的 distance 方法:

from shapely.geometry import Point, LineString
import geopandas

line1 = LineString([
    Point(0, 0),
    Point(0, 1),
    Point(1, 1),
    Point(1, 2),
    Point(3, 3),
    Point(5, 6),
])

line2 = LineString([
    Point(5, 3),
    Point(5, 5),
    Point(9, 5),
    Point(10, 7),
    Point(11, 8),
    Point(12, 12),
])

line3 = LineString([
    Point(9, 10),
    Point(10, 14),
    Point(11, 12),
    Point(12, 15),
])

print(line1.distance(line2))
> 0.5547001962252291

如果你有一个 geopandas GeoSeries/GeoDataFrame,你需要更聪明一点。

gs = geopandas.GeoSeries([line1, line2, line3])
gs.distance(gs)

返回全零,因为它在索引上排列 gsgs,这是所有相同的几何图形。

但是:

gs.distance(gs.shift())

为您提供从 line1 到 line2 以及 line2 到 line3 的距离:

0         NaN
1    0.554700
2    0.948683
dtype: float64

【讨论】:

  • 哇!非常感谢 !!这是一个很好的答案。
猜你喜欢
  • 2017-08-11
  • 2022-12-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-14
相关资源
最近更新 更多