I have a line with begin and end node XY data (IHS_NET_EDIT_DISSOLVE) and would like to create a point feature class representing the begin and end nodes. With the following code I am able to successfully create the XY event layers, but the resulting feature classes are empty:
arcpy.MakeXYEventLayer_management(IHS_NET_EDIT_DISSOLVE, "START_X", "START_Y", "lyrBeginNodes")
arcpy.MakeXYEventLayer_management(IHS_NET_EDIT_DISSOLVE, "END_X", "END_Y", "lyrEndNodes")
print("Begin Node Layer Count: " + str(arcpy.GetCount_management("lyrBeginNodes")))
print("End Node Layer Count: " + str(arcpy.GetCount_management("lyrEndNodes")))
arcpy.FeatureClassToFeatureClass_conversion("lyrBeginNodes", outputPath, "BeginNodes")
arcpy.FeatureClassToFeatureClass_conversion("lyrEndNodes", outputPath, "EndNodes")
print("Begin Node FC Count: " + str(arcpy.GetCount_management("BeginNodes")))
print("End Node FC Count: " + str(arcpy.GetCount_management("EndNodes")))
As you can see from what's printed, the layer counts look good, but the feature classes are empty:
>>>
Begin Node Layer Count: 2452
End Node Layer Count: 2452
Begin Node FC Count: 0
End Node FC Count: 0
>>>
What am I doing wrong here? I imagine it has to do with how I'm referencing the layers as input, but I don't know how else to make it work.
1 Answer 1
I found the answer - it turns out in my case that the problem wasn't with FeatcureClassToFeatureClass, but with the spatial reference. Somewhere along the line the spatial reference setting (which I thought is supposed to default to the spatial reference of the input feature) wasn't adding up and the resulting coordinates were out of bounds, resulting in an empty feature class.
My solution was to set sref = arcpy.Describe(IHS_NET_EDIT).spatialReference
then set the spatial reference parameters to sref for both AddGeometryAttributes_management and MakeXYEventLayer_management.
arcpy.FeatureClassToFeatureClass_conversion
directly after eacharcpy.MakeXYEventLayer_management
and see if this can solve the issue.arcpy.SaveToLayerFile_management()
which works witharcpy.MakeXYEventLayer_management()
before usingarcpy.FeatureClassToFeatureClass_conversion()
. You can refer to the help ofarcpy.MakeXYEventLayer_management()
: desktop.arcgis.com/en/arcmap/10.3/tools/data-management-toolbox/…