作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Linestring1 = LINESTRING (51.2176008 4.4177154, 51.21758 4.4178548, **51.2175729 4.4179023**, *51.21745162000732 4.41871738126533*)
Linestring2 = LINESTRING (*51.21745162000732 4.41871738126533*, **51.2174025 4.4190475**, 51.217338 4.4194807, 51.2172511 4.4200562, 51.2172411 4.4201077, 51.2172246 4.4201654, 51.2172067 4.420205, 51.2171806 4.4202355, 51.2171074 4.4202929, 51.2170063 4.4203409, 51.2169564 4.4203641, 51.2168076 4.4204243, 51.2166588 4.4204833, 51.2159018 4.420431, 51.2154117 4.4203843)
最佳答案
获取 LineString
的端点,你只需要访问它的 boundary
属性(property):
from shapely.geometry import LineString
line = LineString([(0, 0), (1, 1), (2, 2)])
endpoints = line.boundary
print(endpoints)
# MULTIPOINT (0 0, 2 2)
first, last = line.boundary
print(first, last)
# POINT (0 0) POINT (2 2)
coords
中获取第一个和最后一个点。坐标序列:
from shapely.geometry import Point
first = Point(line.coords[0])
last = Point(line.coords[-1])
print(first, last)
# POINT (0 0) POINT (2 2)
LineString
对象首先使用相同的
coords
属性(property):
from shapely.wkt import loads
first_line = loads("LINESTRING (51.2176008 4.4177154, 51.21758 4.4178548, 51.2175729 4.4179023, 51.21745162000732 4.41871738126533)")
second_line = loads("LINESTRING (51.21745162000732 4.41871738126533, 51.2174025 4.4190475, 51.217338 4.4194807, 51.2172511 4.4200562, 51.2172411 4.4201077, 51.2172246 4.4201654, 51.2172067 4.420205, 51.2171806 4.4202355, 51.2171074 4.4202929, 51.2170063 4.4203409, 51.2169564 4.4203641, 51.2168076 4.4204243, 51.2166588 4.4204833, 51.2159018 4.420431, 51.2154117 4.4203843)")
first_line = LineString(first_line.coords[:-1])
second_line = LineString(second_line.coords[1:])
print(first_line.boundary[1], second_line.boundary[0])
# POINT (51.2175729 4.4179023) POINT (51.2174025 4.4190475)
关于python - 如何在Shapely中获取LineString的端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61819120/
我是一名优秀的程序员,十分优秀!