gpt4 book ai didi

python - 线与多边形交点坐标

转载 作者:行者123 更新时间:2023-11-30 23:16:31 32 4
gpt4 key购买 nike

我正在使用 Python、Shapely 和 Fiona。考虑到有两个可用的形状文件,一个是线形状文件,一个是多边形形状文件。

如何获取由交点(用 Q 标记表示)及其各自坐标组成的最终结果 shapefile?

enter image description here

最佳答案

您需要获取多边形外部与直线的交点。如果您改为使用与多边形的交集,则结果是一条线,因为多边形有一个面积。另外,如果它们是平行的,交集可能是一条线,所以你也可以期待一个 GeometryCollection

这是一个开始:

from shapely.wkt import loads

poly = loads('POLYGON ((140 270, 300 270, 350 200, 300 150, 140 150, 100 200, 140 270))')
line = loads('LINESTRING (370 290, 270 120)')

intersection = poly.exterior.intersection(line)

if intersection.is_empty:
print("shapes don't intersect")
elif intersection.geom_type.startswith('Multi') or intersection.geom_type == 'GeometryCollection':
for shp in intersection:
print(shp)
else:
print(intersection)

关于python - 线与多边形交点坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27717248/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com