[英]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.