Using ESRI Tutorial Data for Utility Network Tracing (Montgomery.gdb) which is a File Geodatabase and following Arcpy script I am not getting any erro on running the script to find the path between two points in Flag (point) layer
# Import arcpy module
import arcpy
# Local variables:
gnVersionFDS_Net = "E:/Montgomery.gdb/Water/Water_Net"
Flags = "E:/Montgomery.gdb/Water/Flags"
gnVersionFDS_1 = "gnVersionFDS_1_Net"
# Process: Trace Geometric Network
arcpy.TraceGeometricNetwork_management(gnVersionFDS_Net, gnVersionFDS_1, Flags, "FIND_PATH", "", "", "", "", "", "NO_TRACE_ENDS", "", "", "", "AS_IS", "", "", "", "AS_IS")
print "The Proccess Done"
I added the Flag layer manually to the Dataset and it has two points as
enter image description here again, I am not getting any error but I am not seeing any layer and path to be generated or added to somewhere. Can you please let me know what I am doing wrong or how can I make this rum properly?
Update
I try to copy the output as a shapefile using this ArcPy
arcpy.Copy_management(gnVersionFDS_1, "C:/data/path.shp")
but I am getting this error now
1 Answer 1
Your script output is a Group Layer which will be added to your ArcMap Table of Contents with a Selection Set showing your trace results. If the script is run outside of ArcMap you won't get any other output.
You could Save to Layer File to save the group layer, however this doesn't seem to include the selection set.
The group layer is the reason the arcpy.Copy_management()
didn't work - you will need to loop through the layers in the group layer and save each of those in order to output just the selection.
Something like this may work - loops through the layers in the group layer, then saves them to your GDB.
import arcpy
gnVersionFDS_Net = "E:/Montgomery.gdb/Water/Water_Net"
Flags = "E:/Montgomery.gdb/Water/Flags"
gnVersionFDS_1 = "gnVersionFDS_1_Net"
arcpy.TraceGeometricNetwork_management(gnVersionFDS_Net, gnVersionFDS_1, Flags, "FIND_PATH", "", "", "", "", "", "NO_TRACE_ENDS", "", "", "", "AS_IS", "", "", "", "AS_IS")
groupLayer = arcpy.mapping.Layer(gnVersionFDS_1)
for layer in groupLayer:
if layer.isFeatureLayer:
if layer.getSelectionSet():
print "Saving trace output from {0}".format(layer.name)
arcpy.FeatureClassToFeatureClass_conversion(layer, r"E:\Montgomery.gdb", "trace_{0}".format(layer.name))
Explore related questions
See similar questions with these tags.
arcpy.FeatureClassToFeatureClass_conversion()
orarcpy.Copy_management()
to save it to your GDB.