91 | | == [GeoTIFF output] `-co COMPRESS=` is broken! == |
92 | | ''When I compress an image with gdalwarp the result is often many times larger than the original! '' |
93 | | |
94 | | By default gdalwarp operates on chunks that are not necessarily aligned with the boundaries of the |
95 | | blocks/tiles/strips of the output format, so this might cause repeated compression/decompression of |
96 | | partial blocks, leading to lost space in the output format. |
97 | | |
98 | | The situation can be improved by using the [http://gdal.org/structGDALWarpOptions.html#a0ed77f9917bb96c7a9aabd73d4d06e08 OPTIMIZE_SIZE warping option] ("-wo OPTIMIZE_SIZE=YES"), |
99 | | but note that depending on the source and target projections, it might also significantly slow down |
100 | | the warping process. |
101 | | |
102 | | Another possibility is to use gdalwarp without compression and then follow up with gdal_translate with compression: |
103 | | {{{ |
104 | | gdalwarp infile tempfile.tif ...options... |
105 | | gdal_translate tempfile.tif outfile.tif -co compress=lzw ...etc. |
106 | | }}} |
107 | | |
108 | | Alternatively, you can use a VRT file as the output format of gdalwarp. The VRT file is just an XML file that will be created immediately. The gdal_translate operations will be of course a bit slower as it will do the real warping operation. |
109 | | |
110 | | {{{ |
111 | | gdalwarp -of VRT infile tempfile.vrt ...options... |
112 | | gdal_translate tempfile.vrt outfile.tif -co compress=lzw ...etc. |
113 | | }}} |
114 | | |
115 | | If using GDAL 2+ (ticket #6061) you can combine this into a single operation by writing the VRT to [https://www.gdal.org/gdal_virtual_file_systems.html#gdal_virtual_file_systems_vsistdout /vsistdout/] and piping that to `gdal_translate` and specifying [https://www.gdal.org/gdal_virtual_file_systems.html#gdal_virtual_file_systems_vsistdin /vsistdin/] as the input. For example: |
116 | | {{{ |
117 | | gdalwarp -q -t_srs EPSG:32611 -of vrt input_file.tif /vsistdout/ | gdal_translate -co compress=lzw /vsistdin/ output_file.tif |
118 | | }}} |
119 | | |