<!DOCTYPE html><html><head><title></title><style type="text/css">#qt p.qt-MsoNormal{margin-top:0cm;margin-right:0cm;margin-bottom:0cm;margin-left:0cm;font-size:11pt;font-family:"Calibri", sans-serif;}
p.MsoNormal,p.MsoNoSpacing{margin:0}</style></head><body><div style="font-family:Arial;">Hello,<br></div><div style="font-family:Arial;"><br></div><div style="font-family:Arial;">The GDAL API actually has a couple of methods that return the size of a file (not dataset) on disk: <a href="https://gdal.org/doxygen/cpl__vsi_8h.html#ac92fbd5e6fc143b026001b32c4c19ed1">VSIStatL</a>, <a href="https://gdal.org/doxygen/cpl__vsi_8h.html#ad1a691db1ba2f43add25a5c0d6498da6">VSIStatExL</a>. Since these work on files, they're not going to return valid results for multi-file formats. On the flip side, they support e.g. reading from ZIP files, which can come in handy.<br></div><div style="font-family:Arial;"><br></div><div style="font-family:Arial;">If you want to compute the compressed size of an image you have in memory, that's not really possible. The compression factor will depend on the image contents, and the only way to determine it is to actually do it and see how large the result is. You can even compress it without writing to disk, using <span class="font" style="font-family:menlo, consolas, monospace, sans-serif;">/vsimem/</span>.<br></div><div style="font-family:Arial;"><br></div><div style="font-family:Arial;">To get the uncompressed size, you're basically correct for simple images. You can multiply by the number of bands, which is 3 for an RGB image (like in your case), or 4 for RGBA. But some formats like NetCDF support multiple images in a single file, or even data with 3 or more dimensions. For those, there's no single width and height to use in a formula.<br></div><div style="font-family:Arial;"><br></div><div style="font-family:Arial;">Regards,<br></div><div style="font-family:Arial;">Laurentiu<br></div><div style="font-family:Arial;"><br></div><div>On Tue, May 9, 2023, at 11:47, Elena Ruiz wrote:<br></div><blockquote type="cite" id="qt" style="overflow-wrap:break-word;"><div class="qt-WordSection1"><p class="qt-MsoNormal"><span lang="EN-GB">Hello, I need to know the disk size of an image, I calculate it using the following formula:</span><br></p><p class="qt-MsoNormal"><span lang="EN-GB"> </span><br></p><p class="qt-MsoNormal"><span lang="EN-GB">Disk size=( sizex*sizey*bits per pixel)/8 =memory size without compression</span><br></p><p class="qt-MsoNormal"><span lang="EN-GB"> </span><br></p><p class="qt-MsoNormal"><span lang="EN-GB">But when the image is compressed on disk it occupies less and the size in memory is much larger, is there some method in the C++ GDAL API, to obtain the size on disk, size on memory, or the compression factor?</span><br></p><p class="qt-MsoNormal"><span lang="EN-GB">Example:</span><br></p><p class="qt-MsoNormal"><span lang="EN-GB">SizeX: 60416</span><br></p><p class="qt-MsoNormal"><span lang="EN-GB">SizeY:38656</span><br></p><p class="qt-MsoNormal"><span lang="EN-GB">Bits per pixel:24</span><br></p><p class="qt-MsoNormal"><span lang="EN-GB"> </span><br></p><p class="qt-MsoNormal"><span lang="EN-GB">Size memory= (60416*38656*24)/8=7.006.322.688 bytes</span><br></p><p class="qt-MsoNormal"><span lang="EN-GB">Size disk=2.137.644.631 bytes</span><br></p><p class="qt-MsoNormal"><span lang="EN-GB"> </span><br></p><p class="qt-MsoNormal"><span lang="EN-GB">The format image is <b>COG – Cloud Optimized GeoTIFF generator, and has JPEG compression</b></span><br></p><p class="qt-MsoNormal"><span lang="EN-GB"> </span><br></p><p class="qt-MsoNormal"><span lang="EN-GB">Thanks and regards</span><br></p></div><div><hr><br></div><table style="height:50px;width:473px;"><tbody><tr><td><p style="font-size:10pt;font-family:Arial;" align="right"><img src="https://www.aplitop.com/descargas/firma1.jpg" border="0"><br></p></td><td style="font-size:12pt;height:25px;font-family:Times New Roman;width:330px;" valign="top"><div style="line-height:13px;" align="left"><div><span class="font" style="font-family:Myriad Pro, Open Sans, Arial;"><span class="size" style="font-size:9pt;"><b>Elena Ruiz </b></span></span><br></div><div><span class="font" style="font-family:Myriad Pro, Open Sans, Arial;"><span class="size" style="font-size:7pt;">Sofware Development & Technical Support<br></span></span><span class="font" style="font-family:Myriad Pro, Open Sans, Arial;"><span class="size" style="font-size:7pt;">Tel.
+34 952 43 97 71 <br>eruiz@aplitop.com<br>Sumatra, 9 - 29190 Málaga (Spain)<br></span></span><span class="font" style="font-family:Myriad Pro, Open Sans, Arial;"><span class="size" style="font-size:7pt;"><b>www.aplitop.com<br><br><a class="qt-socialLink" href="https://www.facebook.com/AplitopSL/"><img class="qt-socialLink" style="height:15px;width:15px;" src="cid:SocialLink_Facebook_32x32_a745adb8-c250-4372-8480-e77f503dad3d.png" width="15" height="15" border="0"></a> <a class="qt-socialLink" href="https://twitter.com/aplitop"><img class="qt-socialLink" style="height:15px;width:15px;" src="cid:SocialLink_Twitter_32x32_858247f6-9d4a-4740-a6b3-9b5ebfd98a97.png" width="15" height="15" border="0"></a> <a class="qt-socialLink" href="https://www.linkedin.com/company/aplitop"><img class="qt-socialLink" style="height:15px;width:15px;" src="cid:SocialLink_Linkedin_32x32_154d63de-bf68-468f-9eb0-ffed102fac77.png" width="15" height="15" border="0"></a> <a class="qt-socialLink" href="https://www.youtube.com/user/aplitop"><img class="qt-socialLink" style="height:15px;width:15px;" src="cid:SocialLink_Youtube_32x32_0dea15dd-3774-4086-be9d-f62560b70c86.png" width="15" height="15" border="0"></a></b></span></span></div></div></td></tr></tbody></table><p style="font-size:10pt;font-family:Arial;"><span class="font" style="font-family:Myriad Pro;"><span class="size" style="font-size:6pt;">In accordance with the
provisions of the European Regulation of Data Protection 2016/679 (Reglamento
Europeo de Protección de Datos 2016/679), we inform you that the data and the
information you provide us through this medium will be used by APLITOP, S.L.,
with C.I.F. B-92543396 and with address at C / Sumatra, 9, Malaga, 29190, in
order to answer your questions and inform you about our products. The data
provided will be kept as long as it does not request its cessation and will not
be transferred to third parties except in cases where there is a legal
obligation. You have the right to access your personal data, correct inaccurate
data or request its deletion when the data is no longer necessary for the
purposes that were collected, as well as any rights recognized in the RGPD
2016/679<br></span></span><a href="https://www.aplitop.com/New/en/443/publication-of-point-clouds-on-web" title=""></a><span class="font" style="font-family:Myriad Pro;"><span class="size" style="font-size:6pt;"></span></span></p><p style="font-size:10pt;font-family:Arial;"><span class="font" style="font-family:Myriad Pro;"><span class="size" style="font-size:6pt;"><br></span></span><a href="https://www.aplitop.com/New/en/438/tcpmdt-v9-is-here" title=""></a><a href="https://www.aplitop.com/Event/en/429/aplitop-at-intergeo-2022-essen" title=""></a><span class="font" style="font-family:Myriad Pro;"><span class="size" style="font-size:6pt;"><br><br><a title="" href="https://www.aplitop.com/Event/en/358/intergeo-2019"></a><br></span></span></p><div>_______________________________________________<br></div><div>gdal-dev mailing list<br></div><div><a href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a><br></div><div><a href="https://lists.osgeo.org/mailman/listinfo/gdal-dev">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a><br></div><div><br></div></blockquote><div style="font-family:Arial;"><br></div></body></html>