3

I have a hillshade which I want to compress using JPEG compression:

gdal_translate -co COMPRESS=JPEG -co TILED=YES /home/bera/Drives/ssd1/Hillshades/testhillshade.tif /home/bera/Drives/ssd1/Hillshades/testhillshade_JPEG.tif
Input file size is 25000, 35000
Warning 1: /vsimem/gtiffdataset_jpg_tmp_0x55c683c3bb30: NBITS=32 is invalid for data type UInt16. Using NBITS=16
ERROR 1: JPEGSetupEncode:BitsPerSample 16 not allowed for JPEG
0...10...20.ERROR 1: JPEGSetupEncode:BitsPerSample 32 not allowed for JPEG
.ERROR 1: An error occurred while writing a dirty block from GDALRasterBand::IRasterIO
ERROR 1: JPEGSetupEncode:BitsPerSample 32 not allowed for JPEG
ERROR 1: JPEGSetupEncode:BitsPerSample 32 not allowed for JPEG

I dont understand what the error is telling me.

gdalinfo /home/bera/Drives/ssd1/Hillshades/testhillshade.tif
Driver: GTiff/GeoTIFF
Files: /home/bera/Drives/ssd1/Hillshades/testhillshade.tif
Size is 25000, 35000
Coordinate System is:
PROJCRS["SWEREF99 TM",
    BASEGEOGCRS["SWEREF99",
        DATUM["SWEREF99",
            ELLIPSOID["GRS 1980",6378137,298.257222101004,
                LENGTHUNIT["metre",1]]],
        PRIMEM["Greenwich",0,
            ANGLEUNIT["degree",0.0174532925199433]],
        ID["EPSG",4619]],
    CONVERSION["Transverse Mercator",
        METHOD["Transverse Mercator",
            ID["EPSG",9807]],
        PARAMETER["Latitude of natural origin",0,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8801]],
        PARAMETER["Longitude of natural origin",15,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8802]],
        PARAMETER["Scale factor at natural origin",0.9996,
            SCALEUNIT["unity",1],
            ID["EPSG",8805]],
        PARAMETER["False easting",500000,
            LENGTHUNIT["metre",1],
            ID["EPSG",8806]],
        PARAMETER["False northing",0,
            LENGTHUNIT["metre",1],
            ID["EPSG",8807]]],
    CS[Cartesian,2],
        AXIS["easting",east,
            ORDER[1],
            LENGTHUNIT["metre",1,
                ID["EPSG",9001]]],
        AXIS["northing",north,
            ORDER[2],
            LENGTHUNIT["metre",1,
                ID["EPSG",9001]]]]
Data axis to CRS axis mapping: 1,2
Origin = (380000.000000000000000,6315000.000000000000000)
Pixel Size = (0.500000000000000,-0.500000000000000)
Metadata:
  AREA_OR_POINT=Area
Image Structure Metadata:
  INTERLEAVE=BAND
Corner Coordinates:
Upper Left  (  380000.000, 6315000.000) ( 13d 1'35.12"E, 56d57'46.80"N)
Lower Left  (  380000.000, 6297500.000) ( 13d 2' 4.88"E, 56d48'21.16"N)
Upper Right (  392500.000, 6315000.000) ( 13d13'54.79"E, 56d57'57.86"N)
Lower Right (  392500.000, 6297500.000) ( 13d14'21.45"E, 56d48'32.16"N)
Center      (  386250.000, 6306250.000) ( 13d 7'59.08"E, 56d53' 9.65"N)
Band 1 Block=25000x1 Type=Float32, ColorInterp=Gray
  NoData Value=-9999

Why doesnt it work?

0

1 Answer 1

6

It turns out you cant JPEG compress a raster which has data type Float32.

It is working when I convert it to type Byte with the -ot flag:

gdal_translate -ot Byte -co COMPRESS=JPEG -co TILED=YES /home/bera/Drives/ssd1/Hillshades/test.tif /home/bera/Drives/ssd1/Hillshades/test_JPEG.tif

From 3.3 GB to 62 MB and the quality is very good:

enter image description here

0

Your Answer

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

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