arcpy - saving results from a geometric network trace

3556
3
Jump to solution
01-09-2016 02:30 AM
GregKing
New Contributor

Hi,

I’m writing a script to perform some traces of a geometric network.  So far I have managed to create the script to setup all the layers and run the trace.  The result is the selection of the geometric network elements within a selection group.

The issue I am having is how to then save out the traced features into a separate feature class from the selection group.  Has anyone done this through python/arcpy previously and can provide some guidance?

Regards

Greg

0 Kudos
1 Solution

Accepted Solutions
KevinHibma
Esri Regular Contributor

The output from Trace is actually a group layer. So you need to "select" the particular item out of the group layer you want before you can do something with it. In Modelbuilder, this is pretty straight forward as you'd use the Select tool (only available within Modelbuilder). With a script, you need to properly reference the layer inside the group that you want.

arcpy.Snap_edit(Flags, "'Primary OH Conductor' VERTEX '30 Meters'")

arcpy.TraceGeometricNetwork_management(El_Paso_Electric, "Storm_Net", Flags, "TRACE_UPSTREAM", "", "", "", "", "", "NO_TRACE_ENDS", "TRACE_INDETERMINATE_FLOW", "", "", "AS_IS", "", "", "", "AS_IS")

network = arcpy.mapping.Layer("Storm_Net")

if network.isGroupLayer:

    for sublayer in network:

        arcpy.AddMessage("  {} ".format(sublayer.name))

# Process: Select Data

#arcpy.SelectData_management("Storm_Net", "ServiceLocation")  # <--- dont use

# Build up the path to the item you want, in this case, "Storm_Net" is my output Trace, and "ServiceLocation" is the item inside I want.

arcpy.CopyFeatures_management("Storm_Net/ServiceLocation", outputFeatureClass)

FYI: Output from the AddMessage to list items in the GroupLayer:

  •   ElectricDataset_Net_Junctions
  •   MiscNetworkFeatureBank
  •   SwitchBank
  •   CapacitorBank
  •   FuseBank
  •   RegulatorBank
  •   Light
  •   Generator
  •   DynamicProtectiveDeviceBank
  •   Motor
  •   ServiceLocation
  •   TransformerBank
  •   Flags
  •   SecondaryUGLineSection
  •   SecondaryOHLineSection
  •   PrimaryOHLineSection
  •   PrimaryUGLineSection

View solution in original post

3 Replies
DanPatterson_Retired
MVP Emeritus

Did you try ... Copy Features

you may have to use MakeFeatureLayer first as per the trace help topic

Trace Geometric Network

ie

arcpy.CopyFeatures_management("your layer , "output filename including path")

KevinHibma
Esri Regular Contributor

The output from Trace is actually a group layer. So you need to "select" the particular item out of the group layer you want before you can do something with it. In Modelbuilder, this is pretty straight forward as you'd use the Select tool (only available within Modelbuilder). With a script, you need to properly reference the layer inside the group that you want.

arcpy.Snap_edit(Flags, "'Primary OH Conductor' VERTEX '30 Meters'")

arcpy.TraceGeometricNetwork_management(El_Paso_Electric, "Storm_Net", Flags, "TRACE_UPSTREAM", "", "", "", "", "", "NO_TRACE_ENDS", "TRACE_INDETERMINATE_FLOW", "", "", "AS_IS", "", "", "", "AS_IS")

network = arcpy.mapping.Layer("Storm_Net")

if network.isGroupLayer:

    for sublayer in network:

        arcpy.AddMessage("  {} ".format(sublayer.name))

# Process: Select Data

#arcpy.SelectData_management("Storm_Net", "ServiceLocation")  # <--- dont use

# Build up the path to the item you want, in this case, "Storm_Net" is my output Trace, and "ServiceLocation" is the item inside I want.

arcpy.CopyFeatures_management("Storm_Net/ServiceLocation", outputFeatureClass)

FYI: Output from the AddMessage to list items in the GroupLayer:

  •   ElectricDataset_Net_Junctions
  •   MiscNetworkFeatureBank
  •   SwitchBank
  •   CapacitorBank
  •   FuseBank
  •   RegulatorBank
  •   Light
  •   Generator
  •   DynamicProtectiveDeviceBank
  •   Motor
  •   ServiceLocation
  •   TransformerBank
  •   Flags
  •   SecondaryUGLineSection
  •   SecondaryOHLineSection
  •   PrimaryOHLineSection
  •   PrimaryUGLineSection
jloiseaux
New Contributor II

Hi, Thank you. I am running a weekly script to calculate fire hydrants coverage using Network Analyst.

From time to time the script was stuck on arcpy.SelectData_management("LayerA", "Lines").

  I ve just changed it to "LayerA/Lines" into a variable as you suggested in your post and now it does not get stuck anymore.  Thanks.

Greetings from France,

Have a great day.

Julien Loiseaux.

0 Kudos