[gdal-dev] Space Disk/Memory of Image

Laurențiu Nicola lnicola at dend.ro
Tue May 9 02:08:04 PDT 2023


Hello,

The GDAL API actually has a couple of methods that return the size of a file (not dataset) on disk: VSIStatL <https://gdal.org/doxygen/cpl__vsi_8h.html#ac92fbd5e6fc143b026001b32c4c19ed1>, VSIStatExL <https://gdal.org/doxygen/cpl__vsi_8h.html#ad1a691db1ba2f43add25a5c0d6498da6>. 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.

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 /vsimem/.

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.

Regards,
Laurentiu

On Tue, May 9, 2023, at 11:47, Elena Ruiz wrote:
> Hello, I need to know the disk size of an image, I calculate it using the following formula:
>  
> Disk size=( sizex*sizey*bits per pixel)/8 =memory size without compression
>  
> 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?
> Example:
> SizeX: 60416
> SizeY:38656
> Bits per pixel:24
>  
> Size memory= (60416*38656*24)/8=7.006.322.688 bytes
> Size disk=2.137.644.631 bytes
>  
> The format image is *COG – Cloud Optimized GeoTIFF generator, and has JPEG compression*
>  
> Thanks and regards
> 
> 
> 
> *Elena Ruiz *
> Sofware Development & Technical Support
> Tel. +34 952 43 97 71 
> eruiz at aplitop.com
> Sumatra, 9 - 29190 Málaga (Spain)
> *www.aplitop.com
> 
 <https://www.facebook.com/AplitopSL/>    <https://twitter.com/aplitop>    <https://www.linkedin.com/company/aplitop>    <https://www.youtube.com/user/aplitop>*
> 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
 <https://www.aplitop.com/New/en/443/publication-of-point-clouds-on-web>
> 
> 
 <https://www.aplitop.com/New/en/438/tcpmdt-v9-is-here> <https://www.aplitop.com/Event/en/429/aplitop-at-intergeo-2022-essen>
> 
 <https://www.aplitop.com/Event/en/358/intergeo-2019>
> 
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/gdal-dev
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20230509/3aec691c/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SocialLink_Facebook_32x32_a745adb8-c250-4372-8480-e77f503dad3d.png
Type: image/png
Size: 365 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20230509/3aec691c/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SocialLink_Twitter_32x32_858247f6-9d4a-4740-a6b3-9b5ebfd98a97.png
Type: image/png
Size: 619 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20230509/3aec691c/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SocialLink_Linkedin_32x32_154d63de-bf68-468f-9eb0-ffed102fac77.png
Type: image/png
Size: 468 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20230509/3aec691c/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: SocialLink_Youtube_32x32_0dea15dd-3774-4086-be9d-f62560b70c86.png
Type: image/png
Size: 817 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20230509/3aec691c/attachment-0003.png>


More information about the gdal-dev mailing list