GeoArrow Types

0.3.0 · active · verified Thu Apr 16

The `geoarrow-types` package defines Python types for the GeoArrow specification, primarily as PyArrow extension types. It provides a foundational layer for representing geospatial data in Apache Arrow columnar format, enabling interoperability and high-performance geospatial data processing. The current version is 0.3.0, and it follows a minor release cadence aligned with the broader GeoArrow Python ecosystem.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to register GeoArrow extension types and create PyArrow arrays using these types. It covers both a structured geometry type (Point) and a binary representation type (WKB). The `register_extension_type()` call is essential for PyArrow to map the string identifier (e.g., 'geoarrow.point') to the custom Python class.

import pyarrow as pa
from geoarrow_types import PointExtensionType, WkbExtensionType

# 1. Register GeoArrow Point Type
# This step is crucial for PyArrow to recognize 'geoarrow.point' by name
PointExtensionType.register_extension_type()

# Create a PyArrow array using the registered GeoArrow point type
point_data = pa.array(
    [
        {'x': 1.0, 'y': 2.0},
        {'x': 3.0, 'y': 4.0},
        None # GeoArrow types support null values
    ],
    type="geoarrow.point" # Use the registered string name
)
print("\nGeoArrow Point Array:")
print(point_data)
print("Is GeoArrow Point Type recognized:", isinstance(point_data.type, PointExtensionType))

# 2. Register GeoArrow WKB Type
WkbExtensionType.register_extension_type()

# Example WKB bytes (usually generated by libraries like shapely)
wkb_point_bytes = b'\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\x00@'
wkb_linestring_bytes = b'\x01\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08@\x00\x00\x00\x00\x00\x00\x10@\x00\x00\x00\x00\x00\x00\x14@\x00\x00\x00\x00\x00\x00\x18@'

wkb_data = pa.array([wkb_point_bytes, wkb_linestring_bytes, None], type="geoarrow.wkb")
print("\nGeoArrow WKB Array:")
print(wkb_data)
print("Is GeoArrow WKB Type recognized:", isinstance(wkb_data.type, WkbExtensionType))

view raw JSON →