简体   繁体   English

线与多边形相交坐标

[英]Line vs. Polygon Intersection Coordinates

I am working with Python, Shapely and Fiona. 我正在使用Python,Shapely和Fiona。 Considering there are two shapefiles available, a line shapefile and a polygon shapefile. 考虑到有两个shapefile,一个线shapefile和一个多边形shapefile。

How to obtain an end result shapefile consisting of points of intersection (indicated with Q-marks) and their respective coordinates?? 如何获得由交点(用Q标记表示)及其相应坐标组成的最终结果shapefile?

在此处输入图片说明

You need to get the intersection from the exterior of the polygon and the line. 您需要从多边形和直线的外部获取交点。 If you instead use the intersection with the polygon, the result is a line, since polygons have an area. 如果改用相交点与多边形,则结果是一条线,因为多边形具有面积。 Also, the intersection may be a line, if they are parallel, so you could also expect a GeometryCollection 此外,如果相交是平行的,则相交可能是一条线,因此您也可以期望使用GeometryCollection

Here is something as a start: 这是一个开始:

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