# GetRasterProperties.py
# Description: Write raster properties to a file.
# Note: Written for ArcGIS 9.3.
# Create the Geoprocessor object
import arcgisscripting
gp = arcgisscripting.create()
# Get input parameters
InRaster = gp.GetParameterAsText(0)
OutFile = gp.GetParameterAsText(1)
#Property Types
PropertyTypes=['MINIMUM','MAXIMUM','MEAN','STD','UNIQUEVALUECOUNT','TOP','LEFT','RIGHT','BOTTOM','CELLSIZEX','CELLSIZEY','VALUETYPE','COLUMNCOUNT','ROWCOUNT','BANDCOUNT']
#Output file
OutFile=open(OutFile,'w')
# Process: GetRasterProperties
for PropertyType in PropertyTypes:
try:
Property = gp.GetRasterProperties(InRaster, PropertyType)
gp.AddMessage('%s=%s'%(PropertyType,Property))
OutFile.write('%s=%s\n'%(PropertyType,Property))
except:
# Print error message if an error occurs
gp.AddMessage(gp.GetMessages(2))
OutFile.close()
import arcpy
from arcpy import env
env.workspace = "C:\Path"
outfile = open("C:\RastStats.txt", 'w')
PropTypes = ["MINIMUM", "MAXIMUM", "MEAN"]
rastlist = arcpy.ListRasters("*", "")
for raster in rastlist:
rastname = str(raster)
outfile.write(rastname + "\n")
for PropType in PropTypes:
print PropType
Prop = arcpy.GetRasterProperties_management(raster, PropType)
textinfo = (PropType, Prop)
textstring = str(textinfo)
outfile.write(textstring + "\n")
outfile.close()All,
Here's a follow up.
With help from Luke I managed to get a crude script for 10. It looks like this:import arcpy from arcpy import env env.workspace = "C:\Path" outfile = open("C:\RastStats.txt", 'w') PropTypes = ["MINIMUM", "MAXIMUM", "MEAN"] rastlist = arcpy.ListRasters("*", "") for raster in rastlist: rastname = str(raster) outfile.write(rastname + "\n") for PropType in PropTypes: print PropType Prop = arcpy.GetRasterProperties_management(raster, PropType) textinfo = (PropType, Prop) textstring = str(textinfo) outfile.write(textstring + "\n") outfile.close()
This looks promising, but I'm still on 9.3
I'll be trying to get this to work, but could use help if anyone feels like translating this.
# BatchZonalStatisticsAsTable.py
# Description: Summarizes values of a raster within the zones of another dataset and reports the results to a table
# Requirements: None
# Author: David Coley
# Date: 05/10/06
#import win32com.client, sys, os, string
import arcgisscripting
gp = arcgisscripting.create()
gp.CheckOutExtension("Spatial")
gp.CellSize = 1 #can set as argument
gp.OverWriteOutput = 1
try:
gp.Workspace = "C:\\working\\Temp\\testing\\grids"
InZonalLayer = "C:\\working\\Temp\\testing\\TreatmentFranksTract2010.mdb\\Controls"
InZonalValueField = "PIN" #can set as argumment
#set output workspace which holds tables in a gdb
OutWorkSpace = "C:\\working\\Temp\\testing\\outputs3"
#Get the raster datasets in the input workspace and loop through them from the start
InputRasters = gp.ListRasters()
InputRasters.reset()
InputRaster = InputRasters.next()
OutTable = "C:\\working\\Temp\\testing\\outputs3\\" + InputRaster + "_stats.dbf"
while InputRaster:
# Process: Zonal Statistics as Table
gp.ZonalStatisticsAsTable_sa(InZonalLayer, InZonalValueField, InputRaster, OutTable, "DATA")
# print InputRaster
InputRaster = InputRasters.next()
#print OutTable
except:
gp.AddMessage(gp.GetMessages(2))
print gp.GetMessages(2)
What parameters must I input in the parameters tab to get this to work? I am new to scripts and getting them to work.