Work with trace results

Depending on what you need to do with the results, you can work with the appropriate return type you configured in the trace parameters. The following types of results may be returned when executing the trace:

  • Elements—Element results provide the utility elements that are found by a trace. Use these results when you need access to individual utility elements, their corresponding features, and their attributes. This is the default trace result type.

  • Geometry—Geometry results contains multipart geometries that represent the union of the geometry for all elements returned. These results are best for displaying the trace result on a map.

  • Functions—A function is a trace configuration that allows you to run calculations on network attributes associated with traced features. A function output is returned for every function defined in the configuration.

Use dark colors for code blocksCopy
                  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
ListenableFuture> utilityTraceResultsListenableFuture;
utilityTraceResultsListenableFuture = utilityNetwork.traceAsync(utilityTraceParameters);
utilityTraceResultsListenableFuture.addDoneListener(() -> {
  try {
    List utilityTraceResults = utilityTraceResultsListenableFuture.get();
    if (utilityTraceResults.get(0) != null) {
      if (utilityTraceResults.get(0) instanceof UtilityElementTraceResult) {
        UtilityElementTraceResult utilityElementTraceResult = (UtilityElementTraceResult) utilityTraceResults.get(0);
        List elements = utilityElementTraceResult.getElements();
        if (!elements.isEmpty()) {
          // check if there are any elements in the first trace result
          System.out.println("Count of utility elements in first trace result is: " + elements.size());
          // process trace results here
        }
      }
    }
  }
});

Element results

If you need fine-grained access to the results, such as the ability to work with individual utility elements from the trace, you need to obtain the corresponding features for these elements from the utility element results.

You can use the element's network source to match its table against the layer's table by instance or name.

For every group (network source with utility elements), make sure there is a layer in the map for the features. Next, find the features corresponding to the utility elements.

Use dark colors for code blocksCopy
                                          
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// get the first result of the utility trace and then the elements in that result
utilityElementTraceResult = (UtilityElementTraceResult) utilityTraceResults.get(0);
utilityElements = utilityElementTraceResult.getElements();
// group together utility elements that have the same network source
List utilityElementsWithSameNetworkSource;
if (!utilityElements.isEmpty()) {
  // make a HashMap of key-value pairs where key is the name of a UtilityNetworkSource and
  // value is a list of utility elements in that UtilityNetworkSource
  HashMap> hashMap = new HashMap<>();
  for (UtilityElement utilityElement : utilityElements) {
    String utilityNetworkSourceName = utilityElement.getNetworkSource().getName();
    // if utilityNetworkSourceName is already a key, get the corresponding list of elements
    if (hashMap.containsKey(utilityNetworkSourceName)) {
      utilityElementsWithSameNetworkSource = hashMap.get(utilityNetworkSourceName);
    }
    // if utilityNetworkSourceName is not a key, create a new list of elements
    else {
      utilityElementsWithSameNetworkSource = new ArrayList<>();
    }
    // add current utility element to the list of elements
    utilityElementsWithSameNetworkSource.add(utilityElement);
    // update the hashMap with the new/modified key-value pair
    hashMap.put(utilityNetworkSourceName, utilityElementsWithSameNetworkSource);
  }
  // ensure that the features' layer exists in the map
  for (Map.Entry> entry : hashMap.entrySet()) {
    FeatureLayer layer = (FeatureLayer) map.getOperationalLayers().get(0);
    if (layer.getFeatureTable().getTableName().equals(entry.getKey())) {
      // get the features that correspond to the elements
      ListenableFuture> arcGISFeatureListListenableFuture;
      arcGISFeatureListListenableFuture = utilityNetwork.fetchFeaturesForElementsAsync(entry.getValue());
      arcGISFeatureListListenableFuture.addDoneListener(() -> {
        try {
          List arcGISFeatureList = arcGISFeatureListListenableFuture.get();
        } catch (InterruptedException | ExecutionException e) {
          e.printStackTrace();
        }
      });
    }
  }
} else
  System.out.println("First trace result is empty");

Select the features that correspond to the trace result or process as required.

Use dark colors for code blocksCopy
            
1
2
3
4
5
6
7
8
9
10
11
12
arcGISFeatureListListenableFuture = utilityNetwork.fetchFeaturesForElementsAsync(entry.getValue());
arcGISFeatureListListenableFuture.addDoneListener(() -> {
  try {
    List arcGISFeatureList = arcGISFeatureListListenableFuture.get();
    // select features to highlight result
    for (ArcGISFeature arcGISFeature : arcGISFeatureList){
      layer.selectFeature(arcGISFeature);
    }
  } catch (InterruptedException | ExecutionException e) {
    e.printStackTrace();
  }
});

Function results

If function results are included, they will contain a UtilityTraceFunctionOutput for every UtilityTraceFunction that was defined in the UtilityTraceConfiguration. Each UtilityTraceFunctionOutput contains the original function definition as well as the function result.

Geometry results

Geometry results make it easy to display the trace result as graphics in the map view. At most, geometry results will contain three (multipart) geometries: one multipoint, one polyline, and one polygon. Each geometry represents the union of the geometry of the results of that spatial type. The UtilityGeometryTraceResult exposes the geometry result for each potential geometry type. If the result does not include a certain geometry type, the corresponding property will be null.

Get the geometry results from the trace results. Depending how the trace parameters were defined (i.e. which result types were requested), there may be more than one result type. Create a new graphic for each geometry in the geometry results, check if there's any need to reproject to the map's spatial reference, use a symbology appropriate for the geometry type, and add them to a graphics overlay in the map view.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.