3

I have a tif file with 3 bands and want to tile it with gdal2tiles.py. After experimenting this now works well, except for the issue that points around the edges, not in the original image, are appearing in the PNG images as black and not transparent. I have tried various combinations of gdal_translate, gdalwarp, srcnodata, and dstalpha, but have not solved it. Presumably there is some simple thing I need to do?

My last run was

gdal2tiles.py --profile=mercator –-resampling=lanczos –-s_srs=EPSG:27700 --srcnodata=255 -z 13-14 input output

The resulting tiles can be seen here in my OL3 system.

The gdalinfo for the input file and one of the edge output tiles (which actually contains none of the map) follow.

Input file

Driver: GTiff/GeoTIFF
Files: C:\Users\Peter_2\Documents\Mapping\Data\NLS 3xHunts XIX.14\114489818.tif
Size is 17229, 12065
Coordinate System is:
PROJCS["OSGB_1936_British_National_Grid",
    GEOGCS["GCS_OSGB 1936",
        DATUM["OSGB_1936",
            SPHEROID["Airy 1830",6377563.396,299.3249646000043,
                AUTHORITY["EPSG","7001"]],
            AUTHORITY["EPSG","6277"]],
        PRIMEM["Greenwich",0],
        UNIT["degree",0.0174532925199433]],
    PROJECTION["Transverse_Mercator"],
    PARAMETER["latitude_of_origin",49],
    PARAMETER["central_meridian",-2],
    PARAMETER["scale_factor",0.9996012717],
    PARAMETER["false_easting",400000],
    PARAMETER["false_northing",-100000],
    UNIT["metre",1,
        AUTHORITY["EPSG","9001"]]]
Origin = (533646.656691546550000,273318.915670182380000)
Pixel Size = (0.159509410413376,-0.159509410413376)
Metadata:
  AREA_OR_POINT=Area
Image Structure Metadata:
  INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left  (  533646.657,  273318.916) (  0d 2'16.78"W, 52d20'28.52"N)
Lower Left  (  533646.657,  271394.435) (  0d 2'19.54"W, 52d19'26.27"N)
Upper Right (  536394.844,  273318.916) (  0d 0' 8.36"E, 52d20'26.09"N)
Lower Right (  536394.844,  271394.435) (  0d 0' 5.55"E, 52d19'23.83"N)
Center      (  535020.751,  272356.675) (  0d 1' 5.60"W, 52d19'56.18"N)
Band 1 Block=17229x1 Type=Byte, ColorInterp=Red
  Minimum=40.000, Maximum=254.000, Mean=241.642, StdDev=20.476
  NoData Value=255
  Metadata:
    STATISTICS_MAXIMUM=254
    STATISTICS_MEAN=241.64176511056
    STATISTICS_MINIMUM=40
    STATISTICS_STDDEV=20.47588938378
Band 2 Block=17229x1 Type=Byte, ColorInterp=Green
  Minimum=42.000, Maximum=254.000, Mean=240.687, StdDev=21.626
  NoData Value=255
  Metadata:
    STATISTICS_MAXIMUM=254
    STATISTICS_MEAN=240.6865420862
    STATISTICS_MINIMUM=42
    STATISTICS_STDDEV=21.626479151752
Band 3 Block=17229x1 Type=Byte, ColorInterp=Blue
  Minimum=35.000, Maximum=248.000, Mean=225.614, StdDev=20.731
  NoData Value=255
  Metadata:
    STATISTICS_MAXIMUM=248
    STATISTICS_MEAN=225.61397171369
    STATISTICS_MINIMUM=35
    STATISTICS_STDDEV=20.731247427002

One of the output tiles

As you can see this tile just looks like a black rectangle down the edge of a transparent area. The part covered by the tiff has come out transparent, but the part that is not covered by the tiff has come out black.

this is the png image[2]

Driver: PNG/Portable Network Graphics
Files: C:\Users\Peter_2\Documents\Mapping\Software\M4OPS\OPS\HcN Holywell-cum-Needingworth\AA Not to FTP\working\00967 Hunts XIX_14 1885X\14\8192\10996.png
Size is 256, 256
Coordinate System is `'
Image Structure Metadata:
  INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left  (    0.0,    0.0)
Lower Left  (    0.0,  256.0)
Upper Right (  256.0,    0.0)
Lower Right (  256.0,  256.0)
Center      (  128.0,  128.0)
Band 1 Block=256x1 Type=Byte, ColorInterp=Red
  Minimum=0.000, Maximum=255.000, Mean=1.702, StdDev=19.920
  Mask Flags: PER_DATASET ALPHA 
  Metadata:
    STATISTICS_MAXIMUM=255
    STATISTICS_MEAN=1.7024536132812
    STATISTICS_MINIMUM=0
    STATISTICS_STDDEV=19.919693448821
Band 2 Block=256x1 Type=Byte, ColorInterp=Green
  Minimum=0.000, Maximum=255.000, Mean=1.702, StdDev=19.920
  Mask Flags: PER_DATASET ALPHA 
  Metadata:
    STATISTICS_MAXIMUM=255
    STATISTICS_MEAN=1.7024536132812
    STATISTICS_MINIMUM=0
    STATISTICS_STDDEV=19.919693448821
Band 3 Block=256x1 Type=Byte, ColorInterp=Blue
  Minimum=0.000, Maximum=255.000, Mean=1.702, StdDev=19.920
  Mask Flags: PER_DATASET ALPHA 
  Metadata:
    STATISTICS_MAXIMUM=255
    STATISTICS_MEAN=1.7024536132812
    STATISTICS_MINIMUM=0
    STATISTICS_STDDEV=19.919693448821
Band 4 Block=256x1 Type=Byte, ColorInterp=Alpha
  Minimum=0.000, Maximum=255.000, Mean=5.067, StdDev=34.660
  Metadata:
    STATISTICS_MAXIMUM=255
    STATISTICS_MEAN=5.0668334960937
    STATISTICS_MINIMUM=0
    STATISTICS_STDDEV=34.660054173433
  • Black areas appear because tiles are warped to another coordinate system but they should have been marked as nodata areas with the alpha channel. I can't say why OpenLayers does not handle the transparency automatically. – user30184 Dec 20 '16 at 19:56
  • 1
    I don't think it is an OpenLayers problem. I have added the actual png image of the tile I did the gdalinfo for, and the problem is in there. My guess is that the black area should have been marked as nodata with the alpha channel, but it was not. – Peter Cooper Dec 21 '16 at 10:24
0

A workaround for this issue is to first use gdalwarp to transform the input image into EPSG:3857 so that no re-projection is done by gdal2tiles. For example:

gdalwarp -t_srs EPSG:3857 example.tif example-EPSG3857.tif
gdal2tiles.py -z 10-18 example-EPSG3857.tif tiles/
0

It looks like the image has been reprojected but the areas outside the original image (black pixel areas) have not been assigned as nodata. Also, in your last gdal2tiles run it looks like you're assigning nodata to color white (255).

Perhaps you could try running gdal2tiles again with the "–srcnodata=0" option,

or run gdal_translate on your already-reprojected images to specify black pixels (0) as noData, then re-run gdal2tiles with either the srcnodata option unused or set to black "–srcnodata=0".

gdal_translate -a_nodata 0 input.tif output.tif

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.