geopandas.GeoDataFrame.to_arrow#

GeoDataFrame.to_arrow(*, index=None, geometry_encoding='WKB', interleaved=True, include_z=None)[来源]#

将GeoDataFrame编码为GeoArrow格式。

有关GeoArrow规范的详细信息,请参见 https://geoarrow.org/

此函数返回一个通用的 Arrow 数据对象,实施Arrow PyCapsule Protocol(即具有__arrow_c_stream__方法)。然后,该对象可以被您选择的支持此协议的 Arrow 实现使用。

在1.0版本中添加。

Parameters:
indexbool, default None

如果 True,始终将数据框的索引作为列包含在文件输出中。 如果 False,索引将不会写入文件。 如果 None,索引将作为列包含在文件输出中,除了 RangeIndex 仅作为元数据存储。

geometry_encoding{‘WKB’, ‘geoarrow’ }, default ‘WKB’

用于数据转换的GeoArrow编码。

interleavedbool, default True

仅与‘geoarrow’编码相关。如果为True,几何体的坐标将交错存储在一个固定大小的列表数组中。如果为False,坐标将作为单独的数组存储在一种结构类型中。

include_zbool, default None

仅与‘geoarrow’编码相关(对于WKB,个体几何形状的维度得以保留)。 如果为False,返回2D几何形状。如果为True,将在输出中包含第三维度(如果几何形状没有第三维度,z坐标将为NaN)。 默认情况下,将从输入几何形状中推断维度。 请注意,对于空几何形状,这种推断可能不可靠(为了确保结果,建议指定关键字)。

Returns:
ArrowTable

一个通用的箭头表对象,几何列编码为GeoArrow。

示例

>>> from shapely.geometry import Point
>>> data = {'col1': ['name1', 'name2'], 'geometry': [Point(1, 2), Point(2, 1)]}
>>> gdf = geopandas.GeoDataFrame(data)
>>> gdf
    col1     geometry
0  name1  POINT (1 2)
1  name2  POINT (2 1)
>>> arrow_table = gdf.to_arrow()
>>> arrow_table
<geopandas.io._geoarrow.ArrowTable object at ...>

返回的数据对象需要被实现箭头 PyCapsule 协议的库消费。例如,将数据包装为 pyarrow.Table(需要 pyarrow >= 14.0):

>>> import pyarrow as pa
>>> table = pa.table(arrow_table)
>>> table
pyarrow.Table
col1: string
geometry: binary
----
col1: [["name1","name2"]]
geometry: [[0101000000000000000000F03F0000000000000040,01010000000000000000000040000000000000F03F]]