AnsweredAssumed Answered

Problem appending multiple raster properties to .txt file.

Question asked by drecsoo on May 6, 2012
Latest reply on May 7, 2012 by drecsoo
I'm a python newb who is interested in appending selected raster properties (using the arcpy.GetRasterProperties_management(input_raster, "property_type") function) to a comma-delimited table, but am having trouble figuring out how to do this for multiple results. As an abridged example (of my actual script), I have created two 'for' loops; one for each raster property I am interested in outputting (i.e. Cell Size X, Cell Size Y). My list of rasters include S01Clip_30m through S05Clip_30m. My goal is to create a .txt file that should look something like this:

RasterName, CellSizeX, CellSizeY
S01Clip_30m, 88.9372, 88.9375
S02Clip_30m, 88.9374, 88.9371

The code I have so far is below (with some uncertain, botched syntax at the bottom). When I run it, I get this result:

S05Clip_30m, 88.9374
(last raster in the list, CellSizeY)

I appreciate any help you can provide on the crucial bottom code block.

Thanks so much.

import arcpy from arcpy import env env.workspace = ('C:\\StudyAreas\\Aggregates.gdb') InFolder = ('C:\\dre\\python\\tables') OutputFile = open(InFolder + '\\' + 'RasterProps.txt', 'a') rlist = arcpy.ListRasters('*','*') for grid in rlist:     if grid[-8:] == "Clip_30m":         result = arcpy.GetRasterProperties_management(grid,'CELLSIZEX')         CellSizeX = result.getOutput(0) for grid in rlist:     if grid[-8:] == "Clip_30m":         result = arcpy.GetRasterProperties_management(grid,'CELLSIZEY')         CellSizeY = result.getOutput(0)  # I know the syntax below is incorrect, but I know there are *some* elements that  # should be included based on other example scripts that I have... # # if result.getOutput(0) == CellSizeX: #    coltype = CellSizeX # elif result.getOutput(0) == CellSizeY: #    coltype = CellSizeY # r = ''.join(grid) # colname = r[0:] # OutputFile.writelines(colname+','+coltype+'\n')