0

I created a Python script that was previously working fine, but is now giving me an error when I try to use the arcpy.Clip_analysis() function in arcmaps 10.2.1. I am not adding a filetype extnsion to any of my feature class names when creating them. Previously, this worked fine. Now however i looks like ".shp" is being affixed to my feature class name twice, making the name invalid. Here is my code:

    in_features = os.path.join(arcMapsAuto.pc_gdb, arcMapsAuto.merged_feature_class )
    clip_features = os.path.join(arcMapsAuto.shapes_gdb, "Terminal_Polygon_Merge") 
    out_feature_class = os.path.join(arcMapsAuto.tc_gdb, "All_Terminal_Clip") 

    # Check to see if feature class already exists
    if arcpy.Exists(out_feature_class):
        print "All_Terminal_Clip creation: FAIL."
        print " --All_Terminal_Clip already exists."
        #return 

    print in_features
    print clip_features
    print out_feature_class     
            # printed out:  {geodatabas}\All_Terminal_Clip


    # Execute Clip
    try:
        arcpy.Clip_analysis(in_features, clip_features, out_feature_class)
        print " All_Terminal_Clip creation: SUCCESSS."

    except Exception as err:
        arcpy.AddError(err)
        print "All_Terminal_Clip creation: FAIL."
        print err 
        # printed error:  ERROR 000210: Cannot create output {geodatabase}\All_Terminal_Clip.shp.shp ERROR 000354: The name contains invalid characters

        return

I am missing something? Is arcpy.Clip_analysis() affixing .shp.shp to my target feature class name, and is this a new issue? I swear I've used the same code before without a problem? Any ideas on how I can fix this?

{geodatabase}\All_Terminal_Clip

All_Terminal_Clip creation: FAIL.

ERROR 000210: Cannot create output {geodatabase}\All_Terminal_Clip.shp.shp ERROR 000354: The name contains invalid characters

  • Would you be able to edit your question to include just a code snippet that works up to where you believe Clip_analysis is appending ".shp" onto a feature class name twice, please? By doing that I think you will discover what may be astray with your code, or if it is a Clip_analysis bug, then that will then become apparent. Your question could also be improved by including the current output from the code you have currently included but it will be best to remove your try/except so that more of the error is viewable. – PolyGeo Aug 5 '14 at 23:29
  • I'm not sure what arcMapsAuto is but how about instead of out_feature_class = os.path.join(arcMapsAuto.tc_gdb, "All_Terminal_Clip") doing simple string append out_feature_class = arcMapsAuto.tc_gdb + "\\All_Terminal_Clip.shp". Assuming arcMapsAuto.tc_gdb is a folder, if it is a geodatabase then it shouldn't be appending anything and don't include the extension. – Michael Stimson Aug 5 '14 at 23:33
  • @PolyGeoI did include output, in the form of comments – user3150002 Aug 5 '14 at 23:42
  • 2
    It looks like your path to geodatabase is not correct, try setting that as a string: out_feature_class = "c:\\PATH\\TO\\GEODATABASE.gdb\\All_Terminal_Clip", at the moment it's {geodatabas}\\All_Terminal_Clip which is likely to be causing your error. – Michael Stimson Aug 5 '14 at 23:47
  • 1
    I'm probably not the only potential answerer who would miss seeing the output of your print statements recorded as in code comments. I recommend using a separate Comment block which the Stack Exchange editor lets you do easily using the " button. – PolyGeo Aug 6 '14 at 0:02
1

As commented by @MichaelMiles-Stimson:

It looks like your path to geodatabase is not correct, try setting that as a string: out_feature_class = "c:\PATH\TO\GEODATABASE.gdb\All_Terminal_Clip", at the moment it's {geodatabas}\All_Terminal_Clip which is likely to be causing your error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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