Skip to content

r.in.gdal: Compare only the horizontal CRS with the project - #7936

Merged
petrasovaa merged 1 commit into
OSGeo:mainfrom
petrasovaa:crs-check-horizontal
Sep 24, 2026
Merged

petrasovaa merged 1 commit into
OSGeo:mainfrom
petrasovaa:crs-check-horizontal

Conversation

@petrasovaa

Copy link
Copy Markdown
Contributor

Bug

Importing data with a compound CRS (e.g., NAD83(2011) / North Carolina (ftUS) + NAVD88 height (ftUS), failed with "Coordinate reference system of dataset does not appear to match current project" even when the project was created from that very file. r.import had no way around it: its temporary project is created from the file too, so the import into it failed the same way.

Project creation stores only the horizontal SRID (EPSG:6543) while the CRS check compared the file's full compound CRS against it with OSRIsSameEx(), which never matches. Geographic 3D data (EPSG:4979) had the same problem in the other direction: a project created from such a file gets PROJ_SRID = EPSG:4979 and then rejects ordinary 2D lat-lon data.

Fix

GRASS has no vertical CRS, so check_projection() now compares the horizontal components only, using OSRDemoteTo2D() on clones of both CRSs (GDAL >= 3.1; GRASS requires 3.7). The import itself is unchanged: it never transforms with the file CRS, and r.proj/v.proj already get a horizontal pipeline from PROJ.

Since this drops information the file carries, the tools now say so:

  • Vertical CRS <NAVD88 height (ftUS)> of the dataset is ignored
  • The vertical component of the dataset CRS is ignored (geographic 3D)

The same change is applied to the four copies of the check code in r.in.gdal, r.external, v.in.ogr and v.external. The lidar/PDAL importers compare via G_compare_projections(), which is already horizontal only.

Tests

New pytest files for the raster tools (r.in.gdal, r.external) and the vector tools (v.in.ogr, v.external), with data generated as small GDAL/OGR VRT files, covering compound and geographic 3D CRSs in both project and file, the message, and that a different horizontal CRS is still rejected. Against the unfixed build 20 of the 28 tests fail.

--

Implemented with the help of Claude Code.

Data with a compound or geographic 3D CRS was rejected even by a project
created from the same file. Same fix in r.external, v.in.ogr and
v.external, plus a message that the vertical component is ignored.
@github-actions github-actions Bot added vector Related to vector data processing raster Related to raster data processing Python Related code is in Python C Related code is in C module tests Related to Test Suite labels Sep 22, 2026
@cwhite911

Copy link
Copy Markdown
Contributor

What about adding support for vertical CRS on projects? Make it optional but enforce it if it is set.

@petrasovaa

Copy link
Copy Markdown
Contributor Author

What about adding support for vertical CRS on projects? Make it optional but enforce it if it is set.

This is a bug fix, adding that feature would be different PR, likely more complicated.

@metzm metzm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this fix!
As I understand, a vertical CRS is specific to a dataset, and it is perfectly valid to have different datasets with the same horizontal, but different vertical CRSs. GDAL can on reprojection apply vertical CRS info to e.g. elevation values, I've been testing this before.
Users should reproject to a 2D CRS with GDAL to be on the safe side before importing into GRASS.

@metzm

metzm commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Fixes #7336

@petrasovaa
petrasovaa merged commit d24a5e0 into OSGeo:main Sep 24, 2026
26 checks passed
@petrasovaa
petrasovaa deleted the crs-check-horizontal branch September 24, 2026 18:40
@github-actions github-actions Bot added this to the 8.6.0 milestone Sep 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C Related code is in C module Python Related code is in Python raster Related to raster data processing tests Related to Test Suite vector Related to vector data processing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants