Repository navigation
Description
Part of #2230.
Summary
Implement GeoSeries.affine_transform(matrix) and GeoDataFrame delegation using Sedona's existing ST_Affine Spark SQL function.
The implementation must remain fully distributed: it should construct a Spark column expression for every geometry row and must not call to_geopandas(), collect(), toLocalIterator(), or a Python row UDF.
API and coefficient mapping
GeoPandas accepts either of these matrix layouts:
- 2D:
[a, b, d, e, xoff, yoff] - 3D:
[a, b, c, d, e, f, g, h, i, xoff, yoff, zoff]
They represent:
x' = a*x + b*y + c*z + xoff
y' = d*x + e*y + f*z + yoff
z' = g*x + h*y + i*z + zoff
Sedona's 2D wrapper call accepts the six GeoPandas values directly. The 3D Python wrapper has this positional signature instead:
ST_Affine(geometry, a, b, d, e, xOff, yOff, c, f, g, h, i, zOff)
The 12-value implementation must therefore pass the optional 3D coefficients by name or explicitly reorder them. Passing *matrix directly would produce incorrect coordinates. Coefficients should also be normalized to Python floats because the current wrapper validation rejects integer arguments.
Requirements
- Accept one operation-wide sequence containing exactly 6 or 12 numeric coefficients.
- Validate invalid lengths and non-numeric values with clear errors.
- Reject
Nonecoefficients before callingST_Affine; otherwise its optional-argument handling can silently select the 2D overload. - Normalize valid numeric coefficients to Python floats.
- Route 6-value matrices to the 2D
ST_Affineoverload. - Explicitly map 12-value matrices to the 3D
ST_Affinewrapper arguments. - Preserve GeoSeries index and CRS metadata.
- Preserve geometry SRID, nulls, empty geometries, mixed geometry types, and existing Z values under a 2D transform.
- Provide GeoDataFrame behavior through the existing
base.pygeometry-column delegation. - Add no driver-side materialization or new mandatory dependency.
Tests
Add direct and GeoPandas parity coverage for:
- identity, translation, scale, rotation, and shear matrices;
- integer and floating-point coefficients;
- 6-value 2D and 12-value 3D matrices;
- a 12-value ordering regression:
range(1, 13)applied toPOINT Z (1 2 3)must producePOINT Z (24 43 62); - 2D matrices applied to Z geometries;
- 3D matrices applied to 2D and Z geometries;
- null and empty geometries;
- points, lines, polygons, multi-geometries, and geometry collections;
- invalid matrix lengths and non-numeric coefficients;
- index, CRS, and SRID preservation;
- GeoSeries and GeoDataFrame delegation.
Document rather than emulate driver-side behavior for mixed 2D/3D geometry collections, M ordinates, and NaN-Z inputs where the underlying JTS and Shapely engines differ. Homogeneous 2D and 3D geometries must match GeoPandas.
Likely files
python/sedona/spark/geopandas/base.pypython/sedona/spark/geopandas/geoseries.pypython/tests/geopandas/test_geoseries.pypython/tests/geopandas/test_match_geopandas_series.py
No JVM, Scala, or SQL wrapper changes should be necessary.
Acceptance criteria
- Output matches GeoPandas for supported 2D and 3D matrices.
- Execution remains a Spark expression over distributed geometry rows.
- No driver collection, local iteration, or Python row UDF is introduced.
- Focused tests and the relevant Python matrix pass.
- The implementation PR references
Part of #2230and does not close the epic.
Non-goals
- Implementing
scale,skew, ortranslatein the same pull request. - Accepting a different matrix per row.
- Adding new affine functionality to Sedona's JVM or SQL layers.
Activity
[apacheGH-3134] Validate affine matrix length before copying
[GH-3134] Implement distributed GeoPandas affine_transform (#3135)