Display utility associations

View inQMLC++
View on GitHub
Sample viewer app

Create graphics for utility associations in a utility network.

screenshot

Use case

Visualizing utility associations can help you to better understand trace results and the topology of your utility network. For example, connectivity associations allow you to model connectivity between two junctions that don't have geometric coincidence (are not in the same location); structural attachment associations allow you to model equipment that may be attached to structures; and containment associations allow you to model features contained within other features.

How to use the sample

Pan and zoom around the map. Observe graphics that show utility associations between junctions.

How it works

  1. Create and load a UtilityNetwork with a feature service URL.
  2. Add a FeatureLayer to the map for every UtilityNetworkSource of type Edge or Junction.
  3. Create a GraphicsOverlay for the utility associations.
  4. Add connection for the ViewpointChanged signal of the MapView.
  5. When the sample starts and every time the viewpoint changes, do the following steps.
  6. Get the geometry of the mapview's extent using currentViewpointExtent.extent.
  7. Get the associations that are within the current extent using associationsWithEnvelope(extent).
  8. Get the UtilityAssociationType for each association.
  9. Create a Graphic using the Geometry property of the association and a preferred symbol.
  10. Add the graphic to the graphics overlay.

Relevant API

  • GraphicsOverlay
  • UtilityAssociation
  • UtilityAssociationType
  • UtilityNetwork

About the data

The feature service in this sample represents an electric network in Naperville, Illinois, which contains a utility network used to run the subnetwork-based trace.

Additional information

Credentials:

  • Username: viewer01
  • Password: I68VGU^nMurF

Tags

associating, association, attachment, connectivity, containment, relationships

Sample Code

DisplayUtilityAssociations.qml
                                                                                                                                                                                                                                                        
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
// [WriteFile Name=DisplayUtilityAssociations, Category=UtilityNetwork]
// [Legal]
// Copyright 2020 Esri.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// [Legal]

import QtQuick 2.6
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import Esri.ArcGISRuntime 100.11

