Skip to content

r.in.gdal/r.external: store GDAL band metadata as semantic labels#7028

Open
sakirr05 wants to merge 13 commits intoOSGeo:mainfrom
sakirr05:feat-gdal-band-semantic-label-clean
Open

r.in.gdal/r.external: store GDAL band metadata as semantic labels#7028
sakirr05 wants to merge 13 commits intoOSGeo:mainfrom
sakirr05:feat-gdal-band-semantic-label-clean

Conversation

@sakirr05
Copy link
Contributor

@sakirr05 sakirr05 commented Feb 2, 2026

Fixes #6227

This PR adds support for storing GDAL raster band metadata as GRASS raster
semantic labels during import with r.in.gdal and r.external.

When available, the GDAL band description (preferred) or band name is written
to the raster semantic label, allowing tools to understand band meaning
without changing raster names or band numbering.

Scope:

  • Applies to r.in.gdal and r.external
  • Stores band metadata as raster semantic labels
  • No new CLI options and no change to raster naming

Example:
A raster with GDAL band descriptions "NDVI" and "EVI" will result in GRASS
rasters with semantic labels:

semantic_label=NDVI
semantic_label=EVI

Tests:

  • Added tests for r.in.gdal and r.external using existing GDAL test data

sakirr added 4 commits January 31, 2026 19:13
…els (OSGeo#6227)

- Query GDAL band description and BANDNAME; prefer description over name
- Validate and store as raster semantic label via Rast_write_semantic_label
- Skip silently when missing, invalid, or duplicate (multi-band)
- Add tests for semantic label from band metadata (elevation.tif)
- No naming or CLI changes; backward compatible
@github-actions github-actions bot added raster Related to raster data processing Python Related code is in Python C Related code is in C libraries module general tests Related to Test Suite labels Feb 2, 2026
@github-actions github-actions bot added the CI Continuous integration label Feb 2, 2026

# This will fail if the build failed.
grass --version
command -v grass >/dev/null 2>&1 && grass --version || echo "GRASS not installed yet"
Copy link
Member

Choose a reason for hiding this comment

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

How is this supposed to work? The script tries to run GRASS in the next line anyway.

You are just silencing the error message here in order to get it in the next line... As line 11 says, this will fail (and is supposed to fail) if the build fails...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing this out, I’ll revert the print_versions.sh change and all unrelated security/CI changes so the PR stays focused purely on the GDAL semantic label feature

Copy link
Member

@ninsbl ninsbl left a comment

Choose a reason for hiding this comment

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

Hm, ... I am not a C expert, but the implementation does not seem right to me. You re-implement existing library code in the tools and seem to duplicate code across r.external / r.in.gdal.
What is the motivation /reasoning for that?

@ninsbl
Copy link
Member

ninsbl commented Feb 3, 2026

BTW: Will your proposed changes change the behavior of r.in.gdal/r.external? Here I think esp. of map/file names of multiband data.
It would be valuable to have a multiband raster to test API stability...

@sakirr05
Copy link
Contributor Author

sakirr05 commented Feb 3, 2026

@ninsbl One quick follow up- do you see this as implicit behavior that’s fine to keep as-is, or would you prefer it to be made explicit via a test or docs?

@sakirr05 sakirr05 requested a review from ninsbl February 4, 2026 21:58
Copy link
Member

@ninsbl ninsbl left a comment

Choose a reason for hiding this comment

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

The mechanics look in principle OK to me. That said, I am no C expert. So, I hope someone more knowledgeable could chime in!

What I noticed is that the functions get_gdal_band_semantic_label and set_semantic_label_from_gdal are duplicated in the tools (r.in.gdal, _r.external). That can probably be solved without function duplication ?
Also, not 100% sure if set_semantic_label_from_gdal is needed as a function at all...

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 CI Continuous integration general libraries module Python Related code is in Python raster Related to raster data processing tests Related to Test Suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feat] r.in.gdal/r.external: Import band names / description as semantic label and use as suffix

2 participants