I know this is an old post, but if anyone is looking to do this with ArcMap 10x you can cast your raster as a Raster Object and use the uncompressedSize property to get the size on disk.
That would the maximum possible size -- as you note, almost always smaller due to compression.
Python has functions in the os module to get file sizes off the operating system, so one could write a Python function to measure the size of the raster files using os.path.getsize(). This could be quite involved because you'd have to look at all the files. But it could be done for file-based rasters (not for rasters in the gdb, which are not visible from the OS).
I use the uncompressed size method in the tool validation just as a quick way to automatically select the largest raster in a TOC which is usually the watershed wide Lidar.
To get the actual size of a raster with it's associated files such as .ovr and .aux.xml using the os library I've used this code:
import os raster = # Path to raster file basename = os.path.basename(raster).split(".")[0] rootFolder = os.path.dirname(raster) associatedFiles = [os.path.join(rootFolder,f) for f in next(os.walk(os.path.dirname(raster)))[2] if f.split(".")[0] == basename] if len(os.path.basename(raster).split(".")) == 1: fileList = next(os.walk(raster))[2] dirSize = sum([os.path.getsize(os.path.join(raster,f)) for f in fileList]) rasSize = sum([os.path.getsize(f) for f in associatedFiles]) + dirSize else: rasSize = sum([os.path.getsize(f) for f in associatedFiles]) def convertSize(size,precision=2): suffixes=['B','KB','MB','GB','TB'] suffixIndex = 0 while size > 1024 and suffixIndex < 4: suffixIndex += 1 #increment the index of the suffix size = size/1024.0 #apply the division return "%.*f %s"%(precision,size,suffixes[suffixIndex]) print convertSize(rasSize)
The conversion part of the script was found here. The os.getsize function only returns the size of the file not the size on disk which incorporates the allocated size on the hard drive for the file metadata as seen in the properties of a file.
Here's a function implementation that returns a number in bytes and has the option of returning something similar to uncompressedSize. (There is a bug BUG-000110272 with the uncompressedSize property of the Raster object with large rasters that this works around.)
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">raster_size</SPAN><SPAN class="punctuation token">(</SPAN>filepath<SPAN class="punctuation token">,</SPAN> size_type<SPAN class="operator token">=</SPAN><SPAN class="string token">"DISK"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"""Return size of file-based rasters filepath path to raster size_type "DISK" - file size on disk from os.path.getsize() on files (default) "UNCOMPRESSED" - file size based on rows x columns x 4 bytes (estimate for Esri grid format, 32 bits/gridcell) "CELLS" - number of gridcells returns: file size as long integer """</SPAN> <SPAN class="keyword token">import</SPAN> os filepath <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>realpath<SPAN class="punctuation token">(</SPAN>filepath<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="operator token">not</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>exists<SPAN class="punctuation token">(</SPAN>filepath<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">raise</SPAN> Exception<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"{} not found"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>filepath<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> skey <SPAN class="operator token">=</SPAN> str<SPAN class="punctuation token">(</SPAN>size_type<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>upper<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">if</SPAN> skey <SPAN class="operator token">not</SPAN> <SPAN class="keyword token">in</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"UNC"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"CEL"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">:</SPAN> raster <SPAN class="operator token">=</SPAN> filepath basename <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>basename<SPAN class="punctuation token">(</SPAN>raster<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>split<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"."</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> rootFolder <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>dirname<SPAN class="punctuation token">(</SPAN>raster<SPAN class="punctuation token">)</SPAN> associatedFiles <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>rootFolder<SPAN class="punctuation token">,</SPAN>f<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> f <SPAN class="keyword token">in</SPAN> next<SPAN class="punctuation token">(</SPAN>os<SPAN class="punctuation token">.</SPAN>walk<SPAN class="punctuation token">(</SPAN>os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>dirname<SPAN class="punctuation token">(</SPAN>raster<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">if</SPAN> f<SPAN class="punctuation token">.</SPAN>split<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"."</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">==</SPAN> basename<SPAN class="punctuation token">]</SPAN> <SPAN class="keyword token">if</SPAN> len<SPAN class="punctuation token">(</SPAN>os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>basename<SPAN class="punctuation token">(</SPAN>raster<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>split<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"."</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># .tif, .jpg etc</SPAN> fileList <SPAN class="operator token">=</SPAN> next<SPAN class="punctuation token">(</SPAN>os<SPAN class="punctuation token">.</SPAN>walk<SPAN class="punctuation token">(</SPAN>raster<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN> dirSize <SPAN class="operator token">=</SPAN> sum<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN>os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>getsize<SPAN class="punctuation token">(</SPAN>os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>raster<SPAN class="punctuation token">,</SPAN>f<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> f <SPAN class="keyword token">in</SPAN> fileList<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> rasSize <SPAN class="operator token">=</SPAN> sum<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN>os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>getsize<SPAN class="punctuation token">(</SPAN>f<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> f <SPAN class="keyword token">in</SPAN> associatedFiles<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> dirSize <SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># Esri grid format</SPAN> rasSize <SPAN class="operator token">=</SPAN> sum<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN>os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>getsize<SPAN class="punctuation token">(</SPAN>f<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> f <SPAN class="keyword token">in</SPAN> associatedFiles<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">from</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>sa <SPAN class="keyword token">import</SPAN> Raster r <SPAN class="operator token">=</SPAN> Raster<SPAN class="punctuation token">(</SPAN>filepath<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">if</SPAN> skey <SPAN class="operator token">==</SPAN> <SPAN class="string token">"UNC"</SPAN><SPAN class="punctuation token">:</SPAN> rasSize <SPAN class="operator token">=</SPAN> r<SPAN class="punctuation token">.</SPAN>width <SPAN class="operator token">*</SPAN> r<SPAN class="punctuation token">.</SPAN>height <SPAN class="operator token">*</SPAN> <SPAN class="number token">4</SPAN> <SPAN class="operator token">*</SPAN> r<SPAN class="punctuation token">.</SPAN>bandCount <SPAN class="keyword token">elif</SPAN> skey <SPAN class="operator token">==</SPAN> <SPAN class="string token">"CEL"</SPAN><SPAN class="punctuation token">:</SPAN> rasSize <SPAN class="operator token">=</SPAN> r<SPAN class="punctuation token">.</SPAN>width <SPAN class="operator token">*</SPAN> r<SPAN class="punctuation token">.</SPAN>height <SPAN class="keyword token">return</SPAN> rasSize<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.