Saving XYEvent to Feature Class

2127
7
06-27-2014 01:03 AM
TomMcConnell
New Contributor
I have been trying to create an XY Event file from an Excel 2007 table, then preserve it as a FC in a file geodatabase.  The XY event seems to be created properly, but the Copy Features tool blows up with Error 99999.  Code follows, with error message:
# ---------------------------------------------------------------------------
# TestModel2.py
#
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy
from arcpy import env

# Set overwrite option
arcpy.env.overwriteOutput = True

# Local variables:
R20060102 = "C:\\Ameet\\Climate\\Tables\\R20060102.xlsx\\R20060102$"
X_Field = "long"
Y_Field = "lat"
Spatial_Reference = "GEOGCS['GCS_Arc_1960',DATUM['D_Arc_1960',SPHEROID['Clarke_1880_RGS',6378249.145,293.465]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]];-400 -400 1000000000;-100000 10000;-100000 10000;8.98299489570697E-09;0.001;0.001;IsHighPrecision"
R20060102Layer = "R20060102Layer"
R20060102Lyr = "C:\\Ameet\\Climate\\R20060102.lyr"
R20060102FC = "C:\\Ameet\\Climate\\Daily.gdb\\R20060102"

# Process: Make XY Event Layer
#MakeXYEventLayer_management (table, in_x_field, in_y_field, out_layer, {spatial_reference}, {in_z_field})
arcpy.MakeXYEventLayer_management(R20060102, X_Field, Y_Field, R20060102Layer, Spatial_Reference, "")
print "Event created"

# Process: Save To Layer File
#SaveToLayerFile_management (in_layer, out_layer, {is_relative_path}, {version})
#arcpy.SaveToLayerFile_management(R20060102Layer, R20060102Lyr)
#print "Layer created"

#CopyFeatures_management (in_features, out_feature_class, {config_keyword}, {spatial_grid_1}, {spatial_grid_2}, {spatial_grid_3})
arcpy.CopyFeatures_management(R20060102Lyr, R20060102FC)
print "New FC created"

Messages
Executing: CopyFeatures C:\Ameet\Climate\R20060102.lyr C:\Ameet\Climate\Daily.gdb\R20060102 # 0 0 0
Start Time: Fri Jun 27 01:51:44 2014
ERROR 999999: Error executing function.
The XY event source name has not been setup correctly.
Failed to execute (CopyFeatures).
Failed at Fri Jun 27 01:51:45 2014 (Elapsed Time: 0.53 seconds)
0 Kudos
7 Replies
HåvardMoe
New Contributor III
My guess is that it's because you are trying to copy the layer file (R20060102Lyr) and not the layer (R20060102Layer) to the new FC.

I haven't done XY events, but I have a script saving LR events where I copy the event layer directly without saving a layer file. This uses the MakeRouteEventLayer_lr:


[INDENT]MakeRouteEventLayer_lr (in_routes, route_id_field, in_table, in_event_properties, out_layer, {offset_field}, {add_error_field}, {add_angle_field}, {angle_type}, {complement_angle}, {offset_direction}, {point_event_type})[/INDENT]


The "out_layer" above goes directly into the copy feature "in_features":


[INDENT]CopyFeatures_management (in_features, out_feature_class, {config_keyword}, {spatial_grid_1}, {spatial_grid_2}, {spatial_grid_3})[/INDENT]
0 Kudos
TomMcConnell
New Contributor
Tried that; same result.
0 Kudos
IanMurray
Frequent Contributor
have you tried using a different tool to copy the data(feature class to feature class)?

Also, what is the point of making the Layer file, all it needs to run is a feature layer, not an actual .lyr file.  Like Havard said, you should only need to use the output of make xyeventlayer as the input for the copy feature(or feature class to feature class).
0 Kudos
TomMcConnell
New Contributor
Yes, I have tried Feature to Feature and Feature to Point; same result.  I suspect something is askew in my reference to to the event table.
0 Kudos
RichardFairhurst
MVP Honored Contributor
Yes, I have tried Feature to Feature and Feature to Point; same result.  I suspect something is askew in my reference to to the event table.


The spreadsheet is the suspect.  It is not a real database and could have bad fields or a so many other problems.  Try Excel to Table and use a real table as the XY Event source.  I oppose the direct use of Excel spreadsheets beyond conversion to real tables in all my posts, because of the prevalence of these problems.  Real tables enforce rules spreadsheets never will and you will only be guessing about your problem until you make it a real table.

Excel to Table should not fail, but you will probably discover that field names change or field types are not what you thought they would be.  In particular, if the X and Y fields do not import to double fields then the spreadsheet let you create data that a real table would never have let you create.
0 Kudos
HåvardMoe
New Contributor III
Ah, yes. I did not catch that the input was an excel file. I've had all kinds of cryptic errors on those, usually from bad field names (certain characters not allowed), data errors etc. What I have done in cases like this where I have an excel spread as input is to use xlrd for python to read the spreadsheet, add some data validation and then create a new table with the data I needed to use as input to create the event.

Excel to table is a 10.2 function, I believe?
0 Kudos
RichardFairhurst
MVP Honored Contributor
Excel to table is a 10.2 function, I believe?


Yes, it is a 10.2 function.  It seems to work fairly well, although it will convert almost any column with blanks to text.  But so will the XY Event layer tool, since the same programmers designed it.  Anyway, data validation has to be done first on the Excel table including conversion to a real table before using it in geoprocessing operations to make the code work reliably.
0 Kudos