[GIS] Tiling rgba geotiffs using vrt rather than gdal_warp

gdalgdal2tilesgeotiff-tiff

I've carefully cut the collar off a set of USGS geotifs and I'd like to run through them with gdal2tiles but producing a vrt that undersands the alpha layer, or having gdal2tiles overlap two source files into one tile is not working. Some things I have tried have made all black pixels transparent. Other attempts rendered the transparent borders on my source files as if they were solid white, so when one tile is made from two adjoining tifs the transparent border from one covers up the useful content of another. Here is my process, maybe someone can tell me a conversion step I'm missing:

  • Download regular USGS geotif from Topoquest
  • gdal_translate -expand rgba -co COMPRESS=LZW orginal.tif translated.tif
  • Open translated.tif in Photoshop, cut off the collar, save.
  • gdalcopyproj.py translated.tif prepared.tif

Do that for all of them

  • gdalbuildvrt temp.vrt *.tif
  • gdal2tiles.py temp.vrt tiles

P.S. I can merge them all smoothly with gdal_warp but on this group of 30 it is making a combined geotiff of 51223 x 65163 and on other sets there will be lots of wasted space when the source tifs are in a diagonal line but gdal_warp will create a rectangular output.

Best Answer

GDAL supports a mask layer, but it also supports a "no data" colour which I tend to use because it cuts the size of the final image down by 25%. So the steps I would use with your data, after cutting off the collar is:

gdal_translate -expand rgb -gcp <pixel/coordinate pairs> -co TILED=YES -a_srs <EPSG code for the map's projection> -a_nodata 255 255 255 original.tif translated.tif

Note, I've put in Ground Control Points (GCPs) and a projection which you'll have to determine empirically. Also note I've assigned pure white to the nodata value.

These images are still not properly georeferenced however, as they still only have GCPs rather than proper coordinates. So you will need to run gdalwarp:

gdalwarp -t_srs EPSG:4326 -co TILED=YES -srcnodata 255 255 255 -dstnodata 255 255 255 translated.tif warped.tif

Note again the explicit setting of the nodata values. This is probably overkill, but it doesn't hurt, and I've had gdalwarp ignore what I thought was implicit nodata vales.

Next, you need to run gdalbuildvrt like you have it, but I usually explicitly specify the nodata values again, to be on the safe side:

gdalbuildvrt -srcnodata 255 255 255 -vrtnodata 255 255 255 temp.vrt <warped files>.tif

Edit

This may be closer to what you want:

gdalbuildvrt -srcnodata 255 255 255 -hidenodata temp.vrt <warped files>.tif

Finally, you can call gdal2tiles.py as you have it.