Skip to content

[GH-3153] Align CRS handling across raster operations - #3194

Draft
jiayuasu wants to merge 3 commits into
apache:masterfrom
jiayuasu:fix/raster-predicate-missing-crs
Draft

[GH-3153] Align CRS handling across raster operations#3194
jiayuasu wants to merge 3 commits into
apache:masterfrom
jiayuasu:fix/raster-predicate-missing-crs

Conversation

@jiayuasu

@jiayuasu jiayuasu commented Jul 28, 2026

Copy link
Copy Markdown
Member

Closes #3153.

What changed

  • Use one explicit CRS contract for raster-geometry operations:
    • a raster without a CRS accepts only an SRID-0 geometry and evaluates the coordinates directly;
    • an EPSG-addressable raster requires the geometry to have an SRID and transforms it when needed;
    • a raster with a non-EPSG CRS treats an SRID-0 geometry as native raster coordinates, while an EPSG-tagged geometry is transformed to the raster's full CRS.
  • Require matching CRS presence for raster-raster topological predicates. Two CRS-less rasters use planar coordinates directly; two rasters with defined CRSs are transformed when needed.
  • Apply the contract to RS_Intersects, RS_Contains, RS_Within, RS_AsRaster, RS_Clip, RS_SetValues, RS_Value, RS_Values, RS_ZonalStats, RS_ZonalStatsAll, and the geometry variants of RS_WorldToRasterCoord, RS_WorldToRasterCoordX, and RS_WorldToRasterCoordY.
  • Rasterize the transformed geometry, fixing cases where the intersection check used aligned coordinates but rasterization still used the original coordinates.
  • Preserve the existing planar envelope filtering and indexing for optimized range and broadcast raster joins. CRS validation occurs when a candidate pair reaches the scalar predicate; joins do not preflight CRS metadata across their complete inputs.
  • Keep the legacy RS_DWithin behavior unchanged: missing CRS or SRID metadata is still interpreted as WGS84.
  • Update the SQL documentation and examples for the affected operations.

Why

Raster inputs can carry full CRS metadata even when that CRS has no EPSG identifier. Treating every missing geometry SRID as WGS84 can silently compare incompatible coordinates, while rejecting SRID 0 unconditionally makes non-EPSG rasters unreachable because JTS geometries cannot carry the raster's full CRS object.

The three-state contract rejects ambiguous combinations while keeping custom-CRS rasters usable with geometries expressed directly in their native coordinate space.

User impact

Topological raster operations now reject these ambiguous combinations with a stable error:

  • raster without CRS + geometry with a positive SRID;
  • EPSG raster + SRID-0 geometry;
  • raster-raster input where only one raster has a CRS.

A non-EPSG raster accepts an SRID-0 geometry as native raster coordinates. Callers that intend an untagged geometry to be WGS84 should assign SRID 4326 explicitly.

Validation

  • mvn -o -pl common test — 1,175 tests passed
  • mvn -o -Pscala2.12,sedona-spark-3.4 -pl spark/common -DwildcardSuites=org.apache.sedona.sql.RasterJoinSuite scalatest:test — 57 tests passed
  • mvn -o -Pscala2.12,sedona-spark-3.4 -pl spark/common -DwildcardSuites=org.apache.sedona.sql.rasteralgebraTest scalatest:test — 167 tests passed
  • mvn -o -Pscala2.12,sedona-spark-3.4 -pl spark/common -DwildcardSuites=org.apache.sedona.sql.BroadcastIndexJoinSuite,org.apache.sedona.sql.rasterIOTest scalatest:test — 86 tests passed
  • Repository pre-commit hooks passed

@jiayuasu jiayuasu changed the title [GH-3153] Reject one-sided CRS in raster predicates [GH-3153] Reject one-sided CRS in raster operations Jul 28, 2026
@jiayuasu jiayuasu changed the title [GH-3153] Reject one-sided CRS in raster operations [GH-3153] Align CRS handling across raster operations Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RS_ raster predicates: reconsider assuming WGS84 for a missing CRS

1 participant