I am doing a script with python. There I have many raster in canvas (qgis) which I would like to know size in MB. I am searching function in python that give me this result.

Anyone can help me?


Try referring to this Stack Overflow post. They are looking at zip files, but it should work fine for your raster file.

If you are using a type of raster that is made up of multiple files, then I would suggest getting the file size of each and summing it.

The code would be similar to:

import os
os.path.getsize(#your file here)

As the post says, you can shift it to MB like this:

os.path.setsize(#your file here) >> 20

Credit definitely goes to Mark Longair and his answer on the referenced form post.


Using hurry.filesize you could do something like this :

import os
from hurry.filesize import size

raster_size = os.path.getsize('YOUR_PATH_HERE')
size(raster_size, system=alternative)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.