Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a large land cover map in a geodatabase, that I want to batch clip by defined catchments (about 63 polygons). The output files are named based on a field in the "clipper" (sys.argv[2]) called Watershed (currently a hard coded portion of my script).

The script below works if I run it on a shapefile, and point the outputs to an empty folder.
Ideally, I want to run this on a feature class, and point the outputs to a geodatabase using ArcMap9.3, however, I get the following error code: 000210: Cannot create output .

Does anyone have any suggestions? I have full permissions on my machine, and path directories are correct, so I'm not sure why I'm getting this particular error.

# Parameter list for ArcToolbox
#                                   Parameter Properties
#           Display Name            Data type           Type        Direction   MultiValue
#   argv[1] Output workspace        Workspace           Required    Input       No
#   argv[2] Layer used to Clip      Feature Class       Required    Input       No
#   argv[3] Layer to be clipped     Feature Class       Required    Input       No
#   argv[4] prefix for file name    String          Required    Input       No
#-----------------------------------------------------------------------------

#Import system modules
import sys
import string
import os
import arcgisscripting

# Create the Geoprocessor object
gp = arcgisscripting.create(9.3)

# Load required toolboxes...
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Analysis Tools.tbx")

# Designate a workspace for cliped vector data
gp.workspace = sys.argv[1]

# Assign variables to be processed...
clipper = sys.argv[2] # feature used to clip vector data
vector = sys.argv[3] # vector data to be clipped and then rasterized
suffix = sys.argv[4] # file naming convention prefix

# Search cursor sequence...
rows = gp.SearchCursor(clipper)
row = rows.Next()
feat = row.Shape # used as the clip_features in the Clip_analysis (clipper input must have a field called "Index_Key", which is used as the file name of each output)
while row:
    n = str(row.Watershed) # assign a variable for the processing message based on a field
    print "clipping to: " +n # tells you what grid was clipped
    # Clip_analysis <in_features> <clip_features> <out_feature_class> {cluster_tolerance}
    gp.Clip_analysis(vector, feat, str(row.Watershed)+"_"+str(suffix)+".shp", "") #update str if necessary
    row=rows.next()

# reset the array...
del rows
del gp
share|improve this question
1  
So you have the geodatabase pre-created when you run the script? Have you shut down ArcCatalog and ArcMap and then run the script? I'm wondering if this is a geodatabase lock issue. –  Chad Cooper Jan 3 '12 at 15:59
add comment

1 Answer

up vote 4 down vote accepted

In your while loop, it is trying to output a shapefile.

You can see this by the string the script tries to construct:

gp.Clip_analysis(vector, feat, str(row.Watershed)+"_"+str(suffix)+".shp", "")

Change to either:

gp.Clip_analysis(vector, feat, str(row.Watershed)+"_"+str(suffix), "") or gp.Clip_analysis(vector, feat, str(n)+"_"+str(suffix), "")

I think that should get it a little farther.

share|improve this answer
    
I will suggest to change above line to: gp.Clip_analysis(vector, feat, str(row.getValue(Watershed)+"_"+str(suffix), "") –  iRfAn Jan 4 '12 at 12:21
    
Thanks! It works now, and very quickly! –  Czed Jan 4 '12 at 14:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.