Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raster labeling #59753

Merged
merged 25 commits into from
Dec 18, 2024
Merged

Raster labeling #59753

merged 25 commits into from
Dec 18, 2024

Conversation

nyalldawson
Copy link
Collaborator

@nyalldawson nyalldawson commented Dec 5, 2024

Allows raster pixels to be labeled with the value taken from a raster band.

Labels are registered with the labeling engine, so participate in label conflict resolution and overlap avoidance

Options include

  • Selection of band to take values from
  • Using QgsNumericFormat to customise the number format for the labels
  • Uses text renderer, so supports buffers, shadows, etc
  • Label priority
  • Scale dependant visibility
  • Optional pixel size dependent visibilty, ie show only when pixels are > 4mm in size
  • Z index control, overlap avoidance mode
  • Option for showing values resampled over neighbouring pixels

Fixes #14408

Funded by Canton de Neuchâtel

Peek.2024-12-05.15-41.mp4

@nyalldawson nyalldawson added Feature Rasters Related to general raster layer handling (not specific data formats) Needs Documentation When merging a labeled PR, an issue will be created in the Doc repo. Changelog Items that are queued to appear in the visual changelog - remove after harvesting labels Dec 5, 2024
@qgis-bot
Copy link
Collaborator

qgis-bot commented Dec 5, 2024

@nyalldawson

This pull request has been tagged for the changelog.

  • The description will be harvested so please provide a "nearly-ready" text for the final changelog
  • If possible, add a nice illustration of the feature. Only the first one in the description will be harvested (GIF accepted as well)
  • If you can, it's better to give credits to your sponsor, see below for different formats.

You can edit the description.

Format available for credits
  • Funded by NAME
  • Funded by URL
  • Funded by NAME URL
  • Sponsored by NAME
  • Sponsored by URL
  • Sponsored by NAME URL

Thank you!

@qgis-bot
Copy link
Collaborator

qgis-bot commented Dec 5, 2024

@nyalldawson
This pull request has been tagged as requiring documentation.

A documentation ticket will be opened at https://github.com/qgis/QGIS-Documentation when this PR is merged.

Please update the description (not the comments) with helpful description and screenshot to help the work from documentors.
Also, any commit having [needs-doc] or [Needs Documentation] in will see its message pushed to the issue, so please be as verbose as you can.

Thank you!

@github-actions github-actions bot added this to the 3.42.0 milestone Dec 5, 2024
Copy link

github-actions bot commented Dec 5, 2024

🪟 Windows builds

Download Windows builds of this PR for testing.
Debug symbols for this build are available here.
(Built from commit 236dbd6)

🪟 Windows Qt6 builds

Download Windows Qt6 builds of this PR for testing.
(Built from commit 236dbd6)

@nyalldawson nyalldawson closed this Dec 5, 2024
@nyalldawson nyalldawson reopened this Dec 5, 2024
@saberraz
Copy link
Contributor

saberraz commented Dec 5, 2024

Very nice feature. A couple of silly questions maybe:

  • Does this work with expression engine. Lets say I have a temporal raster where times are stored as a band. Can I then show the raster pixel based on the band and then see the label changes as I move the temporal controller?!
  • Will there be an option to merge the same labels for neighboring cells?

@nyalldawson
Copy link
Collaborator Author

nyalldawson commented Dec 5, 2024

@saberraz

Does this work with expression engine. Lets say I have a temporal raster where times are stored as a band. Can I then show the raster pixel based on the band and then see the label changes as I move the temporal controller?!

No -- right now the band selection is fixed, and you get the pixel values only. (There's kind-of expression support via the "custom expression" option in the number format panel, but that's limited).

I think it'd be nice for a follow up to add an expression based labels mode, so eg you can get all band values as a list and choose how to display these (but that's not in my current scope).

Will there be an option to merge the same labels for neighboring cells?

It's not planned, but I do have a follow up coming which will allow the labels to show downsampled values (eg labeling only every second pixel)

@saberraz
Copy link
Contributor

