Select to view content in your preferred language

Help with Raster Processing in Python

427
2
05-30-2012 11:48 AM
NARESHALIGETI
Emerging Contributor
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")
Tags (2)
0 Kudos
2 Replies
BruceNielsen
Frequent Contributor
It looks like it is searching through a directory tree (rooted at topfolder), gathering statistics about all of the .ecw files it finds in the tree, and writing the statistics out to a text file (outCSV) as a comma-separated table.
0 Kudos
NARESHALIGETI
Emerging Contributor
Thanks Bruce! Would you mind to also give me a line-by-line explanation of the code above or an alternate method to write the code during your free time. Thanks in advance for the quick turn around.

-Naresh
LiDAR Analyst
0 Kudos