0

I try to use gdal_translate in my windows command prompt to convert a single band .tif raster to a single band .gpkg.

gdal_translate -of GPKG example.tif example.gpkg

I always get a .gpkg with four bands.

I tried all possible combinations of the following commands with no succes:

-band
-mask
-expand

gdalinfo of example.tif

Driver: GTiff/GeoTIFF
Files: example.tif
       example.tif.aux.xml
Size is 5334, 5280
"
"
Metadata:
  AREA_OR_POINT=Area
Image Structure Metadata:
  COMPRESSION=LZW
  INTERLEAVE=BAND
"
"
Band 1 Block=5334x1 Type=Byte, ColorInterp=Gray
  Min=10.000 Max=113.000
  Minimum=10.000, Maximum=113.000, Mean=50.602, StdDev=14.032
  NoData Value=255
  Metadata:
    STATISTICS_MAXIMUM=113
    STATISTICS_MEAN=50.60229149027
    STATISTICS_MINIMUM=10
    STATISTICS_STDDEV=14.032043952498

gdalinfo of example.gpkg:

Driver: GPKG/GeoPackage
Files: example.gpkg
Size is 5334, 5280
"
"
Metadata:
  AREA_OR_POINT=Area
  IDENTIFIER=example
  ZOOM_LEVEL=5
Image Structure Metadata:
  INTERLEAVE=PIXEL
"
"
Band 1 Block=256x256 Type=Byte, ColorInterp=Red
  Mask Flags: PER_DATASET ALPHA
Band 2 Block=256x256 Type=Byte, ColorInterp=Green
  Mask Flags: PER_DATASET ALPHA
Band 3 Block=256x256 Type=Byte, ColorInterp=Blue
  Mask Flags: PER_DATASET ALPHA
Band 4 Block=256x256 Type=Byte, ColorInterp=Alpha
4
  • Also please show us the exact commandline(s) you used. with regards to the parameters. Please add the relevant bits from gdalinfo for both your input and the bad output. Nov 3, 2020 at 15:35
  • Gdalinfo showes that the NoData value in the tiff was already 255. So this is no transforming issue. I updated my question acording to that.
    – sfetan
    Nov 3, 2020 at 16:43
  • gdal.org/drivers/raster/gpkg.html#opening-options suggests that you could add -oo "BAND_COUNT=1" but how would we be able to find the actual count of bands is beyond me. Nov 3, 2020 at 18:31
  • Try converting from Type=Byte to Type=Float when you save to GeoPackage, assuming the Type is not critical. GDAL seems to assume 4 bands when converting to GeoPackage for Int type data, and 1 band for Float type data. I don't know why though! Aug 1, 2022 at 12:07

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.