Fixing Ibis Output With No CRS or GeoParquet Metadata
On this page
Problem statement
Projected to NZTM2000 in Ibis, Auckland's 167 suburbs left DuckDB three ways and lost their CRS three ways. execute() gave a GeoDataFrame with crs set to None. to_parquet() wrote a file GeoPandas refused to open. A COPY of the compiled SQL wrote a file that opened as longitude/latitude, with its western edge at x = 1,739,625. This page reproduces each one and labels each exit correctly.
Quick answer
Set the CRS yourself when the result leaves Ibis: the one named in the last convert, or the source's if there was none.
gdf = nztm.execute().set_crs("EPSG:2193") # the target of the last convert
print(gdf.crs.to_epsg(), f"{gdf.to_crs(4326).total_bounds.round(2).tolist()}")
2193 [174.57, -37.1, 175.04, -36.7]
With the CRS set to EPSG:2193, the target of the query's convert, GeoPandas can reproject the suburbs again: back in longitude/latitude they span 174.57–175.04° E and 37.1–36.7° S, the box they were cut from.
Three exits, three ways to lose the CRS
1. execute() returns a GeoDataFrame with no CRS
gdf = nztm.execute()
print(type(gdf).__name__, "crs:", gdf.crs)
try:
gdf.to_crs(4326)
except ValueError as error:
print(f"{type(error).__name__}: {' '.join(str(error).split())}")
GeoDataFrame crs: None
ValueError: Cannot transform naive geometries. Please set a crs on the object first.
Ibis's DuckDB backend does return a real GeoDataFrame, with a geometry column built from the result's WKB, but its crs is None. GeoPandas then refuses any reprojection, and the GeoDataFrame cannot be placed on a basemap.
2. to_parquet() writes bytes without GeoParquet metadata
nztm.to_parquet("data/suburbs_ibis.parquet")
print("geometry column:", pq.read_schema("data/suburbs_ibis.parquet").field("geometry").type,
"· metadata:", pq.read_metadata("data/suburbs_ibis.parquet").metadata)
try:
gpd.read_parquet("data/suburbs_ibis.parquet")
except ValueError as error:
print(f"{type(error).__name__}: {str(error).splitlines()[0]}")
geometry column: binary · metadata: None
ValueError: Missing geo metadata in Parquet/Feather file.
to_parquet on an Ibis expression writes the geometry as plain binary and no file-level metadata at all (None), so there is no geo entry to say the column is geometry, let alone in which CRS. GeoPandas will not guess and stops.
3. A DuckDB COPY labels metres as degrees
sql = ibis.to_sql(nztm)
con.raw_sql(f"copy (select * replace (ST_GeomFromWKB(geometry) as geometry) from ({sql})) to 'data/suburbs_copy.parquet'")
copied = gpd.read_parquet("data/suburbs_copy.parquet")
print("CRS GeoPandas reads:", copied.crs, "· western edge x:", f"{copied.total_bounds[0]:,.0f}")
print("projected 'from degrees' to NZTM2000:", copied.to_crs(2193).total_bounds[:2].tolist())
CRS GeoPandas reads: OGC:CRS84 · western edge x: 1,739,625
projected 'from degrees' to NZTM2000: [inf, inf]
Turning the bytes back into geometry inside a DuckDB COPY gets a GeoParquet file GeoPandas opens, and it is wrong. DuckDB writes the geo metadata, but the geometry carries no CRS, and GeoParquet defines a missing CRS as OGC:CRS84. GeoPandas reports degrees for coordinates whose western edge is at x = 1,739,625. Nothing fails until someone reprojects the file, and then every coordinate becomes infinite.
4. Put the CRS on each exit
con.raw_sql(f"copy (select * replace (ST_SetCRS(ST_GeomFromWKB(geometry), 'EPSG:2193') as geometry) from ({sql})) "
"to 'data/suburbs_copy_crs.parquet'")
nztm.execute().set_crs("EPSG:2193").to_parquet("data/suburbs_gpd.parquet")
for path in ["data/suburbs_copy_crs.parquet", "data/suburbs_gpd.parquet"]:
back = gpd.read_parquet(path)
print(f"{path:31} EPSG:{back.crs.to_epsg()} {back.to_crs(2193).area.sum() / 1e6:.1f} km²")
data/suburbs_copy_crs.parquet EPSG:2193 656.8 km²
data/suburbs_gpd.parquet EPSG:2193 656.8 km²
Both repaired files come back as EPSG:2193 with the 656.8 km² the query measured. In SQL, ST_SetCRS puts the CRS on the geometry before COPY writes it, and DuckDB then writes it into the GeoParquet metadata. In Python, set_crs on the executed result lets GeoPandas write the metadata itself. Use the first when the result is too large to collect in Python.
One function for the way out
The data used on this page
One file: the 167 Auckland suburbs (macrohood division areas) from Overture Maps 2026-11-18.0, read from a saved copy; ODbL 1.0, © OpenStreetMap contributors.
from pathlib import Path
import geopandas as gpd
import ibis
import pyarrow.parquet as pq
import requests
from ibis import _
Path("data").mkdir(exist_ok=True)
name = "overture-auckland-suburbs-2026-11-18.0.parquet" # from s3://overturemaps-us-west-2/release/2026-11-18.0/theme=divisions
if not Path(f"data/{name}").exists():
Path(f"data/{name}").write_bytes(requests.get(f"https://data.spatialworkflow.io/{name}", timeout=300).content)
con = ibis.duckdb.connect()
# the cast is for Ibis 12, which cannot read DuckDB's GEOMETRY('OGC:CRS84') type (see /ibis-keyerror-ogc-crs84/)
suburbs = con.sql(f"select * replace (geometry::GEOMETRY as geometry) from read_parquet('data/{name}')")
nztm = suburbs.select("name", geometry=_.geometry.convert("EPSG:4326", "EPSG:2193"))
nztm = nztm.mutate(km2=nztm.geometry.area() / 1e6)
print(f"{nztm.count().execute()} suburbs, {nztm.km2.sum().execute():.1f} km² on NZTM2000")
167 suburbs, 656.8 km² on NZTM2000
Example 1: a helper that carries the CRS with the expression
def to_geopandas(expr, crs):
"""Run an Ibis expression and label its geometry with the CRS its coordinates are in."""
return expr.execute().set_crs(crs)
big = to_geopandas(nztm.order_by(ibis.desc("km2")).limit(5), "EPSG:2193")
check = (big.area / 1e6 - big.km2).abs().max()
print(big[["name", "km2"]].round(1).to_string(index=False))
print(f"GeoPandas area against Ibis area: largest difference {check:.1e} km²")
name km2
Māngere 25.7
Flat Bush 20.5
Massey 17.7
Henderson 17.4
Papakura 16.9
GeoPandas area against Ibis area: largest difference 0.0e+00 km²
A two-line helper makes the CRS an argument of every exit instead of a step to remember. The five largest suburbs, Māngere (25.7 km²) to Papakura (16.9 km²), have exactly the same area in GeoPandas as in the Ibis query, a difference of 0.0 km², which shows the label and the coordinates agree. Labelled EPSG:4326 by mistake, the same check would fail at once.
Why the CRS does not survive
None, no metadata, and a wrong default are three answers to one missing label. Only the third produces a file that looks finished, which is why the area check in Example 1 is worth its two lines.
Labels that are wrong rather than missing
- Several geometry columns.
executemakes the first geometry column in the select the active one, even when a column calledgeometrycomes later (a centroid selected first becomes the geometry). The others come back as geometry with no CRS; set each withgdf[col] = gdf[col].set_crs(...), andset_geometryto pick the active one.
Internal links
- Fixing Ibis OperationNotDefinedError for transform — the
convertwhose target this page sets - Fixing KeyError: 'OGC:CRS84' when Ibis reads GeoParquet — where the CRS label is dropped on the way in
- Fixing a geometry column lost on export from DuckDB — the same export written in DuckDB SQL, to CSV, GeoJSON and Parquet
- How to rewrite a GeoPandas workflow in Ibis — where results go back to GeoPandas
FAQ
Which CRS should I set?
The CRS the coordinates are in when the query ends: the target of the last convert, or the CRS the data was read in if nothing converted it. On this page that is EPSG:2193 for the projected suburbs.
Can Ibis write GeoParquet with a CRS directly?
Not with to_parquet on Ibis 12.0 and DuckDB. Either execute and write through GeoPandas, or COPY the compiled SQL with ST_SetCRS, as in step 4.