<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
{mso-style-priority:34;
margin-top:0cm;
margin-right:0cm;
margin-bottom:0cm;
margin-left:36.0pt;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
span.EmailStyle19
{mso-style-type:personal;
font-family:"Calibri",sans-serif;
color:windowtext;}
span.EmailStyle20
{mso-style-type:personal;
font-family:"Calibri",sans-serif;
color:windowtext;}
span.EmailStyle21
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
/* List Definitions */
@list l0
{mso-list-id:534659664;
mso-list-type:hybrid;
mso-list-template-ids:1732281016 134807569 134807577 134807579 134807567 134807577 134807579 134807567 134807577 134807579;}
@list l0:level1
{mso-level-text:"%1\)";
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l0:level2
{mso-level-number-format:alpha-lower;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l0:level3
{mso-level-number-format:roman-lower;
mso-level-tab-stop:none;
mso-level-number-position:right;
text-indent:-9.0pt;}
@list l0:level4
{mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l0:level5
{mso-level-number-format:alpha-lower;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l0:level6
{mso-level-number-format:roman-lower;
mso-level-tab-stop:none;
mso-level-number-position:right;
text-indent:-9.0pt;}
@list l0:level7
{mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l0:level8
{mso-level-number-format:alpha-lower;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-18.0pt;}
@list l0:level9
{mso-level-number-format:roman-lower;
mso-level-tab-stop:none;
mso-level-number-position:right;
text-indent:-9.0pt;}
@list l1
{mso-list-id:2057584222;
mso-list-template-ids:-1213414648;}
ol
{margin-bottom:0cm;}
ul
{margin-bottom:0cm;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-GB link="#0563C1" vlink="#954F72"><div class=WordSection1><p class=MsoNormal>Hi all,<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I posted this question on GIS SE (<a href="https://gis.stackexchange.com/questions/317009/compression-not-applying-when-updating-exiting-geotiff-file-in-gdal?noredirect=1#comment515654_317009">link</a>) but have not had any luck, so was wondering if anyone here could help. <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I have a `GeoTiff` file with dimensions 300 x 300 and 8760 bands (hourly for one full year). I am testing some code that opens the file, updates ONE band and exits - but I am finding that the file size almost doubles when I exit the file, despite the new band being the same data type etc. Code is as follows:<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I am creating the `GeoTiff` file using the following creation options using many singular `GeoTiff` files:<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal> gdal_merge.py -separate -co BIGTIFF=YES -co COMPRESS=DEFLATE -co PREDICTOR=1 -co TILED=YES -co BLOCKXSIZE=64 -co BLOCKYSIZE=64 -o block64.tif *.tif<o:p></o:p></p><p class=MsoNormal> <o:p></o:p></p><p class=MsoNormal>The file size is <b>947MB</b>.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I am then updating the file using the following code:<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal> ds = gdal.Open("block64.tif", gdal.GA_Update) <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal> # Some simple operation to change band values<o:p></o:p></p><p class=MsoNormal> arr = ds.GetRasterBand(11).ReadAsArray() / 2<o:p></o:p></p><p class=MsoNormal> ds.GetRasterBand(11).WriteArray(arr)<o:p></o:p></p><p class=MsoNormal> ds.FlushCache()<o:p></o:p></p><p class=MsoNormal> ds = None<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>The file size is now <b>1.9GB</b>.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>My preliminary conclusion is that the compression/creation options are not being applied once I've updated and exited the file. Is there any way to re-compress/reapply the options once I close the file? <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Current options: <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><ol style='margin-top:0cm' start=1 type=1><li class=MsoListParagraph style='margin-left:0cm;mso-list:l0 level1 lfo3'>read file, make changes, save to a new file – this is not ideal as saving the file each time I want to make an update is slow and this operation is happening server-side and needs to be as quick as possible.<o:p></o:p></li><li class=MsoListParagraph style='margin-left:0cm;mso-list:l0 level1 lfo3'>Use VRTs – This is a good option, but I’d like all bands in one GeoTiff to make I/O as quick as possible when extracting time series data, so a VRT wrapper does not help with updating the base file. <o:p></o:p></li></ol><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Any help would be greatly appreciated. <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><span style='mso-fareast-language:EN-GB'>Many thanks, <o:p></o:p></span></p><p class=MsoNormal><span style='mso-fareast-language:EN-GB'><o:p> </o:p></span></p><p class=MsoNormal><span style='mso-fareast-language:EN-GB'>Taylor </span><span style='font-size:9.0pt;mso-fareast-language:EN-GB'><o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p></div></body></html>