import arcpy raster = 'some/path/to/a/raster.tif' description = arcpy.Describe(raster) cellsize = description.children[0].meanCellHeight print cellsize
For clarification purposes only, this code will work only in the python window within ArcMap and not within a stand-alone script.
If you need to run this in a separate python script (using ArcMap 10.5), you may need to add the creation of the raster element between of the declaration of the path for the raster and the Describe process.
In my case, if I wasn't creating the Raster element first, I would get an error stating that the list index was out of range cause by, according to my tests, the missing children[0] portion of the code above.
As such, below is the revised version of the code for usage within a python script.
<SPAN class="keyword token">import</SPAN> arcpy rasterpath <SPAN class="operator token">=</SPAN> <SPAN class="string token">'some/path/to/a/raster.tif'</SPAN> raster<SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Raster<SPAN class="punctuation token">(</SPAN>rasterpath<SPAN class="punctuation token">)</SPAN> description <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Describe<SPAN class="punctuation token">(</SPAN>raster<SPAN class="punctuation token">)</SPAN> cellsize1 <SPAN class="operator token">=</SPAN> description<SPAN class="punctuation token">.</SPAN>children<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>meanCellHeight <SPAN class="comment token"># Cell size in the Y axis and / or </SPAN> cellsize2 <SPAN class="operator token">=</SPAN> description<SPAN class="punctuation token">.</SPAN>children<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>meanCellWidth <SPAN class="comment token"># Cell size in the X axis </SPAN> arcpy<SPAN class="punctuation token">.</SPAN>AddMessage<SPAN class="punctuation token">(</SPAN>str<SPAN class="punctuation token">(</SPAN>cellsize1<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># If you want to show the result in the processing window</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.