0

How do I convert a png with an alpha channel to a GeoTIFF using gdal_translate so that the alpha channel gets reflected in the GeoTiff. Currently the GTiff that is produced is resulting in 3 Bands, which does not contain the transparency requirements that I want. The command I am trying is.:

gdal_translate -of GTiff -gcp 567.344 496.649 4.00783e+06 4.42978e+06 -gcp 391.051 1127.79 3.89327e+06 3.44496e+06 -gcp 1595.33 290.84 5.60473e+06 4.91106e+06 -gcp 164.791 32.1259 3.23639e+06 5.03231e+06 -gcp 1562.15 1131.46 5.57244e+06 3.53e+06 -gcp 447.23 586.995 3.84236e+06 4.2981e+06 -gcp 1.73364 49.8788 3e+06 4.936e+06 -gcp 999.31 38.3279 4.5828e+06 5.2809e+06 -co ALPHA=YES 'source' 'dest'

1

I can't repeat your problem. In the beginning I took an png with alpha as reported by gdalinfo

gdalinfo alphatest.png
Driver: PNG/Portable Network Graphics
Files: alphatest.png
       alphatest.png.aux.xml
Size is 58, 40
Coordinate System is `'
Origin = (12.139578206197234,40.531369883218098)
Pixel Size = (0.049940902207883,-0.049940902207883)
Image Structure Metadata:
  INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left  (  12.1395782,  40.5313699)
Lower Left  (  12.1395782,  38.5337338)
Upper Right (  15.0361505,  40.5313699)
Lower Right (  15.0361505,  38.5337338)
Center      (  13.5878644,  39.5325518)
Band 1 Block=58x1 Type=Byte, ColorInterp=Red
  Mask Flags: PER_DATASET ALPHA
Band 2 Block=58x1 Type=Byte, ColorInterp=Green
  Mask Flags: PER_DATASET ALPHA
Band 3 Block=58x1 Type=Byte, ColorInterp=Blue
  Mask Flags: PER_DATASET ALPHA
Band 4 Block=58x1 Type=Byte, ColorInterp=Alpha

I re-used your command

gdal_translate -of GTiff -gcp 567.344 496.649 4.00783e+06 4.42978e+06 -gcp 391.051 1127.79 3.89327e+06 3.44496e+06 -gcp 1595.33 290.84 5.60473e+06 4.91106e+06 -gcp 164.791 32.1259 3.23639e+06 5.03231e+06 -gcp 1562.15 1131.46 5.57244e+06 3.53e+06 -gcp 447.23 586.995 3.84236e+06 4.2981e+06 -gcp 1.73364 49.8788 3e+06 4.936e+06 -gcp 999.31 38.3279 4.5828e+06 5.2809e+06 -co ALPHA=YES alphatest.png alphatest.tif

Gdalinfo proves that ground control points and alpha band are included

gdalinfo alphatest.tif
Driver: GTiff/GeoTIFF
Files: alphatest.tif
Size is 58, 40
Coordinate System is `'
GCP Projection =
GCP[  0]: Id=1, Info=
          (567.344,496.649) -> (4007830,4429780,0)
GCP[  1]: Id=2, Info=
          (391.051,1127.79) -> (3893270,3444960,0)
GCP[  2]: Id=3, Info=
          (1595.33,290.84) -> (5604730,4911060,0)
GCP[  3]: Id=4, Info=
          (164.791,32.1259) -> (3236390,5032310,0)
GCP[  4]: Id=5, Info=
          (1562.15,1131.46) -> (5572440,3530000,0)
GCP[  5]: Id=6, Info=
          (447.23,586.995) -> (3842360,4298100,0)
GCP[  6]: Id=7, Info=
          (1.73364,49.8788) -> (3000000,4936000,0)
GCP[  7]: Id=8, Info=
          (999.31,38.3279) -> (4582800,5280900,0)
Image Structure Metadata:
  INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left  (    0.0,    0.0)
Lower Left  (    0.0,   40.0)
Upper Right (   58.0,    0.0)
Lower Right (   58.0,   40.0)
Center      (   29.0,   20.0)
Band 1 Block=58x35 Type=Byte, ColorInterp=Red
  Mask Flags: PER_DATASET ALPHA
Band 2 Block=58x35 Type=Byte, ColorInterp=Green
  Mask Flags: PER_DATASET ALPHA
Band 3 Block=58x35 Type=Byte, ColorInterp=Blue
  Mask Flags: PER_DATASET ALPHA
Band 4 Block=58x35 Type=Byte, ColorInterp=Alpha

Parameter -co ALPHA=YES was not needed but alpha band was created even without it.

I did my test with GDAL 2.4.0dev.

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.