1

I have a large tif-file that cannot open with gdal.Open in Python as it is larger than 4 GB. I want to compress this file without losing the initial resolution. I have tried to split the raster into tiles with the following:

  1. Export the layer as a vrt tif file (image).

first

I load the newly created tif files and they are now more south than prior, even with the same projection (EPSG: 4326).

second

Then I tried with the GRASS r.tile tool, but even when I set the width (41037) and height (13568) to specific values, it changes the outcome and pixels (image). In the new outcome, the width is 41037, and the height is now 6458. This results in the minimum pixel value changes from 65 to 72.

third

Is there a way to make sure, the tiles either have the same projection/spatial location or simply compress the tif file to just under 4 GB and still keep the resolution?

2
  • 2
    OS? Version of QGIS? Version of GDAL in QGIS (Menu "Help" > "About")? You mention a limitation to open Geotif file bigger than 4GB but if Bigtiff supported, the limitation does not exist. Hence my previous questions.
    – ThomasG77
    Commented Jun 22, 2021 at 21:51
  • 1
    If you expand the "Create Options" checkbox that I can see in the screnshots above, it should show you some compression options. Choose the "High Compression" profile.
    – Mike T
    Commented Jun 23, 2021 at 8:00

1 Answer 1

2

As stated in my comment, you should not have to cut your geotiff to bypass the 4GB limitation. There is support for Bigtiff (mentioned in the Geotiff GDAL driver documentation https://gdal.org/drivers/raster/gtiff.html)

It mentioned

BigTIFF is a TIFF variant which can contain more than 4GiB of data (size of classic TIFF is limited by that value). This option is available if GDAL is built with libtiff library version 4.0 or higher. The default is IF_NEEDED.

So first approach is to "hunt" why you do not have BigTIFF support in your QGIS/GDAL install and see if it's possible to manage the main issue e.g "why you are unable to open file bigger than 4GB"

Alternative approaches:

Cut to multiple images

If you really have no choice e.g the first approach to solve the real issue is not working, you may use gdal_retile.py http://gdal.org/programs/gdal_retile.html to split your image

There is in QGIS GUI an available Processing algorithm named Retile to generate the gdal_retile.py command and call it from QGIS

A standalone (only with GDAL without QGIS dependency) command line example could be

gdal_retile.py -ps 5000 5000 -targetDir my_output_dir_path input.tif

It will crop your input geotiff every 5000 x 5000 pixels and get resulting geotiffs in directory my_output_dir_path

Compress image output

You can also compress the geotiff by changing option in "Create Options" to "High Compression" to decrease file size. See screenshot below with red highlighted part:

enter image description here

1
  • I do not want to change my gdal version as it has caused a lot of troubles before, and I now (finally) have a stable version. But I used the gdal retile tool in QGIS and it somehow worked. I did not change the resolution but the size was compressed.
    – Thomas
    Commented Jun 25, 2021 at 7:44

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.