gisproj90

Help Creating A Tool *urgent*

Discussion created by gisproj90 on Mar 9, 2012
Latest reply on Mar 12, 2012 by dkwiens
Hello,

I am trying to develop an arc toolbox tool that will require an input of a single vector shapefile and a single raster image. It will first split the vector shapefile into multiple shapefiles, then from those individual shapefiles, extract raster data by mask to create a directory of individual raster files. I am currently working on the python code for this tool, and this is what I have so far. Every time we run the tool ArcMap crashes. Any suggestions on how to improve our tool?  Need to finish this by this monday, 3/12.

#define filepath
filepath = r"G:\geog173_Sheng_Programming\Final_Project"

#import system module 
import arcpy, os
from arcpy import env
from arcpy.sa import * 



#enable overwrite 
arcpy.env.overwriteOutput = True

#define filepath
filepath = r"G:\geog173_Sheng_Programming\Final_Project"

#import system module 
import arcpy, os
from arcpy import env
from arcpy.sa import * 



#enable overwrite 
arcpy.env.overwriteOutput = True


#set parameters 
vector = arcpy.GetParameterAsText(0)
raster = arcpy.GetParameterAsText(1)
out_split = arcpy.GetParameterAsText(2)
out_mask = arcpy.GetParameterAsText(3)
 

#set workspace environment 
arcpy.env.workspace = out_split#filepath

# Replace a layer/table view name with a path to a dataset (which can be a layer file) or create the layer/table view within the script
# The following inputs are layers or table views: "North_America"
arcpy.ImportToolbox(r"G:\geog173_Sheng_Programming\Final_Project\SplitLayerByAttributes.tbx")
arcpy.SplitLayerByAttributes(vector,'CNTRY_NAME',"#",out_split)


#Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")

shp_count = 0

#mask_Canada
#mask_USA
  #mask_Mex

for file1 in os.listdir(out_split):    
    if file1.endswith(".shp"):
        print file1
        shp_count = shp_count + 1
        
        # Execute ExtractByMask
        outExtractByMask = ExtractByMask (InRaster, file1)  

        # Save the output
        out_mask_new = out_mask + str(shp_count)
        outExtractByMask.save(out_mask_new)


print shp_count
print "extract by mask completed"


Thank you so much for the help!

Outcomes