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.
for (final utilityTraceResult in utilityTraceResults) {
if (utilityTraceResult is UtilityGeometryTraceResult) {
// Process the geometry result.
examineGeometryResults(utilityTraceResult);
} else if (utilityTraceResult is UtilityElementTraceResult) {
// Process the element result.
examineElementResults(utilityTraceResult.elements);
} else if (utilityTraceResult is UtilityFunctionTraceResult) {
// Process the function result.
examineFunctionResults(utilityTraceResult.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
// Filter out the result elements that are part of the feature table.
final filteredElements = elements
.where(
(utilityElement) =>
utilityElement.networkSource.name ==
layer.featureTable?.tableName,
)
.toList();
final features =
await _utilityNetwork.getFeaturesForElements(filteredElements);
Select the features that correspond to the trace result or process as required.
// Highlight features.
layer.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.
for (final utilityTraceFunctionOutput in functionTraceOutputs) {
// Get the original function (as defined in the trace configuration).
final utilityTraceFunction = utilityTraceFunctionOutput.function;
// Get the network attribute that was used in the function.
final networkAttribute = utilityTraceFunction.networkAttribute;
// Get the type of function.
final 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
// If there are no features of a particular geometry type, it will be null.
// Add each geometry to the graphics overlay.
if (geometryTraceResult.polygon != null) {
_graphicsOverlay.graphics
.add(Graphic(geometry: geometryTraceResult.polygon));
}
if (geometryTraceResult.polyline != null) {
_graphicsOverlay.graphics
.add(Graphic(geometry: geometryTraceResult.polyline));
}
if (geometryTraceResult.multipoint != null) {
_graphicsOverlay.graphics
.add(Graphic(geometry: geometryTraceResult.multipoint));
}