ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / UtilityNetworkLayer Class / GetUtilityNetwork Method
Example

In This Topic
    GetUtilityNetwork Method
    In This Topic
    Gets utility network associated with the layer. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public UtilityNetwork GetUtilityNetwork()
    Public Function GetUtilityNetwork() As UtilityNetwork

    Return Value

    The utility network associated with the layer.
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Could not open the utility network.
    Example
    Get a Utility Network from a Layer
    // This routine obtains a utility network from a FeatureLayer, SubtypeGroupLayer, or UtilityNetworkLayer
    public static UtilityNetwork GetUtilityNetworkFromLayer(Layer layer)
    {
      UtilityNetwork utilityNetwork = null;
    
      if (layer is UtilityNetworkLayer)
      {
        UtilityNetworkLayer utilityNetworkLayer = layer as UtilityNetworkLayer;
        utilityNetwork = utilityNetworkLayer.GetUtilityNetwork();
      }
    
      else if (layer is SubtypeGroupLayer)
      {
        CompositeLayer compositeLayer = layer as CompositeLayer;
        utilityNetwork = GetUtilityNetworkFromLayer(compositeLayer.Layers.First());
      }
    
      else if (layer is FeatureLayer)
      {
        FeatureLayer featureLayer = layer as FeatureLayer;
        using (FeatureClass featureClass = featureLayer.GetFeatureClass())
        {
          if (featureClass.IsControllerDatasetSupported())
          {
            IReadOnlyList<Dataset> controllerDatasets = new List<Dataset>();
            controllerDatasets = featureClass.GetControllerDatasets();
            foreach (Dataset controllerDataset in controllerDatasets)
            {
              if (controllerDataset is UtilityNetwork)
              {
                utilityNetwork = controllerDataset as UtilityNetwork;
              }
              else
              {
                controllerDataset.Dispose();
              }
            }
          }
        }
      }
      return utilityNetwork;
    }
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also