Fixing Ibis OperationNotDefinedError for transform on DuckDB
On this page
Problem statement
You reproject a geometry column in Ibis the way the method list suggests, t.geometry.transform(2193), and DuckDB answers OperationNotDefinedError: Compilation rule for 'GeoTransform' operation is not defined. set_srid and srid fail the same way. Ibis has these methods because some of its backends (PostGIS among them) store an SRID in every geometry; DuckDB's backend does not, so it cannot compile them. It does compile a different method that reprojects. This page shows the error on Overture Maps places in Auckland, the method that works, and the axis-order detail that makes the same call in raw DuckDB SQL return infinite coordinates.
Quick answer
Use convert(source, target), which names both CRSs, in place of transform(srid):
nztm = places.mutate(geometry=places.geometry.convert("EPSG:4326", "EPSG:2193")) # NZGD2000 / NZTM2000, metres
sky = nztm.filter(nztm.name == "Sky Tower").select("name", e=_.geometry.x(), n=_.geometry.y()).execute()
print(sky.round(1).to_string(index=False))
name e n
Sky Tower 1757111.2 5920490.5
convert takes the CRS the coordinates are in and the CRS to put them into, and compiles to DuckDB's ST_Transform. The Sky Tower lands at 1,757,111 m east and 5,920,490 m north on NZTM2000, the national grid, where distances and areas come out in metres.
Reprojecting without an SRID
1. The three methods that need an SRID
for label, expr in [("transform(2193)", lambda g: g.transform(2193)),
("set_srid(4326)", lambda g: g.set_srid(4326)),
("srid()", lambda g: g.srid())]:
try:
places.select(x=expr(places.geometry)).limit(1).execute()
except OperationNotDefinedError as error:
print(f"{label:16} {type(error).__name__}: {error}")
transform(2193) OperationNotDefinedError: Compilation rule for 'GeoTransform' operation is not defined
set_srid(4326) OperationNotDefinedError: Compilation rule for 'GeoSetSRID' operation is not defined
srid() OperationNotDefinedError: Compilation rule for 'GeoSRID' operation is not defined
All three fail when the expression is compiled, not when it runs, so they fail even on an empty table. transform takes only the target, because on a backend that stores an SRID in each geometry the source is already known. DuckDB's geometry has nowhere to keep one, so there is no source to transform from, and Ibis leaves the operation undefined there rather than guess.
2. What convert compiles to
sql = ibis.to_sql(places.select(geometry=places.geometry.convert("EPSG:4326", "EPSG:2193")))
print(next(line.strip() for line in sql.splitlines() if "ST_TRANSFORM" in line))
ST_TRANSFORM("t0"."geometry", 'EPSG:4326', 'EPSG:2193', TRUE) AS "geometry"
The compiled call has a fourth argument that the Ibis method does not show: TRUE, DuckDB's always_xy flag.
3. Why the last argument matters
raw = duckdb.connect()
raw.sql("load spatial")
for always_xy in [False, True]:
wkt = raw.sql(f"select ST_AsText(ST_Transform(ST_Point(174.762199, -36.848447), 'EPSG:4326', 'EPSG:2193', {always_xy}))").fetchone()[0]
print(f"always_xy={always_xy!s:5} {wkt}")
always_xy=False POINT (inf inf)
always_xy=True POINT (1757111.192142319 5920490.500827469)
Without the flag, DuckDB follows EPSG:4326's official axis order, latitude first. It reads the Sky Tower's longitude, 174.76, as a latitude, which does not exist, and returns POINT (inf inf). With it, x is longitude, as in every GeoParquet file. Ibis always sends TRUE, so convert("EPSG:4326", β¦) is right for longitude/latitude data; hand-written DuckDB SQL needs the flag added, or it produces infinities.
4. Check the result against a geodesic distance
airport = places.filter(places.id == "d001fa55-3bcb-4041-b8e6-1b6883f5a6b3") # "Auckland Airport", the terminal
pair = (places.filter(places.name == "Sky Tower").select(a=_.geometry)
.cross_join(airport.select(b=_.geometry)))
d = pair.select(
lon_a=_.a.x(), lat_a=_.a.y(), lon_b=_.b.x(), lat_b=_.b.y(),
nztm_m=_.a.convert("EPSG:4326", "EPSG:2193").distance(_.b.convert("EPSG:4326", "EPSG:2193")),
).execute().iloc[0]
geodesic = Geod(ellps="GRS80").inv(d.lon_a, d.lat_a, d.lon_b, d.lat_b)[2]
print(f"Sky Tower to the airport: {d.nztm_m:,.0f} m on NZTM2000, {geodesic:,.0f} m on the ellipsoid ({d.nztm_m - geodesic:+.1f} m)")
Sky Tower to the airport: 17,138 m on NZTM2000, 17,140 m on the ellipsoid (-1.6 m)
From the Sky Tower to the Auckland Airport terminal is 17,138 m on the projected coordinates and 17,140 m measured on the GRS80 ellipsoid with pyproj. The 1.6 m gap is NZTM2000's own scale error this far from its central meridian, about one part in 10,000: the conversion is right. (The place is picked by its Overture id because Overture also has an "Auckland International Airport" placed in the city centre.)
A wrong source CRS, and the way back
The data used on this page
56,465 Overture Maps places for Auckland, release 2026-11-18.0, stored longitude first like every GeoParquet file, from a saved copy; CDLA Permissive 2.0.
from pathlib import Path
import duckdb
import ibis
import requests
from ibis import _
from ibis.common.exceptions import OperationNotDefinedError
from pyproj import Geod
Path("data").mkdir(exist_ok=True)
name = "overture-auckland-places-2026-11-18.0.parquet" # from s3://overturemaps-us-west-2/release/2026-11-18.0/theme=places
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/)
places = con.sql(f"select * replace (geometry::GEOMETRY as geometry) from read_parquet('data/{name}')")
print(f"{places.count().execute():,} places Β· ibis {ibis.__version__} Β· duckdb {duckdb.__version__}")
56,465 places Β· ibis 12.0.0 Β· duckdb 1.5.5
Example 1: converting coordinates that are already projected
twice = nztm.mutate(geometry=nztm.geometry.convert("EPSG:4326", "EPSG:2193"))
print(twice.filter(twice.name == "Sky Tower").select(e=_.geometry.x(), n=_.geometry.y()).execute().to_string(index=False))
ranges = nztm.aggregate(e_min=_.geometry.x().min(), e_max=_.geometry.x().max(),
n_min=_.geometry.y().min(), n_max=_.geometry.y().max()).execute().iloc[0]
print(f"NZTM2000 extent of the places: E {ranges.e_min:,.0f}β{ranges.e_max:,.0f}, N {ranges.n_min:,.0f}β{ranges.n_max:,.0f}")
e n
inf inf
NZTM2000 extent of the places: E 1,737,928β1,782,904, N 5,892,372β5,937,077
convert trusts the source CRS it is given. Applied a second time to coordinates already in metres, it treats 1,757,111 as a longitude and returns infinity again, with no error. The quickest guard is the extent: in NZTM2000 the places run from 1,737,928 to 1,782,904 m east and 5,892,372 to 5,937,077 m north, numbers that cannot be degrees.
Example 2: back to longitude and latitude
back = nztm.mutate(geometry=nztm.geometry.convert("EPSG:2193", "EPSG:4326"))
err = (places.select("id", lon=_.geometry.x(), lat=_.geometry.y())
.join(back.select("id", lon2=_.geometry.x(), lat2=_.geometry.y()), "id")
.aggregate(max_dlon=(_.lon - _.lon2).abs().max(), max_dlat=(_.lat - _.lat2).abs().max(), n=_.count())
.execute().iloc[0])
print(f"{int(err.n):,} places there and back: largest change {err.max_dlon:.1e}Β° in longitude, {err.max_dlat:.1e}Β° in latitude")
56,465 places there and back: largest change 2.8e-14Β° in longitude, 2.1e-14Β° in latitude
Converting the 56,465 projected places back to EPSG:4326 returns every coordinate to within 2.8e-14Β°, a few nanometres, so a projected working copy can go back to longitude/latitude for a web map without losing anything.
Example 3: the same two methods compiled for PostGIS
t = ibis.table({"geometry": "geometry"}, name="places")
for label, expr in [("transform(2193)", t.select(g=t.geometry.transform(2193))),
("convert(4326 β 2193)", t.select(g=t.geometry.convert("EPSG:4326", "EPSG:2193")))]:
for dialect in ["duckdb", "postgres"]:
try:
line = next(l.strip() for l in ibis.to_sql(expr, dialect=dialect).splitlines() if "ST_TRANSFORM" in l)
except OperationNotDefinedError:
line = "not defined"
print(f"{label:21} {dialect:9} {line}")
transform(2193) duckdb not defined
transform(2193) postgres ST_ASEWKB(ST_TRANSFORM("t0"."geometry", 2193)) AS "g"
convert(4326 β 2193) duckdb ST_TRANSFORM("t0"."geometry", 'EPSG:4326', 'EPSG:2193', TRUE) AS "g"
convert(4326 β 2193) postgres not defined
ibis.to_sql compiles an unbound table for any dialect without a database, which makes it a cheap way to check where a method is defined. On PostGIS, transform(2193) becomes ST_TRANSFORM(geometry, 2193) and convert is the undefined one: exactly the reverse of DuckDB.
Why DuckDB has no SRID to set
Each Ibis method creates an operation (GeoTransform, GeoSetSRID, GeoSRID, GeoConvert), and each backend has its own table of rules for turning operations into SQL. Ibis 12's DuckDB table has a rule for GeoConvert and none for the other three, and PostgreSQL's table is the reverse, as Example 3 printed. The method list in the documentation is the same for every backend; the rule table is what decides. Compiling an unbound table with ibis.to_sql(expr, dialect=β¦) checks a method against a backend in a millisecond, before any data is involved.
When convert still gives wrong answers
- Infinity instead of an error. A wrong source CRS gives
infcoordinates, and they pass quietly througharea()anddistance(). Check the extent after every conversion, as in Example 1. - The same code on PostGIS. There
transform(2193)works andconvertis the method that is not defined. Code meant for both backends needs a branch oncon.name. - Overture's duplicate places. Overture has several places named for the airport, one of them in the city centre. Pick a reference point by id, not by name, or a distance check can confirm the wrong thing.
- Projected metres are not ground metres. NZTM2000 was 1.6 m short on 17 km here. For distances across a whole country, measure on the ellipsoid instead (distances in metres).
Internal links
- How to measure distances and buffers in metres in Ibis β what to do with the projected column
- Fixing KeyError: 'OGC:CRS84' when Ibis reads GeoParquet β the cast in this page's setup
- Fixing Ibis output with no CRS β the CRS
convertdoes not record, put back on the result - How to see the SQL behind an Ibis spatial query β reading what each method compiles to
FAQ
Does Ibis remember the CRS after convert?
No. On DuckDB the column has the same type before and after, and the result reaches GeoPandas with no CRS. Keep the CRS names in your code and set the CRS when the data leaves Ibis.
Can I pass an EPSG number to convert?
It takes CRS strings, the same ones ST_Transform accepts: "EPSG:2193", or a PROJ string. This page uses the EPSG: form throughout.