I'm using ArcGIS Desktop 10.2.2.

I have a feature class in a geodatabase that from time to time I want to update with new data in an excel table. I wrote the following script to convert an excel table into a shapefile and overwrite the old feature class with that new shapefile.

Note: Hardwiring the Input_Table and Output_FC variables didn't help.

# Get tool input parameters
#wspace = arcpy.GetParameterAsText(0)           # workspace
Input_Table = arcpy.GetParameterAsText(0)   # CSV file with new / updated points
Output_FC = arcpy.GetParameterAsText(1)         # Original Feature Class Overwritten by NEW Shapefile in final step (CopyFeatures)

import arcpy, sys
from arcpy import env

#Overwrite Old Files (False=No, True=Yes)
arcpy.env.overwriteOutput = True

# Set the local variables
wspace = r"Q:\GW\EC1210WQAEH_QESEA\CSSP_ATL\Users\vanvulpenc\CSV_to_Shapefile\temp_workspace"
x_coords = "Lng"
y_coords = "Lat"
output_Layer = "output_Layer"
saved_Layer = "To_Shapefile.lyr"

# Set the spatial reference
spRef = arcpy.SpatialReference("NAD 1983 (CSRS)") 

# Make the XY event layer
arcpy.MakeXYEventLayer_management(Input_Table, x_coords, y_coords, output_Layer, spRef)

# Save to a layer file
arcpy.SaveToLayerFile_management(output_Layer, saved_Layer)

# Copy features to shapefile

arcpy.CopyFeatures_management(wspace+saved_Layer, Output_FC)

print 'Data Conversion Complete'

My script generates the following error message:

Traceback (most recent call last):
  File "Q:\GW\EC1210WQAEH_QESEA\CSSP_ATL\Users\vanvulpenc\Scripts\CSV_to_Shapefile.py", line 41, in <module>
    arcpy.CopyFeatures_management(wspace+saved_Layer, Output_FC)
  File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\management.py", line 2429, in CopyFeatures
    raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Features: Dataset Q:\GW\EC1210WQAEH_QESEA\CSSP_ATL\Users\vanvulpenc\CSV_to_Shapefile\temp_workspaceTo_Shapefile.lyr does not exist or is not supported
WARNING 000725: Output Feature Class: Dataset Q:\GW\EC1210WQAEH_QESEA\CSSP_ATL\Users\vanvulpenc\CSV_to_Shapefile\MWQStations.gdb\MWQStations_NS already exists.
Failed to execute (CopyFeatures).

In your code you have set:

arcpy.env.overwriteOutput = 1

but from its documentation arcpy.env expects a Boolean (True or False) rather than an Integer for its overwriteOutput property.

Try this instead:

arcpy.env.overwriteOutput = True

I am also suspicious of this path being reported in your error message:

Q:\GW\EC1210WQAEH_QESEA\CSSP_ATL\Users anvulpenc\CSV_to_Shapefile emp_workspaceTo_Shapefile.lyr

The missing letters and inserted spaces suggest that your backspaces are not being escaped by using an r in front of a pathname somewhere. I am suspicious that the precise code that you have presented may not be what was run to produce that error message.

It also looks like you are trying to provide a layer file to CopyFeatures when it expects "Feature Layer; Raster Catalog Layer".

Instead of:

wspace = r"Q:\GW\EC1210WQAEH_QESEA\CSSP_ATL\Users\vanvulpenc\CSV_to_Shapefile\temp_workspace"
arcpy.SaveToLayerFile_management(output_Layer, saved_Layer)
arcpy.CopyFeatures_management(wspace+saved_Layer, Output_FC)

try simply:

wspace = r"Q:\GW\EC1210WQAEH_QESEA\CSSP_ATL\Users\vanvulpenc\CSV_to_Shapefile\temp_workspace"
arcpy.CopyFeatures_management(saved_Layer, r"{0}\{1}".format(wspace,Output_FC))

I have used Python string formatting to set the full path for your output.

  • Thanks, that was the precise code used but now that I've changed the overwriteOutput to = True I'm getting a new error (above) suggesting the problem is that the feature class I'm trying to overwrite already exists. – Waterman Feb 2 '18 at 1:35
  • 1
    @Waterman If you are getting a new error then that should be researched/asked as a new question. Try hardwiring values for Input_Table and Output_FC while you are testing. – PolyGeo Feb 2 '18 at 1:37
  • New question posted here: gis.stackexchange.com/questions/270392/… – Waterman Feb 5 '18 at 23:04
  • Hardwiring the parameters results in the same error as above. – Waterman Feb 5 '18 at 23:04
  • @Waterman I think you should edit your question to reflect that hardwiring so that potential answerers do not need to configure a Python script tool to test your code. – PolyGeo Feb 5 '18 at 23:16

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.