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

gdal2tiles: Fix case where --exclude still writes fully transparent tiles #9532

Merged
merged 3 commits into from
Apr 2, 2024

Conversation

kevinmehall
Copy link
Contributor

The alpha channel is only checked for a fully transparent tile when the source region is of nonzero size. When there are zero pixels to copy, the tile will also be transparent and should be skipped with --exclude.

This occurs when the edge of the input is aligned with the tile grid. To reproduce the issue, create a GeoTIFF with:

$ gdal_create -outsize 1536 1536 -a_srs EPSG:3857 -a_ullr -114.65554242953658 114.65554242953658 114.65554242953658 -114.65554242953658 -bands 4 -burn 0 -co COMPRESS=DEFLATE empty.tif

This will be fully transparent so should produce no tiles with --exclude, but currently produces tiles along one edge:

$ python3 swig/python/gdal-utils/osgeo_utils/gdal2tiles.py --exclude --xyz -w none empty.tif -z 11-20 /tmp/tiled_out 
...
$ find /tmp/tiled_out/20
/tmp/tiled_out/20
/tmp/tiled_out/20/524288
/tmp/tiled_out/20/524288/524291.png
/tmp/tiled_out/20/524287
/tmp/tiled_out/20/524287/524291.png
/tmp/tiled_out/20/524285
/tmp/tiled_out/20/524285/524291.png
/tmp/tiled_out/20/524289
/tmp/tiled_out/20/524289/524291.png
/tmp/tiled_out/20/524286
/tmp/tiled_out/20/524286/524291.png
/tmp/tiled_out/20/524284
/tmp/tiled_out/20/524284/524291.png
/tmp/tiled_out/20/524290
/tmp/tiled_out/20/524290/524291.png

…iles

The alpha channel is only checked for a fully transparent tile when
the source region is of nonzero size. When there are zero pixels
to copy, the tile will also be transparent and should be skipped
with `--exclude`.
@rouault rouault added this to the 3.9.0 milestone Mar 23, 2024
@rouault
Copy link
Member

rouault commented Mar 23, 2024

@kevinmehall Your fix is reasonable, but I'm wondering if an even better fix wouldn't be to add a check before

# Read the source raster if anything is going inside the tile as per the computed
to avoid adding such tiles at all into the tile_details[] list. The --exclude option was designed more to exclude fully transparent tiles "in the middle" of the covered area, rather than tiles at the edges that have no area at all.

@kevinmehall kevinmehall force-pushed the gdal2tiles-exclude-aligned branch from 2517e51 to 3a23448 Compare March 29, 2024 23:10
@kevinmehall kevinmehall force-pushed the gdal2tiles-exclude-aligned branch from 3a23448 to 1a8dbe4 Compare March 29, 2024 23:16
@kevinmehall
Copy link
Contributor Author

Agreed. Added a commit (you can squash-merge them if you'd prefer).

I'm also not sure whether it should check self.options.exclude_transparent or be enabled unconditionally. I didn't dig into geo_query deep enough to tell whether this can result in a non-rectangular set of tiles, or if it will always cut off an entire row or column of tiles that is only there due to rounding differences.

@rouault rouault merged commit a6efaae into OSGeo:master Apr 2, 2024
32 checks passed
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