Depending on what you need to do with the results, you can work with the appropriate return type you configured in the trace A trace is an action that analyzes the paths in a utility network and returns features based on connectivity or traversability from the specified starting points. Learn more parameters. The following types of results may be returned when executing the trace:

  • Elements—Element results provide the utility elements A utility element is an entity in a utility network that corresponds to a feature or a part of a feature (for example, a terminal inside a device). Learn more that are found by a trace. Use these results when you need access to individual utility elements, their corresponding features A feature is a single record, also known as a row, that represents a real-world entity. It typically contains a geometry (point, multipoint, polyline, or polygon) and attributes but it can also contain just attributes. Learn more , and their attributes Attributes are fields and values for a single feature or non-spatial record. They are typically stored in a database or service such as a feature service. Learn more . This is the default trace result type.

  • Geometry—Geometry results contains multipart geometries that represent the union of the geometry A geometry is a geometric shape, such as a point, polyline, or polygon, that contains one or more coordinates and a spatial reference. Learn more 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.

// Execute the network utility trace.
ListenableFuture<List<UtilityTraceResult>> utilityTraceResultsListenableFuture =
utilityNetwork.traceAsync(utilityTraceParameters);
// Wait for the trace to complete.
utilityTraceResultsListenableFuture.addDoneListener(() -> {
try {
// Get the trace results.
List<UtilityTraceResult> utilityTraceResults = utilityTraceResultsListenableFuture.get();
// Check that there is a trace result, then get the first result of the utility trace.
if (utilityTraceResults.getFirst() != null &&
utilityTraceResults.getFirst() instanceof UtilityElementTraceResult utilityElementTraceResult) {
// Get the elements in the trace result.
List<UtilityElement> utilityElements = utilityElementTraceResult.getElements();
if (!utilityElements.isEmpty()) {
// Check if there are any elements in the first trace result.
System.out.println("Count of utility elements in first trace result is: "
+ utilityElements.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 A utility element is an entity in a utility network that corresponds to a feature or a part of a feature (for example, a terminal inside a device). Learn more from the trace A trace is an action that analyzes the paths in a utility network and returns features based on connectivity or traversability from the specified starting points. Learn more , you need to obtain the corresponding features A feature is a single record, also known as a row, that represents a real-world entity. It typically contains a geometry (point, multipoint, polyline, or polygon) and attributes but it can also contain just attributes. Learn more for these elements from the utility element results.

You can use the element’s network source A network source is a feature table whose features comprise one of a utility network's datasets. Learn more to match its table A table is a non-spatial dataset in a feature service. All records in a table share the same set of fields. Learn more 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.

// (continued from above)
// Make a hash map of key-value pairs where key is the name of a utility network source
// and value is a list of utility elements in that utility network source.
HashMap<String, List<UtilityElement>> hashMap = new HashMap<>();
for (UtilityElement utilityElement : utilityElements) {
// Group together utility elements that have the same network source.
List<UtilityElement> utilityElementsWithSameNetworkSource;
String utilityNetworkSourceName = utilityElement.getNetworkSource().getName();
// If the utility network source name is already a key, then get the
// corresponding list of elements.
if (hashMap.containsKey(utilityNetworkSourceName)) {
utilityElementsWithSameNetworkSource = hashMap.get(utilityNetworkSourceName);
} else {
// If utility network source name is not a key, create a new list of elements.
utilityElementsWithSameNetworkSource = new ArrayList<>();
}
// Add current utility element to the list of elements.
utilityElementsWithSameNetworkSource.add(utilityElement);
// Update the hash map with the new/modified key-value pair.
hashMap.put(utilityNetworkSourceName, utilityElementsWithSameNetworkSource);
}
// Ensure that the features' layer exists in the map.
for (Map.Entry<String, List<UtilityElement>> entry : hashMap.entrySet()) {
FeatureLayer layer = (FeatureLayer) map.getOperationalLayers().getFirst();
if (layer.getFeatureTable().getTableName().equalsIgnoreCase(entry.getKey())) {
// Get the features that correspond to the elements.
ListenableFuture<List<ArcGISFeature>> arcGISFeatureListListenableFuture =
utilityNetwork.fetchFeaturesForElementsAsync(entry.getValue());
arcGISFeatureListListenableFuture.addDoneListener(() -> {
try {
List<ArcGISFeature> arcGISFeatureList = arcGISFeatureListListenableFuture.get();
// Do something with the features.

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

// (continued from above)
// Select features to highlight result.
for (ArcGISFeature arcGISFeature : arcGISFeatureList) {
layer.selectFeature(arcGISFeature);
}
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}); // End of arcGISFeatureListListenableFuture.addDoneListener(() -> {
} // End of if (layer.getFeatureTable().getTableName().equalsIgnoreCase(entry.getKey())) {
} // End of for (Map.Entry<String, List<UtilityElement>> entry : hashMap.entrySet()) {
} else {
System.out.println("First trace result is empty.");
}
} // End of if (utilityTraceResults.getFirst() != null &&
// utilityTraceResults.getFirst() instanceof UtilityElementTraceResult utilityElementTraceResult) {
} catch (Exception e) {
e.printStackTrace();
}
}); // End of utilityTraceResultsListenableFuture.addDoneListener(() -> {

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 A trace is an action that analyzes the paths in a utility network and returns features based on connectivity or traversability from the specified starting points. Learn more result as graphics A graphic is a visual element composed of a geometry, symbol, and attributes that is displayed on a map or scene. Learn more in the map view A map view is a user interface that displays map layers and graphics in 2D. It controls the area (extent) of the map that is visible and supports user interactions such as pan and zoom. Learn more . At most, geometry results will contain three (multipart) geometries: one multipoint A multipoint is a type of geometry that contains an array of points and a spatial reference. Point coordinates are expressed as x,y values. Each coordinate can also optionally include a z value for height and/or a m value for measure (typically used in linear referencing). Learn more , one polyline A polyline is a type of geometry containing ordered point coordinates and a spatial reference. Learn more , and one polygon A polygon is a type of geometry containing an array of rings and a spatial reference. Each ring contains an array of point coordinates, where the first and last point are the same. Learn more . 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 A spatial reference is a set of parameters, typically defined by a WKID, that define the coordinate system and spatial properties for geographic data. Applications use a spatial reference to correctly display the position of geographic data in a map or scene. Learn more , use a symbology appropriate for the geometry type, and add them to a graphics overlay in the map view.