Geopandas Polygon 和 Shapely LineString 之间的交集

Intersection between Geopandas Polygon and Shapely LineString

假设我们有以下方形作为 Geopandas DataFrame

import geopandas as gpd
from shapely.geometry import LineString, LinearRing, Point, Polygon

polygon_geom = Polygon(zip([0,1,1,0], [0,0,1,1]))
crs = {'init': 'epsg:4326'}
polygon = gpd.GeoDataFrame(index=[0], crs=crs, geometry=[polygon_geom])

Note: The polygon I'm working with is a shape file imported to Geopandas, and for the sake of example I have created a geopanda dataframe for the polygon.

我有另一个使用 Shapely 的 LineString

Point1 = Point(0,1)
Point2 = Point(2,0)
line = LineString([Point1,Point2])

我需要找到 polygonline 之间的交点。预期结果为 (1,0)(1,0.5)

两点

我已经尝试过交集方法但没有成功。非常感谢您的支持和提示。

在您的特定情况下,您可以获得多边形的几何形状:-

poly = polygon.geometry.values[0]

这会检查 linepoly 是否相交:-

line.intersects(poly)

它returns True。 所以我们继续:-

line.intersection(poly).xy

并得到

(数组('d', [0.0, 1.0]), 数组('d', [1.0, 0.5]))

作为结果。