clip nothing

2163
4
01-24-2016 11:26 PM
KevinLam
New Contributor
import arcgisscripting, sys, string, os
gp = arcgisscripting.create(9.3)
gp.OverWriteOutput = 1

FCsToClip = sys.argv[1]
FCClip = sys.argv[2]
outDir = sys.argv[3]

uniq = 9000
cur = gp.SearchCursor(FCClip)
row = cur.Next()
while row:
    DDAbb=row.getValue("ABBREVIATION")
    feat = row.shape
    DDAbb_=DDAbb.replace (" ", "_")
    if not gp.Exists(outDir+"\\"+DDAbb_):
        gp.Clip_analysis(FCsToClip, feat, outDir+"\\"+DDAbb.replace (" ", "_"))
        gp.addMessage(DDAbb.replace (" ", "_"))
    else:
        gp.Clip_analysis(FCsToClip, feat, outDir+"\\"+DDAbb.replace (" ", "_")+"_"+str(uniq))
        uniq+=1
        gp.addMessage(DDAbb.replace (" ", "_")+"_"+str(uniq))
    row = cur.Next()  
del cur, row

Message was edited by: Dan Patterson I provided python syntax highlighting to make it easier to read

Tags (2)
0 Kudos
4 Replies
DanPatterson_Retired
MVP Emeritus

Provide some print statements to check on progress.  Was "while" supported in 9.3?.  Check the help topics for previous versions and in particular to the version 10.0 and 10.1 ... there is a statement there about the evolution of cursors in arcmap and the change in how they are dealt with respect to python

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

Are you getting any error messages, or are the results just empty.

if the results are just empty, make sure all feature classes involved in the clip are in the same projection and the same extent. Do not just assume they are because they may draw in ArcMap, since ArcMap will project-on-the-fly if the layers have valid coordinate systems associated with them.

as Dan mention, if in version 10.x or newer, you may want to look into using the arcpy module instead of gp.

edit...adding a few arcpy help doc links for 10.2

ArcGIS Help (10.2, 10.2.1, and 10.2.2)      Importing Arcpy

ArcGIS Help (10.2, 10.2.1, and 10.2.2)   Clip, including sample script

LukeWebb
Occasional Contributor III

Your variable name indicates you may be passing a list of FCs to the clip tool, it can only clip 1 fc at a time.

FCsToClip    --> FCtoClip

XanderBakker
Esri Esteemed Contributor

Can you Clip using a geometry? If not you may need to use arcpy.CopyFeatures_management and create a in_memory featureclass to use in the Clip tool.

0 Kudos