I guess this depends on how often you want to run the script, whether or not you want to hard code in the clip grids and the output shapefiles.
Very simply, I'd have a dictionary, of clip_grid : output_shapefile, loop through that and spit out the output.
import arcgisscripting
#Create the geoprocessor
gp = arcgisscripting.create(9.3)
input_shape = "yourshapefile.shp" #<-- this single file will be clipped repeatedly
#grids and corresponding outputs go here
clip_dictionary = {"clipgrid1.shp":"output1.shp", "clipgrid2.shp":"output2.shp"}
for iter in clip_dictionary:
#Clip_analysis (in_features, clip_features, out_feature_class, cluster_tolerance)
gp.Clip_analysis(input_shape, iter, clip_dictionary[iter])
Hope that helps!
sys.argv is a possiblity if you wish to read in the arguments from the command line (or if you wish to add the script to the toolbox). You could also use getopt or optparse as well.
Assume that we have a script called clip_export.py, which we wish to pass a list of inputs. We could run the script like:
clip_export.py input_shape clipshape_1;clipshape_2;clipshape_3 output_folder
Note that this is similar to the input that is sent to a python script by Toolbox.
At any rate, you can read this in your script like so:
import sys
input_shape = sys.argv[1] #<-- Note that the 0th argument in sys.argv is the script name
clip_shape_list = sys.argv[2].split(';') #<-- splits the second argument on the semicolon into a python list
output_folder = sys.argv[3]
The from here run the rest of your script. As @Simon Norris shows below.
Again, hope this helps!
I've run into that error a lot. Depending on how your script is setup to process each feature class,ie if it processes each one at a time you could try using a search cursor test. See below.
EDIT:
The search cursor in this case is looking at the first shape record of each feature class and seeing if it has a null value. If its null, then the feature class is empty because the shape can't be null as far as I know. Try this for your code:
REVISED CODE:
for iter in cop_dictionary:
path = part_path + iter + ".shp" # I think all you need is iter here,
# since the for loop handles the iteration
rows = gp.SearchCursor(path)
row = rows.next()
value = row.Shape #or row.SHAPE capitalization matters here!
if value is None:
#move onto next feature class
gp.AddMessage(iter + "Is Empty")
else:
#copy feature class
gp.CopyFeatures_management(iter, path, "", "0", "0", "0")
gp.AddMessage(iter + "has been exported")
del rows, row
Best Answer
Have you tried listing your datasets? http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Iteration_using_Lists
TIP: A good tip with ArcGIS ModelBuilder is you can drag and drop multiple datasets from ArcCatalog or from the Table of Contents [TOC] in ArcMap.
Drag and drop a dataset from the ArcCatalog tree or a layer from the ArcMap table of content http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Listing_data
Lists all datasets from the selected workspace. Specifying search conditions (wildcard) and a feature type limits the results. The workspace must be specified before using any of the List methods
http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=ListDatasets_method
also useful tips http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Using_the_batch_grid_control