直线与多边形交点坐标 [英] Line vs. Polygon Intersection Coordinates

查看:59
本文介绍了直线与多边形交点坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

您需要从多边形和直线的外部获取交点。如果改用与多边形的交点,则结果是一条线,因为多边形有面积。此外,如果交叉点是平行的,则交叉点可以是一条线,因此您还可以期待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)

这篇关于直线与多边形交点坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