Rectangle {
    id: rootRectangle
    clip: true
    width: 800
    height: 600

    readonly property url featureServerUrl: "https://sampleserver7.arcgisonline.com/server/rest/services/UtilityNetwork/NapervilleElectric/FeatureServer"
    readonly property int maxScale: 2000
    readonly property int viewpointScale: 40

    MapView {
        id: mapView
        anchors.fill: parent

        Control {
            background: Rectangle {
                border.color: "black"
                border.width: 1
            }

            padding: 5
            anchors {
                top: parent.top
                left: parent.left
                margins: 20
            }

            contentItem: GridLayout {
                id: grid
                columns: 2
                anchors.horizontalCenter: parent.horizontalCenter

                Label {
                    text: "Utility association types"
                    Layout.alignment: Qt.AlignHCenter
                    Layout.fillWidth: true
                    Layout.columnSpan: 2
                }

                Image {
                    id: attachmentImage
                    fillMode: Image.PreserveAspectFit
                }
                Label {
                    id: attachmentLabel
                    text: "Attachment symbol"
                }

                Image {
                    id: connectivityImage
                }
                Label {
                    id: connectivityLabel
                    text: "Connectivity symbol"
                }
            }
        }

        Point {
            id: centerPoint
            x: -9812698.37297436
            y: 5131928.33743317
            SpatialReference {wkid: 3857}
        }

        Map {
            id: map
            Basemap {
                initStyle: Enums.BasemapStyleArcGISTopographic
            }

            Component.onCompleted: {
                utilityNetwork.load();
            }

            UtilityNetwork {
                id: utilityNetwork
                url: featureServerUrl

                Credential {
                    username: "viewer01"
                    password: "I68VGU^nMurF"
                }

                onLoadStatusChanged: {
                    if (loadStatus !== Enums.LoadStatusLoaded)
                        return;

                    let edges = [];
                    let junctions = [];

                    // get all the edges and junctions in the network
                    for (let i = 0; i < definition.networkSources.length; i++) {
                        if (definition.networkSources[i].sourceType === Enums.UtilityNetworkSourceTypeEdge) {
                            edges.push(definition.networkSources[i]);
                        } else if (definition.networkSources[i].sourceType === Enums.UtilityNetworkSourceTypeJunction) {
                            junctions.push(definition.networkSources[i]);
                        }
                    }

                    // add all edges that are not subnet lines to the map
                    for (let j = 0; j < edges.length; j++) {
                        if (edges[j].sourceUsageType !== Enums.UtilityNetworkSourceUsageTypeSubnetLine && edges[j].featureTable !== null) {
                            map.operationalLayers.append(ArcGISRuntimeEnvironment.createObject("FeatureLayer", {featureTable: edges[j].featureTable}));
                        }
                    }

                    // add all junctions to the map
                    for (let k = 0; k < junctions.length; k++) {
                        if (junctions[k].featureTable !== null) {
                            map.operationalLayers.append(ArcGISRuntimeEnvironment.createObject("FeatureLayer", {featureTable: junctions[k].featureTable}));
                        }
                    }

                    attachmentValue.values = [Enums.UtilityAssociationTypeAttachment];
                    connectivityValue.values = [Enums.UtilityAssociationTypeConnectivity];

                    mapView.setViewpointCenterAndScale(centerPoint, viewpointScale);
                }

                onAssociationsStatusChanged: {
                    if (associationsStatus !== Enums.TaskStatusCompleted)
                        return;

                    let isGraphicUnique = (graphics, id) => {
                        for (let j = 0; j < graphics.count; j++) {
                            const attributes = graphics.get(j).attributes;
                            if (attributes.containsAttribute("GlobalId") && attributes.attributeValue("GlobalId") === id) {
                                return false;
                            }
                        }
                        return true;
                    }

                    for (let i = 0; i < associationsResult.length; i++) {
                        const association = associationsResult[i];

                        if (isGraphicUnique(associationsOverlay.graphics, association.globalId)) {
                            const graphic = ArcGISRuntimeEnvironment.createObject("Graphic", {geometry: association.geometry});
                            graphic.attributes.insertAttribute("GlobalId", association.globalId);
                            graphic.attributes.insertAttribute("AssociationType", association.associationType);
                            associationsOverlay.graphics.append(graphic);
                        }
                    }
                }
            }
        }

        GraphicsOverlay {
            id: associationsOverlay

            // create a renderer for the associations
            UniqueValueRenderer {
                id: uniqueValueRenderer
                fieldNames: ["AssociationType"]

                UniqueValue {
                    id: attachmentValue
                    label: "Attachment"
                    SimpleLineSymbol {
                        id: attachmentSymbol
                        style: Enums.SimpleLineSymbolStyleDot
                        color: "red"
                        width: 5

                        // create swatch image for the legend
                        Component.onCompleted: {
                            createSwatch();
                        }
                        onSwatchImageChanged: {
                            attachmentImage.source = swatchImage;
                        }
                    }
                }

                UniqueValue {
                    id: connectivityValue
                    label: "Connectivity"
                    SimpleLineSymbol {
                        id: connectivitySymbol
                        style: Enums.SimpleLineSymbolStyleDot
                        color: "lime"
                        width: 5

                        // create swatch image for the legend
                        Component.onCompleted: {
                            createSwatch();
                        }
                        onSwatchImageChanged: {
                            connectivityImage.source = swatchImage;
                        }
                    }
                }
            }
        }

        // add associations to the map view
        function addAssociations() {
            // check if outside maximum scale
            if (currentViewpointCenter.targetScale >= maxScale)
                return;

            let currentExtent = currentViewpointExtent.extent;
            if (currentExtent.empty) {
                console.warn("Extent not valid.");
                return;
            }

            utilityNetwork.associationsWithEnvelope(currentExtent);
        }

        onSetViewpointCompleted: {
            if (!succeeded)
                return;

            addAssociations();
        }

        // add new associations when navigation is finished
        onNavigatingChanged: {
            if (navigating)
                return;

            addAssociations();
        }
    }
}

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