Composable Geospatial Data Systems powered by Apache Arrow
Dewey Dunnington and Joris Van den Bossche [and Kyle Barron]
Voltron Data, Inc.
GeoArrow is GeoParquet wherever Parquet isn’t
130 million points to pandas dtype="object" takes minutes and 40 GB of memory
import geopandas
geopandas.read_parquet("microsoft-buildings-point.parquet" )
GeoPandas keeps spatial metadata + data type!
GeoArrow is GeoParquet wherever Parquet isn’t
130 million points from Paruqet to Arrow takes ~2s and a few GB of memory
import pyarrow.parquet
pyarrow.parquet.read_table("microsoft-buildings-point.parquet" )
…but there’s no “geometry” data type in Arrow so we loose the CRS and data type
GeoArrow is GeoParquet wherever Parquet isn’t
You can get the best of both with GeoArrow!
import pandas as pd
import geoarrow.pandas as _
pd.read_parquet("microsoft-buildings-point.parquet" )
src_file geometry
0 0 POINT (-84.95972352431309 32.421832237128726)
1 0 POINT (-84.9597329778881 32.420910155065535)
2 0 POINT (-84.9599375 32.2352595)
3 0 POINT (-84.96016955991914 32.422296538057)
4 0 POINT (-84.9616848201395 32.41927086747914)
TL;DR
GeoArrow is an extension type and memory layout specification that lets geospatial data be a first-class citizen in your Arrow-based data pipeline.
pip install geoarrow-pyarrow
import geoarrow.pyarrow as ga
Use your existing Arrow-based workflow (geometry is just another data type)
More information + data: https://geoarrow.org
geoarrow.pyarrow.io.read_pyogrio_table()
Composable Geospatial Data Systems
Geospatial data are hard at scale:
Metadata propagation (CRS)
Lack of support in file formats designed for composable data systems
Composable Geospatial Data Systems
Many workarounds:
Use a geospatial file format: excellent metadata support, not good at huge data or streaming
Use a serialzed representation (e.g., well-known text or well-known binary) and use a string/blob data type: wide string/blob support, looses metadata, requires deserialization
Use multiple columns (e.g., lon + lat): avoids deserialization, looses metadata, doesn’t scale to lines or polygons
Composable Geospatial Data Systems
GeoArrow lets you build + distribute extensions
GeoArrow + pyarrow
What if you didn’t need to special-case geometry?
import geoarrow.pyarrow as ga
import pyarrow.dataset
tab = pyarrow.parquet.read_table("microsoft-buildings-point.parquet" )
pyarrow.dataset.write_dataset(
tab,
"buildings_dataset" ,
format = "parquet" ,
partitioning= ["src_file" ]
)
GeoArrow + pyarrow
What if you didn’t need to special-case geometry?
import geoarrow.pyarrow as ga
import pyarrow.dataset
ds = pyarrow.dataset.dataset("buildings_dataset" , partitioning= ["src_file" ])
df = ds.filter (pyarrow.dataset.field("src_file" ) == 2 ) \
.head(5 ).to_pandas()
lon, lat = df.geometry.geoarrow.point_coords()
0 -111.696021
1 -111.696236
2 -111.696013
3 -111.696226
4 -111.696020
dtype: float64
0 33.426632
1 33.431045
2 33.390693
3 33.407750
4 33.465649
dtype: float64
GeoArrow + pyarrow
What if you didn’t need to special-case geometry?
GeoArrowExtensionDtype(geoarrow.point <{"$schema":"https://proj.org/schem...>)
GeoArrow: Hand off Data Faster
If you have a tool in another process (or on another node), serialization + writing to/reading from disk can get your data there. But:
Serialize to WKB (a few sec)
Write to disk (a few sec)
Read from disk (a few sec)
Deserialize from WKB (a few sec)
GeoArrow: Hand off Data Faster
If you have a tool in another process (or on another node), serialization + writing to/reading from disk can get your data there. But:
tab = tab.set_column(1 , "geometry" , ga.as_wkb(tab["geometry" ]))
pyarrow.parquet.write_table(tab, "temp.parquet" , compression = "none" )
tab2 = pyarrow.parquet.read_table("temp.parquet" )
tab2.set_column(1 , "geometry" , ga.as_geoarrow(tab2["geometry" ]))
GeoArrow: Hand off Data Faster
If you have a tool in another process (or on another node), you can stream your data there using Flight:
Start Flight server
Get descriptor (0 s)
do_put() (0 s)
writer.write_table() (A few sec)
GeoArrow: Hand off Data Faster
If you have a tool in another process (or on another node), you can stream your data there using Flight:
from pyarrow import flight
import geoarrow.pyarrow as ga
class FlightServer(flight.FlightServerBase):
def do_put(self , context, descriptor, reader, writer):
reader.read_all()
FlightServer(location= "grpc://0.0.0.0:8815" ).serve()
GeoArrow: Hand off Data Faster
If you have a tool in another process (or on another node), you can stream your data there using Flight:
import pyarrow.flight as flight
client = flight.connect ("grpc://0.0.0.0:8815" )
upload_descriptor = flight.FlightDescriptor.for_path("uploaded" )
writer, _ = client.do_put(upload_descriptor, tab.schema)
writer.write_table(tab)
writer.close()
Extending GeoArrow
The Arrow C Data interface lets you distribute native extensions as Python packages that operate on the same copy of the data.
from geoarrow.c import lib
type_in = lib.SchemaHolder()
tab["geometry" ].type ._export_to_c(type_in._addr())
array_in = lib.ArrayHolder()
tab["geometry" ].chunk(0 )._export_to_c(array_in._addr())
Extending GeoArrow
The Arrow C Data interface lets you distribute native extensions as Python packages that operate on the same copy of the data.
kernel = lib.CKernel("box_agg" .encode("UTF-8" ))
type_out = kernel.start(type_in, bytes ())
kernel.push_batch_agg(array_in)
array_out = kernel.finish_agg()
box = pyarrow.Array._import_from_c(array_out._addr(), type_out._addr())
Extending GeoArrow
The Arrow C Data interface lets you distribute native extensions as Python packages that operate on the same copy of the data.
<pyarrow.lib.StructArray object at 0x1680202e0>
-- is_valid: all not null
-- child 0 type: double
[
-88.47067299999998
]
-- child 1 type: double
[
-84.923994
]
-- child 2 type: double
[
30.227561
]
-- child 3 type: double
[
35.00860626358086
]
Composable Geospatial Data Systems
GeoArrow lets you build + distribute extensions
TL;DR
GeoArrow is an extension type and memory layout specification that lets geospatial data be a first-class citizen in your Arrow-based data pipeline.
pip install geoarrow-pyarrow
import geoarrow.pyarrow as ga
Use your existing Arrow-based workflow (geometry is just another data type)
More information + data: https://geoarrow.org
geoarrow.pyarrow.io.read_pyogrio_table()