Depending on what you need to do with the results, you can work with the appropriate return type you configured in 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). that are found by a trace. Use these results when you need access to individual utility elements, their corresponding featuresA 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. , and their attributesAttributes 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. . 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. 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 trace with these parameters.
coroutineScope.launch {
// Run the utility trace and get the results.
utilityNetwork.trace(parameters).onFailure { error ->
showError("Error tracing utility network: ${error.message}")
}.onSuccess { utilityTraceResults: List<UtilityTraceResult> ->
utilityTraceResults.forEach { utilityTraceResult ->
when (utilityTraceResult) {
// Access the utility elements for a utility element trace result.
is UtilityElementTraceResult -> {
val utilityElementTraceResult = utilityTraceResult
examineElementResults(utilityElementTraceResult.elements)
}
// Access the geometries for a geometry trace result.
// Use the multipoint, polygon, and polyline properties of the UtilityGeometryTraceResult instance.
is UtilityGeometryTraceResult -> {
val utilityGeometryTraceResult = utilityTraceResult
examineGeometryResults(utilityGeometryTraceResult)
}
// Access the function outputs for a function trace result.
is UtilityFunctionTraceResult -> {
val utilityGeometryTraceResult = utilityTraceResult
examineFunctionResults(utilityGeometryTraceResult.functionOutputs)
}
}
}
}
}
Element results
If you need fine-grained access to the results, such as the ability to work with individual utility elements
You can use the element's network source
// check if there are any elements in the result
if (utilityElements.isNotEmpty()) {
// Get the result features from each network source layer in the map.
map.operationalLayers.filterIsInstance<FeatureLayer>().forEach { featureLayer ->
// Clear previous selection.
featureLayer.clearSelection()
// Filter out the result elements that are part of the feature table.
val elements = utilityElements.filter { utilityElement ->
utilityElement.networkSource.name == featureLayer.featureTable?.tableName
}
utilityNetwork.getFeaturesForElements(elements).onFailure {
showError("Error getting features for elements.")
}.onSuccess { features ->
// Highlight features.
featureLayer.selectFeatures(features)
}
}
}
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.
utilityFunctionOutputs.forEach { utilityTraceFunctionOutput ->
// Get the original function (as defined in the trace configuration).
val utilityTraceFunction = utilityTraceFunctionOutput.function
val networkAttribute = utilityTraceFunction.networkAttribute
val functionType = utilityTraceFunction.functionType
}
Geometry results
Geometry results make it easy to display the tracex,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).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
when (utilityTraceResult) {
is UtilityGeometryTraceResult -> examineGeometryResults(utilityTraceResult)
If geometry results are found, create a new graphic
// If there are no features of a particular geometry type, it will be null.
// Add each geometry to the graphics overlay.
utilityGeometryTraceResult.polygon?.let { polygon ->
graphicsOverlay.graphics.add(Graphic(polygon))
}
utilityGeometryTraceResult.polyline?.let { polyline ->
graphicsOverlay.graphics.add(Graphic(polyline))
}
utilityGeometryTraceResult.multipoint?.let { multipoint ->
graphicsOverlay.graphics.add(Graphic(multipoint))
}