geopandas.GeoSeries.get_coordinates#

GeoSeries.get_coordinates(include_z=False, ignore_index=False, index_parts=False)[来源]#

从一个 GeoSeries 获取坐标,作为一个 DataFrame 的浮点数。

返回的 DataFrame 的形状为 (N, 2),其中 N 是坐标对的数量。默认情况下 include_z=False,三维数据被忽略。当指定 include_z=True 时,返回的 DataFrame 的形状为 (N, 3)。

Parameters:
include_zbool, default False

包含 Z 坐标

ignore_indexbool, default False

如果为真,生成的索引将被标记为 0, 1, …, n - 1,忽略 index_parts.

index_partsbool, default False

如果为真,结果索引将是一个 MultiIndex(原始索引加上一个额外级别,用于指示坐标对的顺序:每个原始 GeoSeries 中几何体的新零基索引)。

Returns:
pandas.DataFrame

示例

>>> from shapely.geometry import Point, LineString, Polygon
>>> s = geopandas.GeoSeries(
...     [
...         Point(1, 1),
...         LineString([(1, -1), (1, 0)]),
...         Polygon([(3, -1), (4, 0), (3, 1)]),
...     ]
... )
>>> s
0                         POINT (1 1)
1              LINESTRING (1 -1, 1 0)
2    POLYGON ((3 -1, 4 0, 3 1, 3 -1))
dtype: geometry
>>> s.get_coordinates()
     x    y
0  1.0  1.0
1  1.0 -1.0
1  1.0  0.0
2  3.0 -1.0
2  4.0  0.0
2  3.0  1.0
2  3.0 -1.0
>>> s.get_coordinates(ignore_index=True)
     x    y
0  1.0  1.0
1  1.0 -1.0
2  1.0  0.0
3  3.0 -1.0
4  4.0  0.0
5  3.0  1.0
6  3.0 -1.0
>>> s.get_coordinates(index_parts=True)
       x    y
0 0  1.0  1.0
1 0  1.0 -1.0
  1  1.0  0.0
2 0  3.0 -1.0
  1  4.0  0.0
  2  3.0  1.0
  3  3.0 -1.0