Thursday 24 October 2019

qgis - Clipping raster-image increases file size


Working with QGIS 2.4.0 Chugiak I have a question regarding the clipping of raster images. I have an aerial picture that I want to clip using the extents of a shapefile. So far so good, I used the raster/extraction/clipper tool to do this. The problem is that the file size of my output raster is nearly three times larger than the original file (i.e. 725.283 and 249.693 kb respectively), whereas it covers a smaller surface.


Why is my file larger? And is there any way to 'set' the output file size?


The help function of clipper refers to the following page: http://www.gdal.org/gdal_translate.html Though I cannot make much out of it.



I am relatively new to QGIS.



Answer



When you run the raster clip tool in QGIS, it shows you the exact GDAL command that will be run in the bottom section of the dialog box.


Raster clip tool


By clicking the pen button to the right of the command, you can edit it directly and add in a compression configuration option. In my example, this is the starting command:


gdalwarp -q -cutline /tmp/mask.shp -crop_to_cutline -of GTiff /tmp/453A.tif /tmp/output.tif


You can change this to be:


gdalwarp -q -cutline /tmp/mask.shp -crop_to_cutline -of GTiff -co "COMPRESS=LZW" /tmp/453A.tif /tmp/output.tif


The extra -co "COMPRESS=LZW" is just one of many possible compression options you can use with GeoTIFF files. The GDAL documentation has more information on all the options.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...