Clip Analysis Fail

4352
1
01-06-2015 11:37 PM
MittRamgobin
New Contributor
import arcpy
import sys
import os
# Script to create Shapefiles of WP Infrastructure within a specified boundary
# Define variables
UserName = "n041871"
Shapefile = r"S:\SupportServices\Meet\Arc Gis\Planning Refs\Canning\20150107_CTLE.shp"
Suffix = "CTLE"
#Build Path name for workspace
SDEPre = "C:\Users"
SDEPost = "\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog\DynamicCredentials@GISR.sde"
SDE= os.path.join(SDEPre,UserName+SDEPost)
print "Using "+SDE+" as Geodatabase"
arcpy.AddMessage("Using " + str(SDE)+ " as Geodatabase")
arcpy.env.workspace = SDE
arcpy.env.overwriteOutput = True
#Define Layers to Clip
#1. Transmission feature classes
T330OH = os.path.join ("GISTRAN.Transmission", "GISTRAN.Trans_330kV_OH_Carrier") 
T330UG = os.path.join ("GISTRAN.Transmission", "GISTRAN.Trans_330kV_UG_Cable")
T220OV = os.path.join ("GISTRAN.Transmission", "GISTRAN.Trans_220kV_OH_Carrier")
T132OH = os.path.join ("GISTRAN.Transmission", "GISTRAN.Trans_132kV_OH_Carrier")
T132UG = os.path.join ("GISTRAN.Transmission" , "GISTRAN.Trans_132kV_UG_Cable")
T66OV = os.path.join ("GISTRAN.Transmission", "GISTRAN.Trans_66kV_OH_Carrier")
T66UG = os.path.join ("GISTRAN.Transmission", "GISTRAN.Trans_66kV_UG_Cable")
T33OH = os.path.join ("GISTRAN.Transmission", "GISTRAN.Trans_33kV_OH_Carrier")
T33UG = os.path.join ("GISTRAN.Transmission", "GISTRAN.Trans_33kV_UG_Cable")
TransStruc = os.path.join ("GISTRAN.Transmission", "GISTRAN.Trans_Structure")
Substation = os.path.join ("GISTRAN.Transmission", "GISTRAN.Substation")
#Group Transmission Values:
Transmission = (T330OH, T330UG, T220OV, T132OH, T132UG, T66OV, T66UG, T33OH, T33UG, TransStruc, Substation)
 
#2. Distrubution feature classes
POLES = os.path.join("ARCFM.Structure", "ARCFM.Pole")
HVOH = os.path.join("ARCFM.Distribution_HV", "ARCFM.Conductor_HV")
HVUG = os.path.join("ARCFM.Distribution_HV", "ARCFM.Cable_HV")
LVOH = os.path.join("ARCFM.Distribution_LV", "ARCFM.Conductor_LV")
LVUG = os.path.join("ARCFM.Distribution_LV", "ARCFM.Cable_LV")
#Group Distribution Values
Distribution = (POLES, HVOH, HVUG, LVOH, LVUG)
#Future Infrastructure Shapefiles
ISubstation = r"S:\SupportServices\SPIDA Projects\Transmission\Sub-Regional Structure Planning\WP Future Infrastructure\Version 1\WP_New_Sub_stations_20130807.shp"
ILine = r"S:\SupportServices\SPIDA Projects\Transmission\Sub-Regional Structure Planning\WP Future Infrastructure\Version 1\WP_New_Power_Lines_20130807.shp"
#Group New Infrastructure
NewI = (ISubstation, ILine)
#Select Required LOCALITY
arcpy.MakeFeatureLayer_management(Shapefile, "lyr")
#Set Ouput Directory
outputPath = "S:\\SupportServices\\SPIDA Projects\\Infrastructure Shapefiles\\Custom\\"+ str(Suffix)
# Clip Transmission Feature Classes with LOCALITY Layer
for StrucT in Transmission:
    basefileName = arcpy.Describe(StrucT).baseName.replace('.','_') + Suffix
    fileFormat= '.shp'
    finalDest = os.path.join(outputPath,basefileName+fileFormat)
    arcpy.Clip_analysis(StrucT,Shapefile,finalDest)
    print StrucT + "Shapefile Created"
    arcpy.AddMessage(str(StrucT)+" Shapefile Created")
# Clip Distriution Feature Classes with LOCALITY Layer
for StrucD in Distribution:
    basefileName = arcpy.Describe(StrucD).baseName.replace('.','_') + Suffix
    fileFormat= '.shp'
    finalDest = os.path.join(outputPath,basefileName+fileFormat)
    arcpy.Clip_analysis(StrucD,Shapefile,finalDest)
    print StrucD + " Shapefile created"
    arcpy.AddMessage(str(StrucD)+" Shapefile Created")
#Clip New Infrastructure
for Struc in NewI:
    if not os.path.exists(outputPath):os.makedirs(outputPath)
    basefileName = arcpy.Describe(Struc).baseName.replace('.','_') + Suffix
    fileFormat= '.shp'
    finalDest = os.path.join(outputPath,basefileName+fileFormat)
    arcpy.Clip_analysis(Struc,Shapefile,finalDest)
    print Struc + " Shapefile created"
    arcpy.AddMessage(str(Struc)+" Shapefile Created")
#Find empty shapefiles and delete them
arcpy.env.workspace = outputPath
shapefiles = arcpy.ListFeatureClasses()
for shapefile in shapefiles:
    layerName = arcpy.Describe(shapefile).baseName
    arcpy.AddMessage(layerName)
    arcpy.MakeFeatureLayer_management (shapefile, layerName)
    arcpy.AddMessage(arcpy.GetCount_management(layerName).getOutput(0))
    if int(arcpy.GetCount_management(layerName).getOutput(0)) == 0:
        arcpy.Delete_management(shapefile)
        print shapefile + " deleted"
        arcpy.AddMessage(str(shapefile)+" Deleted")
        print "All empty shapefiles have been deleted"
        arcpy.AddMessage("All empty shapefiles have been deleted")
print "process complete"

I am  getting the following error:

Traceback (most recent call last):

  File "S:\SupportServices\Meet\Arc Gis\Scripts\WP_Infrastructure_Shapefile_Cut.py", line 71, in <module>

    arcpy.Clip_analysis(StrucT,"lyr",finalDest)

  File "c:\Program Files (x86)\ArcGIS\Desktop10.0\ArcPy\arcpy\analysis.py", line 55, in Clip

    raise e

ExecuteError: ERROR 000210: Cannot create output S:\SupportServices\SPIDA Projects\Infrastructure Shapefiles\Custom\CTLE\GISTRAN_Trans_330kV_OH_CarrierCTLE.shp

Failed to execute (Clip).

0 Kudos
1 Reply
DuncanHornby
MVP Notable Contributor

I can't spot anything immediately obvious about the output path. If you search desktop help the error code states:

Description

The output cannot be created. Potential reasons include data locking, an incorrect path, and limited access rights.

Solution

Confirm that the data is not locked by another user or application and that you have full rights to the workspace being used. Check to make sure that the path to the data is correct (check for typos in the folder path). Try creating the output in a new location.

I would start with say writing to a local c:\temp to confirm that its not a write permissions issues, if that works it would suggest the data has an issue. Try running the clip tool by itself with those datasets to see if the error occurs then?

0 Kudos