Skip to main content

Crate pyo3_geoarrow

Crate pyo3_geoarrow 

Source
Expand description

§pyo3-geoarrow

PyO3 bindings for GeoArrow types, enabling seamless integration between Rust’s GeoArrow implementation and Python.

This crate provides Python-compatible wrappers around GeoArrow data structures, allowing Python code to efficiently work with and share geospatial data in the GeoArrow format through the Arrow C Data Interface (using the Arrow PyCapsule Interface) without data copies.

§Features

  • Zero-copy data exchange: Use Arrow’s C Data Interface for efficient memory sharing between Rust and Python.
  • GeoArrow types: Python bindings for GeoArrow geometry arrays, scalars, and metadata.
  • Type safety: Strongly-typed wrappers that preserve GeoArrow’s type system in Python.
  • FFI support: Import and export GeoArrow data to/from Python using the Arrow PyCapsule Interface.

§Core Types

  • PyGeoArray: Python wrapper for GeoArrow geometry arrays
  • PyGeoChunkedArray: Python wrapper for chunked GeoArrow geometry arrays
  • PyGeoArrayReader: Python wrapper for streaming array readers
  • PyGeoScalar: Python wrapper for GeoArrow scalar geometries
  • PyGeoType: Python wrapper for GeoArrow data types
  • PyCrs: Python wrapper for coordinate reference system representation

§Usage

This crate is primarily intended for use by Python binding developers who need to interoperate with GeoArrow data in Python. It is also used internally by the geoarrow-rust-* Python packages.

use std::sync::Arc;

use pyo3::prelude::*;
use pyo3_geoarrow::PyGeoArray;
use geoarrow_array::GeoArrowArray;

#[pyfunction]
fn process_geometry(py: Python, array: PyGeoArray) -> PyResult<PyGeoArray> {
    // Access the underlying GeoArrow array
    let inner: Arc<dyn GeoArrowArray> = array.into_inner();

    // Perform operations...

    Ok(PyGeoArray::new(inner))
}

§Integration with Arrow

This crate implements the Arrow PyCapsule Interface, allowing GeoArrow objects to be exchanged with any Python library that supports Arrow, including:

  • PyArrow
  • Polars (once they support extension types)
  • GeoPandas (via PyArrow)
  • DuckDB

§Dependencies

This crate builds on:

Re-exports§

pub use data_type::PyGeoType;

Modules§

data_type
GeoArrow data type definitions and constructors.
input
Input types for accepting GeoArrow data from Python.

Structs§

PyCoordBuffer
Python wrapper for a GeoArrow coordinate buffer.
PyCrs
Python wrapper for a coordinate reference system (CRS).
PyEdges
Python wrapper for GeoArrow edge interpolation type.
PyGeoArray
Python wrapper for a GeoArrow geometry array.
PyGeoArrayReader
Python wrapper for a GeoArrow array reader (stream).
PyGeoChunkedArray
Python wrapper for a chunked GeoArrow geometry array.
PyGeoScalar
Python wrapper for a GeoArrow scalar geometry.
PyOffsetBuffer
Python wrapper for an Arrow offset buffer.
PyprojCRSTransform
An implementation of CrsTransform using pyproj.

Enums§

PyCoordType
Python wrapper for GeoArrow coordinate type.
PyDimension
Python wrapper for GeoArrow coordinate dimension.
PyGeoArrowError
Error type for GeoArrow operations in Python bindings.

Type Aliases§

PyGeoArrowResult
Result type for GeoArrow operations that may fail.