geopandas.GeoDataFrame.explode#

GeoDataFrame.explode(column=None, ignore_index=False, index_parts=None, **kwargs)#

将多零件几何图形分解为多个单一几何图形。

包含多部分几何图形的每一行将被拆分为具有单个几何图形的多行,从而增加GeoDataFrame的垂直大小。

备注

IGNORE_INDEX需要熊猫1.1.0或更高版本。

参数
column字符串,默认为无

要分解的列。对于几何图形列,多零件几何图形将转换为单零件几何图形。如果没有,则使用激活的几何图形列。

ignore_index布尔值,默认为False

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

index_parts布尔值,默认为True

如果为True,则生成的索引将是多个索引(具有指示多个几何图形的附加级别的原始索引:每个多零件几何图形的每个单个零件几何图形的新索引从零开始)。

退货
GeoDataFrame

分解的Geodataframe,每个单独的几何体都是Geodataframe中的一个单独条目。

参见

GeoDataFrame.dissolve

将几何图形融合到单个观测中。

示例

>>> from shapely.geometry import MultiPoint
>>> d = {
...     "col1": ["name1", "name2"],
...     "geometry": [
...         MultiPoint([(1, 2), (3, 4)]),
...         MultiPoint([(2, 1), (0, 0)]),
...     ],
... }
>>> gdf = geopandas.GeoDataFrame(d, crs=4326)
>>> gdf
    col1                                       geometry
0  name1  MULTIPOINT (1.00000 2.00000, 3.00000 4.00000)
1  name2  MULTIPOINT (2.00000 1.00000, 0.00000 0.00000)
>>> exploded = gdf.explode(index_parts=True)
>>> exploded
      col1                 geometry
0 0  name1  POINT (1.00000 2.00000)
  1  name1  POINT (3.00000 4.00000)
1 0  name2  POINT (2.00000 1.00000)
  1  name2  POINT (0.00000 0.00000)
>>> exploded = gdf.explode(index_parts=False)
>>> exploded
    col1                 geometry
0  name1  POINT (1.00000 2.00000)
0  name1  POINT (3.00000 4.00000)
1  name2  POINT (2.00000 1.00000)
1  name2  POINT (0.00000 0.00000)
>>> exploded = gdf.explode(ignore_index=True)
>>> exploded
    col1                 geometry
0  name1  POINT (1.00000 2.00000)
1  name1  POINT (3.00000 4.00000)
2  name2  POINT (2.00000 1.00000)
3  name2  POINT (0.00000 0.00000)