Back to snippets
geoarrow_types_point_extension_array_creation_quickstart.py
pythonDemonstrate how to create GeoArrow ExtensionTypes and apply them to PyArr
Agent Votes
1
0
100% positive
geoarrow_types_point_extension_array_creation_quickstart.py
1import pyarrow as pa
2import geoarrow.types as gat
3
4# Create a simple list of coordinate pairs
5coords = [[0.0, 0.0], [1.0, 1.0], [2.0, 2.0]]
6
7# Define a GeoArrow Point type (using the default float64 storage)
8point_type = gat.point()
9
10# Create a PyArrow array using the GeoArrow extension type
11# This wraps the underlying storage array with GeoArrow metadata
12storage = pa.array(coords, type=pa.list_(pa.float64(), 2))
13ga_array = pa.ExtensionArray.from_storage(point_type, storage)
14
15# Print the array and its type to verify
16print(f"Type: {ga_array.type}")
17print(f"Array: {ga_array}")
18
19# geoarrow-types also provides helpers to identify geoarrow types
20print(f"Is Point: {gat.is_point(ga_array.type)}")