geopandas.GeoSeries.project#
- GeoSeries.project(other, normalized=False, align=None)[来源]#
返回每个几何体到其他的最短距离
该操作以一对一的行方式进行:
该项目方法是插值的反向。
在shapely中,这等于
line_locate_point。- Parameters:
- otherBaseGeometry or GeoSeries
要计算投影点的其他几何体。
- normalizedboolean
如果 normalized 为 True,则返回归一化到对象长度的距离。
- alignbool | None (default None)
如果为真,则根据其索引自动对齐GeoSeries。 如果为假,则保留元素的顺序。 None默认为真。
- Returns:
- Series
示例
>>> from shapely.geometry import LineString, Point >>> s = geopandas.GeoSeries( ... [ ... LineString([(0, 0), (2, 0), (0, 2)]), ... LineString([(0, 0), (2, 2)]), ... LineString([(2, 0), (0, 2)]), ... ], ... ) >>> s2 = geopandas.GeoSeries( ... [ ... Point(1, 0), ... Point(1, 0), ... Point(2, 1), ... ], ... index=range(1, 4), ... )
>>> s 0 LINESTRING (0 0, 2 0, 0 2) 1 LINESTRING (0 0, 2 2) 2 LINESTRING (2 0, 0 2) dtype: geometry
>>> s2 1 POINT (1 0) 2 POINT (1 0) 3 POINT (2 1) dtype: geometry
我们可以将每个几何体投影到一个单一的
shapely 几何体上:>>> s.project(Point(1, 0)) 0 1.000000 1 0.707107 2 0.707107 dtype: float64
我们还可以逐行检查两个GeoSeries。 上面的GeoSeries具有不同的索引。 我们可以基于索引值对齐两个GeoSeries,并使用
align=True投影具有相同索引的元素,也可以忽略索引,根据它们的匹配顺序投影元素,使用align=False:>>> s.project(s2, align=True) 0 NaN 1 0.707107 2 0.707107 3 NaN dtype: float64
>>> s.project(s2, align=False) 0 1.000000 1 0.707107 2 0.707107 dtype: float64