Do not use on any
shared computer
September 8, 2008 03:09am pdt
 
[x]
Attachment Details

Modify python script to include all subdirectories in inputfolder

Tags: Python
Hello,
I found this python script below and I would like to have it modified some.   Is there a way to make the "argv[1]" workspace include all subdirectories within the designated workspace? And is there a way to make the "argv[2]" output text file names to automatically be the same as the input rasters?  

Extra information:
Its set up to use with a toolbox GUI interface within ESRI which isn't necessarily important to me. If the python script works I will be very satisfied. I also don't know if they script below is even affected any of this information.

Thank you kindly,
MJ
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
#RasterDataInfo.py
#
#Author
#  Dan Patterson
#Purpose
#  Lists the properties of raster data and optionally writes to a file.
#
#Properties (right-click on the tool and specify the following)
#General
#  Name  RasterDataInfo
#  Label Raster Data Info
#  Desc  List rasters in a folder.
#        All raster classes within the folder will be described.
#        You can optionally create a text file containing all output.
#        Simply select an output folder then specify an output filename.
#
#Source script RasterDataInfo.py
#
#Parameter list  (examples below)
#                                                Parameter Properties
#           Display Name          Data type      Type      Direction  MultiValue
#  argv[1]  Select a folder       Workspace      Required  Input      No
#  argv[2]  Output text filename  Optional       Optional  Input      No
#--------------------------------------------------------------------
#Import the standard modules
#  Get the folder
#  Get an optional output filename
#  Get a list of feature classes (shapefiles)
#  cycle through the list and add their names to the messages
#
import win32com.client, sys, os, string
gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")
#
gp.workspace=sys.argv[1]
aFileName=sys.argv[2]
#
aMessage="\n" + "Raster data in folder: " + gp.workspace + "\n"
s2="  "
s4="    "
#
#Determine if output is to go to a file as well
#
if aFileName <> '#':         #check to see if a filename is specified
  aFile=open(aFileName, 'w')
  aFile.write(aMessage + "\n")
  gp.AddMessage("\n" + "Output saved to: " + aFileName + "\n" + "Processing..." + "\n")
else:
  gp.AddMessage("\n" +aMessage + "\n" + "Optional text file not created")
 
aLst=gp.ListRasters("*", "all")  #a list, change as desired
aLst.reset()
aRaster=aLst.next()         #an element in a list
#
aCounter = 0
#
while aRaster:
  desc=gp.Describe(aRaster)
  aCounter = aCounter + 1
  if aFileName <> '#':
    gp.addMessage(str(aCounter) + s2 + str(desc.CatalogPath))
    #
  outList = []
  outList.append(str(aCounter) + s2 + str(desc.CatalogPath))
  outList.append(s4 + "Dataset type:  " + str(desc.DataSetType))
  outList.append(s4 + "Format:  " + str(desc.Format))
  outList.append(s4 + "Compression type:  " + str(desc.CompressionType))
  outList.append(s4 + "Sensor type:  " + str(desc.SensorType))
  outList.append(s4 + "Table type:  " + str(desc.TableType))
  outList.append(s4 + "Primary field:  " + str(desc.PrimaryField))
  outList.append(s4 + "Pixel type:  " + str(desc.PixelType))
  outList.append(s4 + "Is integer:  " + str(desc.IsInteger))
  #if str(desc.Format) == "GRID":
  #  rasterNoData = s4 + "NoData value:  " + str(desc.NoDataValue)
  outList.append(s4 + "Number of bands:  " + str(desc.BandCount))
  outList.append(s4 + "Height: " + str(desc.Height))
  outList.append(s4 + "Width: " + str(desc.Width))
  outList.append(s4 + "Raster Cell Height: " + str(desc.MeanCellHeight))
  outList.append(s4 + "Raster Cell Width: " + str(desc.MeanCellWidth))
  outList.append(s4 + "Extent: Xmin, Ymin, Xmax, Ymax " + str(desc.Extent))
  #
  #output to messages
  #
  if aFileName <> '#':
    for aVal in outList:
      aFile.write(aVal + "\n")
    aFile.write("\n")
  else:
    for aVal in outList:
      gp.AddMessage(aVal)
 
  aRaster = aLst.next()
gp.AddMessage("Rasters Processed:  " + str(aCounter) + "\n")
#
if aFileName <> '#':
  aFile.flush()
  aFile.close()
  gp.AddMessage("\n")
#
#del gp
Start your free trial to view this solution
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Question Stats
Zone: Programming
Question Asked By: mgjust
Solution Provided By: pepr
Participating Experts: 2
Solution Grade: A
Views: 5
Translate:
Loading Advertisement...
 
[+][-]Expert Comment by pepr

Rank: Guru

Expert Comment by pepr:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Assisted Solution by ramrom

Rank: Master

Assisted Solution by ramrom:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by ramrom

Rank: Master

Expert Comment by ramrom:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by mgjust
Author Comment by mgjust:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by ramrom

Rank: Master

Expert Comment by ramrom:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Assisted Solution by pepr

Rank: Guru

Assisted Solution by pepr:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Assisted Solution by pepr

Rank: Guru

Assisted Solution by pepr:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Assisted Solution by pepr

Rank: Guru

Assisted Solution by pepr:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by mgjust
Author Comment by mgjust:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Assisted Solution by pepr

Rank: Guru

Assisted Solution by pepr:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Accepted Solution by pepr

Rank: Guru

Accepted Solution by pepr:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080723-EE-VQP-34 / EE_QW_2_20070628