An array of analysis and tracing options usually begin with or include a utility element in the result. This element corresponds to a network feature or object that contains additional information such as a terminal or fraction along value that affects the analysis. For example, the utility element's terminal may limit the number of connectivity associations or change the direction of a trace, while its fraction along value may return a partial geometry from a trace.
This utility element may be created from a feature or asset type with a global id. The feature may be a result of a query or identify operation on a layer or table that is part of the utility network.
Utility element from a feature
You may query for a specific feature using any of its fields or geometry or interactively identify a feature in a map view. When using identify, the feature may be found in the GeoElement
list immediately under IdentifyLayerResult
when part of a FeatureLayer
or from sublayerResults
when part of a SubtypeFeatureLayer
.
// Create a utility element for the feature.
val utilityElement: UtilityElement = utilityNetwork.createElementOrNull(arcGISFeature)
?: return@onSuccess showError("Null utility element.")
Utility element from an asset type
An asset type can come from another utility element or be derived from a feature in the utility network, except from a subnet line table that does not have an asset type. You can use the feature's table name to get its network source. Use the network source and the feature's subtype to get its asset group. From the asset group, you can select an asset type by name or code.
Utility element properties
A terminal is required when a UtilityElement
that supports more than one terminal is used in a trace and optional when used to get associations. Terminals impact traces and connectivity associations.
// Get the terminals for the feature.
utilityElement.apply {
terminal = assetType.terminalConfiguration?.terminals?.first()
}
If the feature represents a line, you can optionally specify a location along the line to use as a trace location. This value is a percentage of the length of the line, beginning from the line's 'from' point.
Use UtilityElement.fractionAlongEdge
to define the location of the point along the line.
The following example uses the GeometryEngine
to get the fraction of a tap location along the line.
UtilityNetworkSourceType.Edge -> {
// Compute how far tapped location is along the edge feature.
val geometry = arcGISFeature.geometry ?: return@onSuccess showError("Null geometry.")
// val location = mapView.screenToLocation(screenCoordinate)
val location =
mapViewProxy.screenToLocationOrNull(screenCoordinate) ?: return@onSuccess showError(
"Null location."
)
utilityElement.fractionAlongEdge = GeometryEngine.fractionAlong(
line = GeometryEngine.createWithZ(geometry, null) as Polyline,
point = location,
tolerance = -1.0
)