CopyFeatures_management Crashes on Second Iteration Through Loop

306
1
12-13-2013 01:25 PM
JonathanMulder
New Contributor III
I've created an XY Event Layer, and now I want to copy that to a shape file.  It works fine on the first iteration, but crashes on the second iteration.  What seems odd, when looking in my geodatabase, the first shapefile is not named correctly; it is just called "shp", but I'm trying to name it "Data_20130626.shp".  Is there a problem in my naming syntax for ShapeName?

Thanks for any help you can provide!

Jon Mulder

# Set the workspace.
env.workspace = "G:\Documents\GIS\HydstraData"
arcpy.env.overwriteOutput = True

## Set the Spatial Reference.
Spatial_Reference = "PROJCS['NAD_1983_California_Teale_Albers',GEOGCS['GCS_North_American_1983',DATUM['D_North_American_1983',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Albers'],PARAMETER['False_Easting',0.0],PARAMETER['False_Northing',-4000000.0],PARAMETER['Central_Meridian',-120.0],PARAMETER['Standard_Parallel_1',34.0],PARAMETER['Standard_Parallel_2',40.5],PARAMETER['Latitude_Of_Origin',0.0],UNIT['Meter',1.0]]"

OutFolderPath = env.workspace
OutName = "tempgdb.gdb"
##Check if geodatabase exists.
if arcpy.Exists(OutName):
    ##Delete geodatabase.
    arcpy.Delete_management(OutName)
##Create geodatabase.    
arcpy.CreateFileGDB_management(OutFolderPath,OutName)

DateStart = date(2013,6,25)
DateEnd = date(2013,6,26)
for dt in rrule(DAILY, dtstart=DateStart, until=DateEnd):
    CurrentDate = dt.strftime("%Y%m%d")
    print CurrentDate
    ##Create Point Shapefile from spreadsheet.
    InSpreadsheet = "G:\Documents\GIS\HydstraData\HydstraMeasurementsDeep\HydstraMeasurements_" + CurrentDate + ".XLS"
    X_Coords = "LONGITUDE"
    Y_Coords = "LATITUDE"
    Z_Coords = "MeanData"
    TableName = os.path.join(OutFolderPath,OutName,"Data_" + CurrentDate)
    print TableName
    LayerName = os.path.join(OutFolderPath,OutName,"Data_" + CurrentDate + ".lyr")
    print LayerName
    ShapeName = os.path.join(OutFolderPath,OutName,"Data_" + CurrentDate + ".shp")
    print ShapeName
    arcpy.ExcelToTable_conversion(InSpreadsheet,TableName)
    arcpy.MakeXYEventLayer_management(TableName,X_Coords,Y_Coords,LayerName,"",Z_Coords)
    arcpy.CopyFeatures_management(LayerName,ShapeName)
print "Completed."


===Outout in Python Shell================================
20130625
G:\Documents\GIS\HydstraData\tempgdb.gdb\Data_20130625
G:\Documents\GIS\HydstraData\tempgdb.gdb\Data_20130625.lyr
G:\Documents\GIS\HydstraData\tempgdb.gdb\Data_20130625.shp
20130626
G:\Documents\GIS\HydstraData\tempgdb.gdb\Data_20130626
G:\Documents\GIS\HydstraData\tempgdb.gdb\Data_20130626.lyr
G:\Documents\GIS\HydstraData\tempgdb.gdb\Data_20130626.shp

Traceback (most recent call last):
  File "G:\Documents\GIS\HydstraData\CreateATinFromPoints_Mulder_20131212.py", line 55, in <module>
    arcpy.CopyFeatures_management(LayerName,ShapeName)
  File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\management.py", line 2281, in CopyFeatures
    raise e
ExecuteError: ERROR 000210: Cannot create output G:\Documents\GIS\HydstraData\tempgdb.gdb\Data_20130626.shp
Failed to execute (CopyFeatures).
Tags (2)
0 Kudos
1 Reply
T__WayneWhitley
Frequent Contributor
The whitepaper on ESRI's shapefile spec establishes an '8.3' naming convention, meaning 8 characters for the name, 3 for the file extension...so either try shortening the name or use a gdb fc format.

Here's the Shapefile Specification:
http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf

"...start with an alphanumeric character (a�??Z, 0�??9), followed by zero or up to seven characters (a�??Z, 0�??9, _, -)."

For example, maybe simply '20130625.shp'...etc., or if you want something more 'informative', give a more sensible descriptor for the name and store the date somewhere else.
0 Kudos