Skip to content

gdal_rasterize all_touched not working as expected #12129

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

Closed
johanvdw opened this issue Apr 11, 2025 · 4 comments · Fixed by #12195
Closed

gdal_rasterize all_touched not working as expected #12129

johanvdw opened this issue Apr 11, 2025 · 4 comments · Fixed by #12195

Comments

@johanvdw
Copy link
Member

What is the bug?

gdal_rasterize with the option all-touched no longer correctly converts all pixels.

The image below shows:

  • the shapefile
  • dark blue - the resulting raster
  • pink: the two pixels which are missing

The problem does not occur in version 3.5.1, but occurs in version 3.6.2 and current master.

Image

Steps to reproduce the issue

Command to reproduce

gdal_rasterize -q -a_nodata -9999 -at -burn 1 -l mask -of GTiff -te 163600 167680 164000 168000 -tr 20 20 -co COMPRESS=DEFLATE mask.shp mask.tif

gdal-rasterize.zip

Versions and provenance

  • versions 3.5.1 (correct) (compiled from source in debian linux)
  • version 3.6.2 (incorrect) (debian bookworm package)
  • version GDAL 3.11.0dev-c4a2e0b926: incorrect (compiled from source in debian linux)

Additional context

originally reported by @Sachagobeyn in watem-sedem/pywatemsedem#55

@jratike80
Copy link
Collaborator

jratike80 commented Apr 11, 2025

I can confirm with GDAL 3.10.2 on Windows . Maybe easier to check the result with an 8-bit output
gdal_rasterize -q -a_nodata 255 -at -burn 1 -of GTiff -te 163600 167680 164000 168000 -tr 20 20 -co COMPRESS=DEFLATE -ot byte mask.shp mask8.tif

And the geometry as WKT is
POLYGON (( 163600 167680, 163600 168000, 164000 168000, 164000 167680, 163600 167680 ))

@johanvdw
Copy link
Member Author

bisect reveals an issue with:
[9f57e09] gdal_rasterize: fix ALL_TOUCHED on polygons whose boundaries coordinates are aligned on pixels (fixes #6414) (#6415)

@johanvdw
Copy link
Member Author

And the geometry as WKT is POLYGON (( 163600 167680, 163600 168000, 164000 168000, 164000 167680, 163600 167680 ))

No that's a box containing all data, not the actual geometry.

That would be:
POLYGON((163899.277344 167988.154297, 163909.339662 167743.621913, 163628.300781 167745.908203, 163661.337891 167785.683594, 163700.000000 167880.000000, 163780.000000 167860.000000, 163835.751953 167942.617188, 163899.277344 167988.154297))

@jratike80
Copy link
Collaborator

No that's a box containing all data, not the actual geometry.

Correct. By the same I learned that OpenJUMP creates a polygon geometry for rasters that it opens. That was what I accidentally copied.

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 a pull request may close this issue.

2 participants