retrieve raster statistics and export to an .xls

750
6
05-22-2018 08:49 AM
HeatherHook
New Contributor

I need to retrieve minimum, maximum, mean, and standard deviation statistical values from a directory of raster files and store the values in an excel spreadsheet. 

My approach as been cursors and GetRasterProperties_management. 

Any insight would be greatly appreciated. 

0 Kudos
6 Replies
DanPatterson_Retired
MVP Emeritus

Get Raster Properties..

returns a result object, but what is your code that provides the shell around dealing with the result and putting it into a format that you can use for Table to Excel ?

0 Kudos
HeatherHook
New Contributor

That's a very good question. I was using a text document file with each object separated by a coma space. 

0 Kudos
DanPatterson_Retired
MVP Emeritus

actually I was referring to the code that cycles through the rasters and uses the tools's arcpy code access to get the stats.  Or do you not have that bit yet? since you refer to cursors

0 Kudos
HeatherHook
New Contributor

for loop. but I really haven't gotten that bit to work properly yet. 

0 Kudos
HeatherHook
New Contributor

i really feel like there is a more efficient approach I just have no idea what it could be.  I also thought there would already be an existing tool for this objective but my searches have come up empty handed.  

0 Kudos
by Anonymous User
Not applicable

I did something similar the other day. Instead of keeping it all inside GIS, I did a standalone script and exported from the script to a .txt file, which I then imported in Excel.

The iterating and printing part of the script looks like this:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import arcpy, os, sys, string, glob

arcpy.env.overwriteOutput = True

shpWS = "E:\MidlGIS\I7010"

arcpy.env.workspace = shpWS

shplist = arcpy.ListFeatureClasses()  

print (len(shplist))

for fc in shplist:
 count = arcpy.GetCount_management(fc)
 ord = fc
 ord = ord[6:]
 ord = ord[:-4]
 print fc[1:5]+"____"+ ord +'____'+str(count)