Skip to content

Keep NoData transparent in the documented hillshade colour-relief pipeline - #732

Closed
borismasis wants to merge 4 commits into
cyclosm:masterfrom
borismasis:borism/hillshade-transparent-nodata
Closed

borismasis wants to merge 4 commits into
cyclosm:masterfrom
borismasis:borism/hillshade-transparent-nodata

Conversation

@borismasis

Copy link
Copy Markdown

Summary

  • Explicitly map GDAL hillshade NoData pixels to transparent RGBA in dem/shade.ramp.
  • Retain existing valid shadow/highlight stops and behaviour for inputs without NoData metadata.
  • Document preservation of NoData metadata and regeneration of existing derived rasters/tiles.
  • Add synthetic regression tests for both the ramp and the documented DEM-to-colour-relief procedure.

Why

gdaldem hillshade marks missing elevation as NoData=0. Without an nv entry, the current ramp's numeric zero stop becomes black with alpha220. Missing terrain is therefore drawn as a dark overlay rather than left unshaded.

Test plan

python3 -m unittest discover -s scripts/tests -p 'test_hillshade_nodata.py' -v

Four tests pass with GDAL3.12.2. Before the change, the two NoData tests fail. Valid shadow/highlight stops and valid numeric zero without NoData metadata retain their original values.

Also rendered the synthetic before/after colour-relief rasters using Mapnik4.3.2 with the existing hillshade settings (bilinear, multiply, opacity0.85). The missing-data area changes from a dark overlay to the untouched background, while valid flat terrain is unchanged.

Scope

This fixes a reproducible problem in the documented hillshade preparation procedure. It does not establish the full active configuration or input provenance of the official tile servers, and it does not claim a verified fix for the broad low-zoom gradient currently visible in some official z4 tiles. Existing semi-transparent terrain rasters and rendered tiles need regeneration to adopt the ramp correction.

Contribution checks

  • Changelog updated.
  • scripts/generate_taginfo.py project.mml was run. Its output is byte-identical to the upstream baseline with the same dependencies. The existing checked-in tag list differs from that generator output already, so this terrain-only change leaves taginfo.json untouched rather than remove unrelated tags.
  • No CartoCSS, SQL, MML or legend changes, so the style XML inputs are unchanged.

Synthetic rendering evidence

The rendering check uses a generated DEM, not official site imagery. The fixture is EPSG:3857, extent (0, 0, 256, 256), with missing data on the left and valid flat terrain on the right. With Mapnik's bilinear/multiply raster settings at opacity 0.85:

Area Original ramp Corrected ramp
Missing elevation RGB (49, 57, 57) RGB (181, 208, 208)
Valid flat terrain RGB (181, 208, 208) RGB (181, 208, 208)

The integration regression additionally uses valid sloping terrain with nonzero alpha, writes colour relief to GeoTIFF, and reopens an on-disk VRT before asserting transparency and preservation of valid shading.

Screenshot upload was unavailable through the paired browser's file-upload interface. The synthetic fixture and exact regression command above are provided for reproducibility.

@Phyks

Phyks commented Nov 12, 2026

Copy link
Copy Markdown
Member

Hi,

Thanks for this MR. However, before reviewing it it would help me have a bit more context on how you noticed this issue and what lead you to fix it. The tests fixtures are not real world examples, and no screenshot is attached. The hillshades documentation is heavily based on OpenTopoMap, which likely has the same behavior/issue: https://github.com/der-stefan/OpenTopoMap/blob/master/mapnik/HOWTO_DEM.md.

Additionally, since it is rather obvious a large part of this contribution is AI-assisted, I would welcome a disclaimer about it and more details on what work was contributed by AI and what is the human contribution/oversight about it.

Thanks

@borismasis

Copy link
Copy Markdown
Author

Thanks for asking for this context. The connection between the observed site issue and this patch needs to be stated more explicitly, and the AI-assistance disclosure should have been included from the start.

What prompted the investigation

Boris reported a broad black gradient when viewing the full CyclOSM basemap over Europe at about map zoom 3.185, centered on approximately 43.07915 N, 14.28667 E. The viewport requests z4 raster tiles. We isolated the basemap from the application overlays: the gradient was already in the provider-delivered PNGs, and remained with those overlays removed. These are the real-world images that prompted the investigation, not outputs of the synthetic test:

Official CyclOSM tile 4/8/5 observed with the dark gradient

Official CyclOSM tile 4/8/6 observed with the dark gradient

At the time of capture (12 November 2026), their SHA-256 values were 0944c387352abec0e5c690c671f5da5d8ca2f1e138ff4aa624530548c61cd483 and be603fd7d274b698dab62aa4b031cfe44e966bab1ef881de6d06be9a5f103d45. The image links are to the live provider, so they can change if those tiles are regenerated. This browser's file-upload interface denied uploading saved screenshots, so these links expose the original provider images directly rather than claim that an application screenshot has been attached.

Why this particular patch

Investigating the published elevation-data instructions led to a separately reproducible problem: gdaldem hillshade marks missing elevation as NoData=0; gdaldem color-relief -alpha with the existing shade.ramp maps it to black with alpha 220 because there is no nv stop. Adding a transparent nv stop fixes that specific behavior while preserving the valid numeric ramp. The tests deliberately isolate this behavior and do not purport to reproduce the production terrain dataset.

I cannot establish that this is the cause of the two official tiles above. The active production terrain configuration and source raster/mask/overview metadata were not available in the public sources inspected. This PR should be reviewed as a correction to the documented color-relief procedure, not as a demonstrated fix of the official low-zoom gradient. It would not help a deployed pipeline that bypasses shade.ramp.

I also read the OpenTopoMap document you linked. It explicitly fills DEM voids first and has separate grayscale gdaldem hillshade output. Its color-relief commands operate on the warped elevation raster. That is not the exact hillshade-to-RGBA-ramp sequence tested here, so I have not established the same issue in OpenTopoMap's actual pipeline or tiles.

AI assistance and human oversight

This contribution and this reply are substantially AI-assisted. The AI agent performed the source/issue investigation, authored the patch, tests and documentation, executed the reported local tests and rendering probes, and submitted the PR through Boris's authorized browser session. A separate AI agent reviewed the candidate; that was not a human code review.

Boris's human contribution was reporting the visual problem, directing the investigation and explicitly authorizing the upstream PR. There has not been a separate human audit of the code, the test results or the production-cause hypothesis, and I should not imply otherwise. Maintainer review and production-data validation are still needed. The public evidence and reproducible tests above are intended to make that review possible.

@Phyks Phyks closed this Nov 12, 2026
@borismasis

Copy link
Copy Markdown
Author

Hi @Phyks - thanks for taking a look! Here's a live link showing the issue: https://www.cyclosm.org/#map=2/-7.1/-83.0/cyclosm - we're also seeing it when trying to use the tiles

@Phyks

Phyks commented Nov 12, 2026

Copy link
Copy Markdown
Member

AFAIK the hillshades used online on cyclosm.org are not the same ones as the ones described in the documentation, since they have been factored out with another codebase in use by openstreetmap-fr. Then, the live issue should be reported to https://github.com/osm-fr/infrastructure/.

cc-ing @cquest who deployed these online hillshades.

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.

2 participants