0

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

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

enter image description here

  • Are you running the trace in ArcMap? – Midavalo Mar 15 '17 at 18:09
  • This is an stand alone ArcPy script so not sure what exactly do you mean? – user1106951 Mar 15 '17 at 18:26
  • Your output is a layer so I would expect it to display itself in ArcMap. – Midavalo Mar 15 '17 at 18:27
  • If not in ArcMap you may need to arcpy.FeatureClassToFeatureClass_conversion() or arcpy.Copy_management() to save it to your GDB. – Midavalo Mar 15 '17 at 18:29
  • Try pasting your code into the Python window in ArcMap – Midavalo Mar 15 '17 at 18:31
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))
| improve this answer | |

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.