geopandas.GeoSeries.project#

GeoSeries.project(other, normalized=False, align=True)[source]#

Return the distance along each geometry nearest to other

The operation works on a 1-to-1 row-wise manner:

../../../_images/binary_op-01.svg

The project method is the inverse of interpolate.

In shapely, this is equal to line_locate_point.

Parameters:
otherBaseGeometry or GeoSeries

The other geometry to computed projected point from.

normalizedboolean

If normalized is True, return the distance normalized to the length of the object.

alignbool (default True)

If True, automatically aligns GeoSeries based on their indices. If False, the order of elements is preserved.

Returns:
Series

Examples

>>> 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

We can project each geometry on a single shapely geometry:

../../../_images/binary_op-03.svg
>>> s.project(Point(1, 0))
0    1.000000
1    0.707107
2    0.707107
dtype: float64

We can also check two GeoSeries against each other, row by row. The GeoSeries above have different indices. We can either align both GeoSeries based on index values and project elements with the same index using align=True or ignore index and project elements based on their matching order using align=False:

../../../_images/binary_op-02.svg
>>> 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