ArcGIS Pro 3.8 API Reference Guide
ArcGIS.Core.Data.UtilityNetwork Namespace / AssetGroup Class / GetAssetType Method
The name of the AssetType to return.
Example

In This Topic
    GetAssetType Method
    In This Topic
    Gets an AssetType object with the specified name. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public AssetType GetAssetType( 
       string assetTypeName
    )
    Public Function GetAssetType( _
       ByVal assetTypeName As String _
    ) As AssetType

    Parameters

    assetTypeName
    The name of the AssetType to return.

    Return Value

    The AssetType that corresponds to assetTypeName.
    Exceptions
    ExceptionDescription

    assetTypeName is null or an empty string.

    -or-

    There is no AssetType that corresponds to assetTypeName.

    A geodatabase-related exception has occurred.
    Remarks
    The string comparison used to find the name is case-insensitive.
    Example
    Export a utility network trace as a JSON file
    {
      // This routine demonstrates how to perform a trace and export the results as a JSON file
      static void ExportUtilityNetworkTraceAsJSON(UtilityNetwork utilityNetwork)
      {
        using (TraceManager traceManager = utilityNetwork.GetTraceManager())
        using (UtilityNetworkDefinition utilityNetworkDefinition = utilityNetwork.GetDefinition())
        using (NetworkSource deviceNetworkSource = GetNetworkSource(utilityNetworkDefinition, "GasDevice") as NetworkSource)
        using (FeatureClass distributionDeviceFeatureClass = utilityNetwork.GetTable(deviceNetworkSource) as FeatureClass)
        using (FeatureClassDefinition distributionDeviceDefinition = distributionDeviceFeatureClass.GetDefinition())
        using (AssetGroup deviceAssetGroup = deviceNetworkSource.GetAssetGroup("Regulator"))
        using (AssetType deviceAssetType = deviceAssetGroup.GetAssetType("Pressure Reducing"))
        using (NetworkAttribute deviceStatusNetworkAttribute = utilityNetworkDefinition.GetNetworkAttribute("DeviceStatus"))
        using (NetworkAttribute accessibleNetworkAttribute = utilityNetworkDefinition.GetNetworkAttribute("Accessible"))
        {
          // Domain and tier information
          DomainNetwork domainNetwork = utilityNetworkDefinition.GetDomainNetwork("Gas");
          Tier pipeDistributionSystemTier = domainNetwork.GetTier("Pipe Distribution");
    
          // Start elements
          Element startingPoint1 = utilityNetwork.CreateElement(deviceAssetType, Guid.Parse("{28CF437E-950C-41B7-B839-8BC45570DE40}"));
          Element startingPoint2 = utilityNetwork.CreateElement(deviceAssetType, Guid.Parse("{63C22828-7BC9-49ED-A14A-A596559B6CB3}"));
    
          startingPoint1.Terminal = startingPoint1.AssetType.GetTerminalConfiguration().Terminals
            .First(x => x.IsUpstreamTerminal);
          startingPoint2.Terminal = startingPoint2.AssetType.GetTerminalConfiguration().Terminals
            .First(x => x.IsUpstreamTerminal);
    
          List<Element> startingPoints = [startingPoint1, startingPoint2];
          List<Element> barriers = [];
    
          // Set up trace filter: DeviceStatus = Open (1) AND Accessible = 1
          NetworkAttributeComparison statusNetworkAttributeComparison = new NetworkAttributeComparison(deviceStatusNetworkAttribute, Operator.Equal, 1);
          NetworkAttributeComparison networkAttributeComparison = new NetworkAttributeComparison(accessibleNetworkAttribute, Operator.Equal, 1);
    
          // Set trace configuration
          TraceConfiguration traceConfiguration = new TraceConfiguration
          {
            AllowIndeterminateFlow = true,
            IgnoreBarriersAtStartingPoints = false,
            IncludeBarriersWithResults = true,
            IncludeContainers = true,
            IncludeContent = true,
            IncludeIsolatedFeatures = false,
            IncludeUpToFirstSpatialContainer = false
          };
    
          traceConfiguration.Filter.Barriers = new And(statusNetworkAttributeComparison, networkAttributeComparison);
          traceConfiguration.DomainNetwork = domainNetwork;
          traceConfiguration.SourceTier = pipeDistributionSystemTier;
    
          // Attribute fields of a network source
          List<string> deviceFields = distributionDeviceDefinition.GetFields().Select(f => f.Name).ToList();
    
          // Network attributes
          List<string> networkattributeNames = new List<string>();
    
          IReadOnlyList<NetworkAttribute> networkAttributes = utilityNetworkDefinition.GetNetworkAttributes();
    
          foreach (NetworkAttribute networkAttribute in networkAttributes)
          {
            networkattributeNames.Add(networkAttribute.Name);
          }
    
          // Result Types
          List<ResultType> resultTypeList = new List<ResultType>() { ResultType.Feature };
    
          // Resutl Options
          ResultOptions resultOptions = new ResultOptions()
          {
            IncludeGeometry = true,
            NetworkAttributes = networkattributeNames,
            ResultFields = new Dictionary<NetworkSource, List<string>>() { { deviceNetworkSource, deviceFields } }
          };
    
          // Trace Arguments
          TraceArgument traceArgument = new TraceArgument(startingPoints)
          {
            Barriers = barriers,
            Configuration = traceConfiguration,
            ResultTypes = resultTypeList,
            ResultOptions = resultOptions
          };
    
          ConnectedTracer connectedTracer = traceManager.GetTracer<ConnectedTracer>();
    
          // Set export options
          TraceExportOptions exportOptions = new TraceExportOptions()
          {
            ServiceSynchronizationType = ServiceSynchronizationType.Asynchronous,
            IncludeDomainDescriptions = true,
          };
    
          // Path to export JSON
          string jsonPath = $"{Path.GetTempPath()}TraceResults.json";
          Uri jsonUri = new Uri(jsonPath);
    
          // Export
          connectedTracer.Export(jsonUri, traceArgument, exportOptions);
    
          string jsonAbsolutePath = HttpUtility.UrlDecode(jsonUri.AbsolutePath);
          if (jsonUri.IsFile && File.Exists(jsonAbsolutePath))
          {
            // Work with the JSON results
          }
        }
    
        NetworkSource GetNetworkSource(UtilityNetworkDefinition unDefinition, string name)
        {
          IReadOnlyList<NetworkSource> allSources = unDefinition.GetNetworkSources();
          foreach (NetworkSource source in allSources)
          {
            if (name.Contains("Partitioned Sink"))
            {
              if (source.Name.Replace(" ", "").ToUpper().Contains(name.Replace(" ", "").ToUpper()) ||
                  source.Name.Replace(" ", "").ToUpper()
                    .Contains(name.Replace("Partitioned Sink", "Part_Sink").Replace(" ", "").ToUpper()))
              {
                return source;
              }
            }
    
            if (name.Contains("Hierarchical Sink"))
            {
              if (source.Name.Replace(" ", "").ToUpper().Contains(name.Replace(" ", "").ToUpper()) ||
                  source.Name.Replace(" ", "").ToUpper()
                    .Contains(name.Replace("Hierarchical Sink", "Hier_Sink").Replace(" ", "").ToUpper()))
              {
                return source;
              }
            }
    
            if (source.Name.Replace(" ", "").ToUpper().Contains(name.Replace(" ", "").ToUpper()))
            {
              return source;
            }
          }
          return null;
        }
      }
    }
    Fetch features and network attributes from a utility network during trace
    {
      // This routine demonstrates how to fetch features and network attributes from a utility network during a trace
      static void FetchFeaturesAndAttributes(UtilityNetwork utilityNetwork)
      {
        using (Geodatabase geodatabase = utilityNetwork.GetDatastore() as Geodatabase)
        using (TraceManager traceManager = utilityNetwork.GetTraceManager())
        using (UtilityNetworkDefinition utilityNetworkDefinition = utilityNetwork.GetDefinition())
        using (NetworkSource deviceNetworkSource = GetNetworkSource(utilityNetworkDefinition, "GasDevice") as NetworkSource)
        using (FeatureClass distributionDeviceFeatureClass = utilityNetwork.GetTable(deviceNetworkSource) as FeatureClass)
        using (FeatureClassDefinition distributionDeviceDefinition = distributionDeviceFeatureClass.GetDefinition())
        using (AssetGroup deviceAssetGroup = deviceNetworkSource.GetAssetGroup("Regulator"))
        using (AssetType deviceAssetType = deviceAssetGroup.GetAssetType("Pressure Reducing"))
        using (NetworkAttribute deviceStatusNetworkAttribute = utilityNetworkDefinition.GetNetworkAttribute("DeviceStatus"))
        using (NetworkAttribute accessibleNetworkAttribute = utilityNetworkDefinition.GetNetworkAttribute("Accessible"))
        using (RelationshipClass valveInspectionRelationshipClass = geodatabase.OpenDataset<RelationshipClass>("GasDeviceToValveInspection"))
        using (Table valveInspection = geodatabase.OpenDataset<Table>("ValveInspection"))
        using (TableDefinition valveInspectionDefn = valveInspection.GetDefinition())
        {
          // Domain and tier information
          DomainNetwork domainNetwork = utilityNetworkDefinition.GetDomainNetwork("Gas");
          Tier pipeDistributionSystemTier = domainNetwork.GetTier("Pipe Distribution");
    
          // Start elements
          Element startingPoint1 = utilityNetwork.CreateElement(deviceAssetType, Guid.Parse("{28CF437E-950C-41B7-B839-8BC45570DE40}"));
          Element startingPoint2 = utilityNetwork.CreateElement(deviceAssetType, Guid.Parse("{63C22828-7BC9-49ED-A14A-A596559B6CB3}"));
    
          startingPoint1.Terminal = startingPoint1.AssetType.GetTerminalConfiguration().Terminals
            .First(x => x.IsUpstreamTerminal);
          startingPoint2.Terminal = startingPoint2.AssetType.GetTerminalConfiguration().Terminals
            .First(x => x.IsUpstreamTerminal);
    
          List<Element> startingPoints = new List<Element>() { startingPoint1, startingPoint2 };
          List<Element> barriers = new List<Element>();
    
          // Set up trace filter: DeviceStatus = Open (1) AND Accessible = 1
          NetworkAttributeComparison statusNetworkAttributeComparison = new NetworkAttributeComparison(deviceStatusNetworkAttribute, Operator.Equal, 1);
          NetworkAttributeComparison networkAttributeComparison = new NetworkAttributeComparison(accessibleNetworkAttribute, Operator.Equal, 1);
    
          // Set trace configuration
          TraceConfiguration traceConfiguration = new TraceConfiguration
          {
            AllowIndeterminateFlow = true,
            IgnoreBarriersAtStartingPoints = false,
            IncludeBarriersWithResults = true,
            IncludeContainers = true,
            IncludeContent = true,
            IncludeIsolatedFeatures = false,
            IncludeUpToFirstSpatialContainer = false
          };
    
          traceConfiguration.Filter.Barriers = new And(statusNetworkAttributeComparison, networkAttributeComparison);
          traceConfiguration.DomainNetwork = domainNetwork;
          traceConfiguration.SourceTier = pipeDistributionSystemTier;
    
          // Attribute fields of a network source
          List<string> deviceFields = distributionDeviceDefinition.GetFields().Select(f => f.Name).ToList();
    
          // Network attributes
          List<string> networkattributeNames = new List<string>();
    
          IReadOnlyList<NetworkAttribute> networkAttributes = utilityNetworkDefinition.GetNetworkAttributes();
    
          foreach (NetworkAttribute networkAttribute in networkAttributes)
          {
            networkattributeNames.Add(networkAttribute.Name);
          }
    
          // Get the field names for the related records table (ValveInspection)
          IReadOnlyList<Field> valveRelatedRecords = valveInspectionDefn.GetFields();
          List<string> valveFieldNames = valveRelatedRecords.Select(f => f.Name).ToList();
    
          // Result Types
          List<ResultType> resultTypeList = new List<ResultType>() { ResultType.Feature, ResultType.RelatedRecord };
    
          // Resutl Options
          ResultOptions resultOptions = new ResultOptions()
          {
            IncludeGeometry = true,
            NetworkAttributes = networkattributeNames,
            ResultFields = new Dictionary<NetworkSource, List<string>>() { { deviceNetworkSource, deviceFields } },
            RelatedRecordFields = new Dictionary<RelationshipClass, List<string>>() { { valveInspectionRelationshipClass, valveFieldNames } }
          };
    
          // Trace Arguments
          TraceArgument traceArgument = new TraceArgument(startingPoints)
          {
            Barriers = barriers,
            Configuration = traceConfiguration,
            ResultTypes = resultTypeList,
            ResultOptions = resultOptions
          };
    
          // Tracer
          ConnectedTracer connectedTracer = traceManager.GetTracer<ConnectedTracer>();
    
          // Async trace result
          IReadOnlyList<Result> traceResults =
            connectedTracer.Trace(traceArgument, ServiceSynchronizationType.Asynchronous);
    
          // Iterate trace results
          foreach (Result traceResult in traceResults)
          {
            if (traceResult is FeatureElementResult featureElementResult)
            {
              IReadOnlyList<FeatureElement> featureElements = featureElementResult.FeatureElements;
    
              // Iterate through the feature elements
              foreach (FeatureElement featureElement in featureElements)
              {
                // Get the field values specified in the `ResultOptions`
                IReadOnlyList<TraceResultFieldValue> resultFieldValues = featureElement.ResultFieldValues;
    
                foreach (TraceResultFieldValue fieldValue in resultFieldValues)
                {
                  if (fieldValue.FieldType == FieldType.Geometry)
                  {
                    // Get the geometry of the feature
                    Geometry geometry = fieldValue.Value as Geometry;
                  }
                }
                // Get the Network attribute values specified in the `ResultOptions`
                IReadOnlyList<TraceResultFieldValue> networkAttributeValues = featureElement.ResultNetworkAttributeValues;
              }
            }
    
            if (traceResult is RelatedRecordResult relatedRecordResult)
            {
              IReadOnlyList<RelatedRecord> relatedRecords = relatedRecordResult.RelatedRecords;
              // Iterate through the related records
              foreach (RelatedRecord relatedRecord in relatedRecords)
              {
                IReadOnlyList<RelationshipClassValue> relationshipClassValues = relatedRecord.RelationshipClassValues;
                foreach (RelationshipClassValue relationshipClassValue in relationshipClassValues)
                {
                  // Access the IDs and name associated with this relationship class
                  var destinationId = relationshipClassValue.DestinationID;
                  var name = relationshipClassValue.Name;
                  var originId = relationshipClassValue.OriginID;
    
                  // Access the relationship values associated with this relationship class 
                  IReadOnlyList<RelationshipValue> relationshipValues = relationshipClassValue.RelationshipValues;
                  foreach (RelationshipValue relationshipValue in relationshipValues)
                  {
                    // Geometry associated with this relationship value
                    Geometry geometry = relationshipValue.Geometry;
    
                    // Out fields associated with non attributed relationship class
                    IReadOnlyList<TraceResultFieldValue> outFields = relationshipValue.OutFields;
    
                    // Out fields associated with attributed relationship class
                    // IReadOnlyList<TraceResultFieldValue> relationshipOutFields = relationshipValue.RelationshipOutFields;
                  }
                }
              }
            }
          }
        }
    
        // Helper inline function
        NetworkSource GetNetworkSource(UtilityNetworkDefinition unDefinition, string name)
        {
          IReadOnlyList<NetworkSource> allSources = unDefinition.GetNetworkSources();
          foreach (NetworkSource source in allSources)
          {
            if (name.Contains("Partitioned Sink"))
            {
              if (source.Name.Replace(" ", "").ToUpper().Contains(name.Replace(" ", "").ToUpper()) ||
                  source.Name.Replace(" ", "").ToUpper()
                    .Contains(name.Replace("Partitioned Sink", "Part_Sink").Replace(" ", "").ToUpper()))
              {
                return source;
              }
            }
    
            if (name.Contains("Hierarchical Sink"))
            {
              if (source.Name.Replace(" ", "").ToUpper().Contains(name.Replace(" ", "").ToUpper()) ||
                  source.Name.Replace(" ", "").ToUpper()
                    .Contains(name.Replace("Hierarchical Sink", "Hier_Sink").Replace(" ", "").ToUpper()))
              {
                return source;
              }
            }
    
            if (source.Name.Replace(" ", "").ToUpper().Contains(name.Replace(" ", "").ToUpper()))
            {
              return source;
            }
          }
    
          return null;
        }
      }
    }
    Create a Telecom Element and Circuit Location in the utility network
    await QueuedTask.Run(() =>
    {
      using (NetworkSource networkSource = telecomDomainNetwork.NetworkSources.FirstOrDefault(ns => ns.Name.Contains(assetGroupName)))
      using (AssetGroup assetGroup = networkSource.GetAssetGroup(assetTypeName))
      using (AssetType assetType = assetGroup.GetAssetType(assetTypeName))
      {
        if (assetType == null)
        {
          throw new Exception($"Asset type '{assetTypeName}' not found in group '{assetGroupName}'.");
        }
    
        TelecomElement telecomElement = utilityNetwork.CreateElement(assetType, globalID) as TelecomElement;
    
        // Use the telecom element to create a circuit location.
        CircuitLocation circuitLocation = new CircuitLocation(telecomElement);
      }
    });
    Run a path trace in the telecom domain network
    await QueuedTask.Run(() =>
    {
      using (TraceManager traceManager = utilityNetwork.GetTraceManager())
      using (NetworkSource deviceNetworkSource = telecomDomainNetwork.NetworkSources.First(f => f.Name.Contains("TelecomDevice")))
      using (AssetGroup assetGroup = deviceNetworkSource.GetAssetGroup("Port"))
      using (AssetType assetType = assetGroup.GetAssetType("Port"))
      {
        Guid startGuid = new Guid("4BB4560A-34F3-4BBA-93D5-C5D6B26F2709");
        Guid stopGuid = new Guid("32203C76-E484-473A-AEA5-B1AB92A0C198");
    
        TelecomElement startElement = utilityNetwork.CreateElement(assetType, startGuid) as TelecomElement;
        TelecomElement stopElement = utilityNetwork.CreateElement(assetType, stopGuid) as TelecomElement;
    
        List<TelecomElement> startingLocations = new List<TelecomElement>() { startElement };
        List<TelecomElement> stoppingLocations = new List<TelecomElement>() { stopElement };
    
        // Path trace configuration 
        TraceConfiguration traceConfiguration = new TraceConfiguration()
        {
          MaxHops = 100,
          NumPaths = 2,
          DomainNetwork = telecomDomainNetwork,
          ValidateConsistency = true
        };
    
        // Trace argument for the path trace with the starting and stopping locations
        TraceArgument traceArgument = new TraceArgument(startingLocations)
        {
          StoppingLocations = stoppingLocations,
          Configuration = traceConfiguration,
          ResultTypes = new List<ResultType>() { ResultType.Path },
          ResultOptions = new ResultOptions { IncludeGeometry = true }
        };
    
        // Run the path trace asynchronously
        PathTracer pathTracer = traceManager.GetTracer<PathTracer>();
        IReadOnlyList<Result> results = pathTracer.Trace(traceArgument, ServiceSynchronizationType.Asynchronous);
        // Iterate through the path trace results
        foreach (Result result in results)
        {
          if (result is PathResult pathResult)
          {
            IReadOnlyList<TracePath> paths = pathResult.Paths;
            foreach (TracePath path in paths)
            {
              Element startLocation = path.StartLocation;
              Element stopLocation = path.StopLocation;
              Geometry pathGeometry = path.Geometry;
              IReadOnlyList<PathConnectivity> pathConnectivities = path.PathConnectivities;
    
              foreach (PathConnectivity pathConnectivity in pathConnectivities)
              {
                Console.WriteLine($"Edge: {pathConnectivity.Edge.GlobalID}, Junction: {pathConnectivity.Junction.GlobalID}");
              }
            }
          }
          else
          {
            Console.WriteLine("Unexpected result type.");
          }
        }
      }
    });
    Add or delete an association between Telecom elements in the utility network
    await QueuedTask.Run(() =>
    {
      using (NetworkSource junctionNetworkSource = telecomDomainNetwork.NetworkSources.FirstOrDefault(ns => ns.Name.Contains("TelcoDevice")))
      using (NetworkSource edgeNetworkSource = telecomDomainNetwork.NetworkSources.FirstOrDefault(ns => ns.Name.Contains("TelcoEdgeObject")))
      {
        TelecomElement junction = utilityNetwork.CreateElement(junctionNetworkSource.GetAssetGroup("Fiber").GetAssetType("Fiber"),
                  new Guid("CCFCF5DE-5B90-4FD9-A459-2F2E88107532")) as TelecomElement;
    
        TelecomElement edgeObject = utilityNetwork.CreateElement(edgeNetworkSource.GetAssetGroup("Fiber").GetAssetType("Fiber"),
                  new Guid("838B4A2B-8531-499D-8DCF-8567901D43D9")) as TelecomElement;
    
        Association association = new Association(AssociationType.JunctionEdgeObjectConnectivityMidspan, junction, edgeObject, 0.3);
    
        // Create the association from the port to the fiber.
        geodatabase.ApplyEdits(() =>
              {
                utilityNetwork.AddAssociation(association);
              });
        // Delete the association
        geodatabase.ApplyEdits(() =>
              {
                utilityNetwork.DeleteAssociation(association);
              });
      }
    
    });
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also