We help IT Professionals succeed at work.

Review of Python script for ESRI GIS application

mgjust
mgjust asked
on
1,749 Views
Last Modified: 2012-06-22
Hello,
Please review the following script. I know that many persons may not now the specifics of the ESRI software. I would simply like someone to review this script and tell me if there is anything wrong with it from either a purely Python or Python + ESRI viewpoint.  I would greatly appreciate annotation because I am trying to learn how to create scripts on my own.  The script below is my attempt (with great hope) to create a script that will have a folder that contains two types of files (rasters and vectors (aka shapefiles)) it will cycle through these files on a one to one basis. It will take a raster "r_a" and a shapefile "s_a" and then use a readymade function  to create a new raster that is the same extent as the shapefile. I will most likely need to get help from the ESRI user forum after I ask here, but I want to make sure that there are no bonehead mistakes yet in this script.

Thanks,


# Description: 
#   Extracts the cells of a raster that correspond with the areas
#   defined by a mask.
# Import system modules
import arcgisscripting
 
# Create the Geoprocessor object
gp = arcgisscripting.create()
 
#Set the input workspace
GP.workspace = "C:/Atest"
#GP.AddMessage(str(GP.workspace))
 
#Set the output workspace
outworkspace = "C:/Btest"
 
#Get a list of the featureclasses in the input folder
rasters = GP.ListRasters()
 
shapefiles = GP.ListShapefiles() 
	
#Reset the enumeration to make sure the first object is returned
rasters.Reset()
 
shapefiles.Reset()
 
    #Loop through the list of feature classes   
raster = rasters.Next()
 
shapefile = shapefiles.Next()
 
try:
    # Set local variables
    InRaster = raster
    InMask = shapefile
    OutRaster = outworkspace + "/" + raster 
    
    # Check out Spatial Analyst extension license
    gp.CheckOutExtension("Spatial")
 
    # Process: ExtractByMask
    gp.ExtractByMask_sa(InRaster, InMask, OutRaster)
 
except:
    # If an error occurred while running a tool, then print the messages.
    print gp.GetMessages()

Open in new window

Comment
Watch Question

Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thank you, however now I have some more questions which I will ask in a new post.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.