Opened 14 years ago

Closed 5 years ago

#3596 closed enhancement (wontfix)

rfe: gdal2tiles.py skip empty tiles

Reported by: hamish Owned by: warmerdam
Priority: normal Milestone: closed_because_of_github_migration
Component: Utilities Version: svn-trunk
Severity: minor Keywords: gdal2tiles
Cc:

Description

Hi,

when using gdal2tiles.py with a source image which gets substantially rotated in the gdalwarp, you can end up with entire rows of tiles containing nothing but blank tiles around the edges. It would be nice to skip them.

here's a method I've used in a similar situation in the past:

  • check Band stats with gdalinfo by looking at the R,G,B bands and seeing if the (6) max and min values of all three bands are identical. (presumably this fails on large solid greyscale fill...)

It works by stacking the 6 numbers in a line and then running uniq and testing if there is only 1 number remaining. Presumably this could be done much more cleanly in Python; maybe remove the head -n 3 to take the 4th alpha band into account; or just test to see if the alpha band is 100% transparent across the entire tile?

    # check if image is empty
    CNT=`gdalinfo -mm -noct -nomd "${OUTFILE}.tif" | grep 'Min/Max' | \
       cut -f2 -d= | head -n 3 | tr ',' '\n' | uniq | wc -l`

    if [ "$CNT" -eq 1 ] ; then
       echo "Skipping blank image ..."
       \rm "${OUTFILE}.tif"
       continue
    fi

thanks, Hamish

Attachments (2)

gdal2tiles_skipblanks.py (99.9 KB ) - added by pwillis 10 years ago.
pwillis: Added some code to skip blank tiles (this is being tested)
gdal2tiles_skipblanks.patch (9.0 KB ) - added by hamish 10 years ago.
Patch supporting skipping blank tiles

Download all attachments as: .zip

Change History (5)

by pwillis, 10 years ago

Attachment: gdal2tiles_skipblanks.py added

pwillis: Added some code to skip blank tiles (this is being tested)

comment:1 by pwillis, 10 years ago

I added my current version of gdal2tiles.py from gdal_1.10.1. I had the same blank tile crashing issue and used the debugger to find out what was going on.

If someone 'diff' s my code against the the original source they can see the changes I made.

Peter

by hamish, 10 years ago

Attachment: gdal2tiles_skipblanks.patch added

Patch supporting skipping blank tiles

in reply to:  1 comment:2 by hamish, 10 years ago

Replying to pwillis:

I added my current version of gdal2tiles.py from gdal_1.10.1. I had the same blank tile crashing issue and used the debugger to find out what was going on.

If someone 'diff' s my code against the the original source they can see the changes I made.

Patch of 1.10.1 vs. Peter's version attached to ticket.

Hamish

comment:3 by Even Rouault, 5 years ago

Milestone: closed_because_of_github_migration
Resolution: wontfix
Status: newclosed

This ticket has been automatically closed because Trac is no longer used for GDAL bug tracking, since the project has migrated to GitHub. If you believe this ticket is still valid, you may file it to https://github.com/OSGeo/gdal/issues if it is not already reported there.

Note: See TracTickets for help on using tickets.