[gdal-dev] gdal2tiles.py of transparent background vrt/png gives black background tiles

John W. Glendening glendening at drjack.net
Sat Apr 22 22:55:23 PDT 2017


I have been creating a tileset from a .vrt based upon .tif files using
gdal2tiles.py.  The .tif files consist of lines overlaid upon a
background map but I now want to eliminate the background map,
i.e. make that area transparent, so the tiles will have only the lines
on a transparent background, so they can be used as an overlay.

I successfully produced the desired .tif files with transparent
background and created a .vrt.  But using gdal2tiles.py gives a black
background (RGBA=0,0,0,255) where a transparent background is
expected. (The expected lines _are_ present, on top of the black
background.)

Thinking that there might be a problem with the gdal2tiles.py
interpretation of the .vrt, I used gdal_translate to convert it to a
(large!) .png file and used that as the gdal2tiles.py argument
instead.  But the background remains black.  As a check of the png
file, I used gdal_translate to crop out and view a section and its
background was indeed transparent (RGBA=0,0,0,0) in the expected
places.

I also tried two other variants of the gdal2tiles.py file that I found
on the web, one from osgeo (with a 2013 copyright) and one from a
geophython site - with identical results.

I'm hoping for some guidance here.

FYI an extract of gdalinfo for the .vrt file is:
 Driver: VRT/Virtual Raster
 Files: 24ksections.vrt
        /home/glendeni/HIKES/TRAILMAP/TILES/BigSurTrailmap-sectionA1-map.tif
        ...
 Size is 37840, 48993
 Coordinate System is:
 PROJCS["unnamed",
     GEOGCS["unnamedellipse",
         DATUM["unknown",
             SPHEROID["unnamed",6378137,0]],
         PRIMEM["Greenwich",0],
         UNIT["degree",0.0174532925199433]],
     PROJECTION["Mercator_1SP"],
     PARAMETER["central_meridian",0],
     PARAMETER["scale_factor",1],
     PARAMETER["false_easting",0],
     PARAMETER["false_northing",0],
     UNIT["metre",1,
         AUTHORITY["EPSG","9001"]]]
 Origin = (-13565727.275918338447809,4356632.541813874617219)
 Pixel Size = (1.836533043499999,-1.836542168400001)
 Corner Coordinates:
 Upper Left  (-13565727.276, 4356632.542) (121d51'46.81"W,
36d24'21.64"N)
 Lower Left  (-13565727.276, 4266654.831) (121d51'46.81"W, 35d45'
9.94"N)
 Upper Right (-13496232.866, 4356632.542) (121d14'19.40"W,
36d24'21.64"N)
 Lower Right (-13496232.866, 4266654.831) (121d14'19.40"W, 35d45'
9.94"N)
 Center      (-13530980.071, 4311643.687) (121d33' 3.10"W, 36d
4'48.23"N)
 Band 1 Block=128x128 Type=UInt16, ColorInterp=Red
 Band 2 Block=128x128 Type=UInt16, ColorInterp=Green
 Band 3 Block=128x128 Type=UInt16, ColorInterp=Blue
 Band 4 Block=128x128 Type=UInt16, ColorInterp=Alpha

The gdalinfo for the .png created by gdal_translate from the .vrt is:
 Driver: PNG/Portable Network Graphics
 Files: 24ksections.png
        24ksections.png.aux.xml
 Size is 37840, 48993
 Coordinate System is:
 PROJCS["unnamed",
     GEOGCS["unnamedellipse",
         DATUM["unknown",
             SPHEROID["unnamed",6378137,0]],
         PRIMEM["Greenwich",0],
         UNIT["degree",0.0174532925199433]],
     PROJECTION["Mercator_1SP"],
     PARAMETER["central_meridian",0],
     PARAMETER["scale_factor",1],
     PARAMETER["false_easting",0],
     PARAMETER["false_northing",0],
     UNIT["metre",1,
         AUTHORITY["EPSG","9001"]]]
 Origin = (-13565727.275918338447809,4356632.541813874617219)
 Pixel Size = (1.836533043499999,-1.836542168400001)
 Image Structure Metadata:
   INTERLEAVE=PIXEL
 Corner Coordinates:
 Upper Left  (-13565727.276, 4356632.542) (121d51'46.81"W,
36d24'21.64"N)
 Lower Left  (-13565727.276, 4266654.831) (121d51'46.81"W, 35d45'
9.94"N)
 Upper Right (-13496232.866, 4356632.542) (121d14'19.40"W,
36d24'21.64"N)
 Lower Right (-13496232.866, 4266654.831) (121d14'19.40"W, 35d45'
9.94"N)
 Center      (-13530980.071, 4311643.687) (121d33' 3.10"W, 36d
4'48.23"N)
 Band 1 Block=37840x1 Type=UInt16, ColorInterp=Red
 Band 2 Block=37840x1 Type=UInt16, ColorInterp=Green
 Band 3 Block=37840x1 Type=UInt16, ColorInterp=Blue
 Band 4 Block=37840x1 Type=UInt16, ColorInterp=Alpha


-- 
John W. (Jack) Glendening



More information about the gdal-dev mailing list