繁体   English   中英

线与多边形相交坐标

[英]Line vs. Polygon Intersection Coordinates

我正在使用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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM