a_naresh299

Help with Raster Processing in Python

Discussion created by a_naresh299 on May 30, 2012
Latest reply on May 31, 2012 by a_naresh299
Deal All,

Would someone out here help me in understanding what this code does? I am finding it difficult to understand being a newbie. Thank you - Naresh

import arcgisscripting, os, sys

gp = arcgisscripting.create(9.3)

# Arguments
topfolder = sys.argv[1]
outCSV = sys.argv[2]

# Local Variables
openCSV = open(outCSV, 'w')
openCSV.write("File Name,File Size (KB),Spatial Reference,YMax,XMin,XMax,YMin,Cell Size\n")
rasters = []

# Collect all rasters in list
for root, dirs, files in os.walk(topfolder):
 for f in files:
  if '.ECW' in f.upper():
   rasters.append(os.path.join(root, f))

gp.AddMessage("\n" + str(len(rasters)) + " raster datasets found\n")

# Loop through rasters and describe file, spatial reference, and cell size
for raster in rasters:
        gp.AddMessage(raster)
 size = str(os.path.getsize(raster) / 1000.0)
 desc = gp.Describe(os.path.join(raster, "Band_1"))
 openCSV.write(raster + "," + size + "," + str(desc.SpatialReference.Name) + "," + str(desc.Extent.YMax) + "," + str(desc.Extent.XMin) + "," + str(desc.Extent.XMax) + "," + str(desc.Extent.YMin) + "," + str(desc.MeanCellHeight) + "\n")

 gp.AddMessage(raster + " has been checked")

Outcomes