saberraz commented Dec 5, 2024

Great work and thanks for the explanation.

@qgis qgis deleted a comment from github-actions bot Dec 6, 2024
@qgis qgis deleted a comment from github-actions bot Dec 6, 2024
@qgis qgis deleted a comment from github-actions bot Dec 6, 2024
@nyalldawson nyalldawson force-pushed the raster_labels_pt1 branch 2 times, most recently from ee88455 to 6d556ba Compare December 9, 2024 05:19
Copy link

github-actions bot commented Dec 9, 2024

Tests failed for Qt 6

One or more tests failed using the build from commit 6d556ba

resampling

resampling

Test failed at test_render_resampled at tests/src/python/test_qgsrasterlabeling.py:324

Rendered image did not match tests/testdata/control_images/raster_labeling/expected_resampling/expected_resampling.png (found 9080 pixels different)

The full test report (included comparison of rendered vs expected images) can be found here.

Further documentation on the QGIS test infrastructure can be found in the Developer's Guide.

@nyalldawson
Copy link
Collaborator Author

nyalldawson commented Dec 17, 2024

I would LOVE a review before I leave on Christmas holidays on Friday please! (Otherwise this will likely miss 3.42 deadline, I'm away from my computer for a month)

Ping @nirvn @m-kuhn @3nids @alexbruy @troopa81

@nirvn
Copy link
Contributor

nirvn commented Dec 18, 2024

@nyalldawson , I'll do it.

Copy link
Contributor

@nirvn nirvn left a comment

Choose a reason for hiding this comment

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

A couple of comments.

We'll need the labeling panel to also be featured in the raster properties dialog before we ship the functionality.

But beyond that, big thanks! It's something I was looking for multiple times.

src/core/labeling/qgspallabeling.cpp Outdated Show resolved Hide resolved
src/core/raster/qgsrasterlayerrenderer.cpp Outdated Show resolved Hide resolved
src/core/raster/qgsrasterlabeling.cpp Outdated Show resolved Hide resolved
src/core/raster/qgsrasterlabeling.cpp Outdated Show resolved Hide resolved
src/core/raster/qgsrasterlabeling.cpp Show resolved Hide resolved
src/core/raster/qgsrasterlabeling.cpp Show resolved Hide resolved
src/gui/raster/qgsrasterlabelsettingswidget.cpp Outdated Show resolved Hide resolved
src/gui/raster/qgsrasterlabelingwidget.h Show resolved Hide resolved
Allows raster pixels to be labeled with the value taken from a raster
band.

Labels are registered with the labeling engine, so participate in
label conflict resolution and overlap avoidance

Options include

- Selection of band to take values from
- Using QgsNumericFormat to customise the number format for the labels
- Uses text renderer, so supports buffers, shadows, etc
- Label priority
- Scale dependant visibility
- Optional pixel size dependent visibilty, ie show only when pixels are
> 4mm in size
- Z index control, overlap avoidance mode

Fixes qgis#14408
@nyalldawson
Copy link
Collaborator Author

@nirvn

We'll need the labeling panel to also be featured in the raster properties dialog before we ship the functionality.

Ok, done!

@nyalldawson nyalldawson merged commit 851e360 into qgis:master Dec 18, 2024
31 checks passed
@nyalldawson nyalldawson deleted the raster_labels_pt1 branch December 18, 2024 09:12
@qgis-bot
Copy link
Collaborator

@nyalldawson
A documentation ticket has been opened at qgis/QGIS-Documentation#9490
It is your responsibility to visit this ticket and add as much detail as possible for the documentation team to correctly document this change.
Thank you!

@m-kuhn
Copy link
Member

m-kuhn commented Dec 19, 2024

Thanks for this, I can think of a couple of times that would have been useful!

@nyalldawson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog Items that are queued to appear in the visual changelog - remove after harvesting Feature Needs Documentation When merging a labeled PR, an issue will be created in the Doc repo. Rasters Related to general raster layer handling (not specific data formats)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show raster values on screen when zoomed-in enough.
5 participants