【问题标题】:Line vs. Polygon Intersection Coordinates线和。多边形交点坐标
【发布时间】:2015-02-27 07:32:53
【问题描述】:

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

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

【问题讨论】:

  • 编辑了问题。现在更清楚了吗?
  • 我尝试过使用 shapely 的 'intersection' 函数(geom intersection)并使用 Fiona 编写输出的简单交集。
  • 你能把代码、示例输入、它的输出和预期的输出贴出来。

标签: python coordinates intersection shapely fiona


【解决方案1】:

您需要从多边形的外部和直线的交点处获取。如果您改为使用与多边形的交集,则结果是一条线,因为多边形有一个区域。此外,交叉点可能是一条线,如果它们是平行的,那么您也可以期待 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)

【讨论】:

  • 如果我想将形状除以线串(或多边形内部的交叉段?在这种情况下,如果交叉点不在集合中,shapely.ops.split 将起作用多边形的外坐标
猜你喜欢
  • 1970-01-01
  • 2019-08-02
  • 2011-07-08
  • 2019-12-27
  • 1970-01-01
  • 1970-01-01
  • 2012-07-05
  • 1970-01-01
相关资源
最近更新 更多