Perform valve isolation trace

View inC++QMLView on GitHubSample viewer app

Run a filtered trace to locate operable features that will isolate an area from the flow of network resources.

screenshot

Use case

Determine the set of operable features required to stop a network's resource, effectively isolating an area of the network. For example, you can choose to return only accessible and operable valves: ones that are not paved over or rusted shut.

How to use the sample

Select one or more features to use as filter barriers or create and set the configuration's filter barriers by selecting a category. Check or uncheck 'Include isolated features'. Press 'Trace' to run a subnetwork-based isolation trace. Press 'Reset' to clear filter barriers.

How it works

  1. Create a MapView.
  2. Create and load a ServiceGeodatabase with a feature service URL and get tables by their layer IDs.
  3. Create a Map that contains FeatureLayer(s) created from the service geodatabases tables.
  4. Create and load a UtilityNetwork with the feature service URL and the Map.
  5. Add a GraphicsOverlay with a Graphic that represents the starting location, and another graphics overlay for the filter barriers.
  6. Populate the list of filter barrier categories from UtilityNetworkDefinition.categories.
  7. When the map view is clicked, identify which features are at that location and add a graphic that represents a filter barrier.
  8. Create a UtilityElement for the identified feature and add this utility element to a list of filter barriers.
    • If the element is a junction with more than one terminal, display a terminal picker. Then set the junction's Terminal property with the selected terminal.
    • If an edge, use the result from GeometryEngine.fractionAlong to set the elements fractionAlongEdge property.
  9. If Trace is clicked with filter barriers:
    • Update the default configurations include isolated features property.
    • Update the UtilityTraceParameters filter barriers property.
    • Run UtilityNetwork.trace.
  10. If 'Trace' is clicked without filter barriers:
  • Create a new UtilityCategoryComparison with the selected category and Enums.UtilityCategoryComparisonOperatorExists.
  • Assign this condition to UtilityTraceFilter.barriers from the default configuration from step 6. Update this configuration's includeIsolatedFeatures property.
  • Run UtilityNetwork.trace.
  1. For every FeatureLayer in the map, select the features returned by featuresForElements from the elements matching their NetworkSource.name with the layer's FeatureTable.name.

Relevant API

  • ServiceGeodatabase
  • UtilityCategory
  • UtilityCategoryComparison
  • UtilityCategoryComparisonOperator
  • UtilityDomainNetwork
  • UtilityElement
  • UtilityElementTraceResult
  • UtilityNetwork
  • UtilityNetworkDefinition
  • UtilityTier
  • UtilityTraceFilter
  • UtilityTraceParameters
  • UtilityTraceResult
  • UtilityTraceType

About the data

The Naperville gas network feature service, hosted on ArcGIS Online (authentication required: this is handled within the sample code), contains a utility network used to run the isolation trace shown in this sample.

Additional information

Using utility network on ArcGIS Enterprise 10.8 requires an ArcGIS Enterprise member account licensed with the Utility Network user type extension. Please refer to the utility network services documentation.

Credentials:

  • Username: viewer01
  • Password: I68VGU^nMurF

Tags

category comparison, condition barriers, isolated features, network analysis, subnetwork trace, trace configuration, trace filter, utility network

Sample Code

PerformValveIsolationTrace.qmlPerformValveIsolationTrace.qmlTerminalPickerView.qml
Use dark colors for code blocksCopy
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
// [WriteFile Name=PerformValveIsolationTrace, 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 Esri.ArcGISRuntime 100.15
import QtQuick.Layouts 1.11
import QtQuick.Dialogs 1.1

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

    readonly property url featureServiceUrl: "https://sampleserver7.arcgisonline.com/server/rest/services/UtilityNetwork/NapervilleGas/FeatureServer"
    readonly property string domainNetworkName: "Pipeline"
    readonly property string tierName: "Pipe Distribution System"
    readonly property string networkSourceName: "Gas Device"
    readonly property string assetGroupName: "Meter"
    readonly property string assetTypeName: "Customer"
    readonly property string globalId: "98A06E95-70BE-43E7-91B7-E34C9D3CB9FF"
    readonly property string sampleServer7Username: "viewer01"
    readonly property string sampleServer7Password: "I68VGU^nMurF"
    property var clickPoint: null
    property var filterBarriers: []
    property var createdElement: null
    property var traceConfiguration: null
    property var startingLocation: null
    property var categories: null
    property bool uiEnabled: false
    property var distributionLineLayerFeatureTable: null
    property var deviceLayerFeatureTable: null

    ListModel {
        id: terminalNamesModel
    }

    MapView {
        id: mapView
        anchors.fill: parent

        Component.onCompleted: {
            // Set the focus on MapView to initially enable keyboard navigation
            forceActiveFocus();
        }

        onMouseClicked: {
            const screenX = mouse.x;
            const screenY = mouse.y;
            const tolerance = 10;
            const returnPopups = false;
            clickPoint = mouse.mapPoint;
            mapView.identifyLayers(screenX, screenY, tolerance, returnPopups);
        }

        onIdentifyLayersStatusChanged : {
            if (identifyLayersStatus !== Enums.TaskStatusCompleted)
                return;

            const results = mapView.identifyLayersResults;
            const identifiedLayerResult = results[0];

            // could not identify location
            if (!identifiedLayerResult)
                return;

            const feature = identifiedLayerResult.geoElements[0];

            let element = utilityNetwork.createElementWithArcGISFeature(feature);

            createdElement = element;

            const elementSourceType = element.networkSource.sourceType;

            if (elementSourceType === Enums.UtilityNetworkSourceTypeJunction) {
                const terminals = element.assetType.terminalConfiguration.terminals;
                if (terminals.length > 1) {
                    terminalNamesModel.clear();

                    for (let i = 0; i < terminals.length; i++) {
                        terminalNamesModel.append({text: terminals[i].name});
                    }

                    terminalPickerView.visible = true;
                    return;
                }
            } else if (elementSourceType === Enums.UtilityNetworkSourceTypeEdge) {

                if (feature.geometry.geometryType === Enums.GeometryTypePolyline) {
                    const line = GeometryEngine.removeZ(feature.geometry);
                    // Set how far the element is along the edge.
                    const fraction = GeometryEngine.fractionAlong(line, clickPoint, -1);
                    element.fractionAlongEdge = fraction;
                }
            }
            let graphic = ArcGISRuntimeEnvironment.createObject("Graphic", {geometry: clickPoint});

            filterBarriersOverlay.graphics.append(graphic);
            filterBarriers.push(element);
        }

        GraphicsOverlay {
            id: startingLocationOverlay
            Graphic {
                id: startingLocationGraphic
                SimpleMarkerSymbol {
                    style: Enums.SimpleMarkerSymbolStyleCross
                    color: "lime"
                    size: 25
                }
            }
        }

        GraphicsOverlay {
            id: filterBarriersOverlay
            SimpleRenderer {
                SimpleMarkerSymbol {
                    style: Enums.SimpleMarkerSymbolStyleX
                    color: "red"
                    size: 25
                }
            }
        }

        Credential {
            id: cred
            username: sampleServer7Username
            password: sampleServer7Password
        }

        Map {
            id: map

            Basemap {
                initStyle: Enums.BasemapStyleArcGISStreetsNight
            }

            Component.onCompleted: {
                serviceGeodatabase.load();
                utilityNetwork.load();
                map.utilityNetworks.append(utilityNetwork);
            }

            ServiceGeodatabase {
                id: serviceGeodatabase
                url: featureServiceUrl
                credential: cred
                onLoadStatusChanged: {
                    if (loadStatus === Enums.LoadStatusLoaded) {

                        // obtain service feature tables from service geodatabase and store them in global properties
                        distributionLineLayerFeatureTable = serviceGeodatabase.tableWithLayerIdAsInt(3);
                        deviceLayerFeatureTable = serviceGeodatabase.tableWithLayerIdAsInt(0);

                        // set each service feature table to their respective feature layer
                        distributionLineLayer.featureTable = distributionLineLayerFeatureTable;
                        deviceLayer.featureTable = deviceLayerFeatureTable;
                    }
                }
            }

            FeatureLayer {
                id: distributionLineLayer
            }

            FeatureLayer {
                id: deviceLayer
            }

            UtilityCategoryComparison {
                id: categoryComparison
            }

            UtilityTraceFilter {
                id: traceFilter
            }

            UtilityTraceParameters {
                id: traceParameters
            }

            QueryParameters {
                id: queryParameters
            }

            UtilityNetwork {
                id: utilityNetwork
                url: featureServiceUrl
                credential: cred

                onTraceStatusChanged: {

                    if (traceStatus !== Enums.TaskStatusCompleted)
                        return;

                    // re-enable UI and select features
                    uiEnabled = true;

                    if (traceResult.count < 1) {
                        messageDialog.visible = true;
                        return;
                    }

                    let utilityTraceResult = traceResult.get(0);
                    let allElements = traceResult.get(0).elements;

                    // if no elements found, then display message
                    if (allElements.length === 0) {
                        messageDialog.visible = true;
                        return;
                    }

                    // iterate through the map's features
                    for (let i = 0; i < map.operationalLayers.count; i++) {
                        let currentFeatureLayer = map.operationalLayers.get(i);

                        // create query parameters to find features whose network names match the layer's feature table name
                        let objectIds = [];
                        for (let j = 0; j < allElements.length; j++) {
                            let networkSourceName = allElements[j].networkSource.name;
                            let featureTableName = currentFeatureLayer.featureTable.tableName;

                            if (networkSourceName === featureTableName) {
                                objectIds.push(allElements[j].objectId);
                            }
                        }

                        queryParameters.objectIdsAsInts = objectIds;
                        currentFeatureLayer.selectFeaturesWithQuery(queryParameters, Enums.SelectionModeNew);
                    }
                }

                onFeaturesForElementsStatusChanged: {
                    if (featuresForElementsStatus !== Enums.TaskStatusCompleted)
                        return;

                    // display starting location
                    if (featuresForElementsResult.count > 0) {
                        let startingLocationGeometry = featuresForElementsResult.get(0).geometry;
                        startingLocationGraphic.geometry = startingLocationGeometry;
                        mapView.setViewpointCenterAndScale(startingLocationGeometry, 3000);

                        uiEnabled = true;
                    }
                }

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

                    // get a trace configuration from a tier
                    if (definition.domainNetwork(domainNetworkName) !== null) {
                        let domainNetwork = definition.domainNetwork(domainNetworkName);
                        if (domainNetwork.tier(tierName) !== null) {
                            let tier = domainNetwork.tier(tierName);
                            traceConfiguration = tier.defaultTraceConfiguration();
                        }
                    }

                    if (traceConfiguration === null)
                        return;

                    // set the trace filter
                    traceConfiguration.filter = traceFilter;

                    // get a default starting location
                    if (definition.networkSource(networkSourceName) !== null) {
                        let networkSource = definition.networkSource(networkSourceName);
                        if (networkSource.assetGroup(assetGroupName) !== null) {
                            let assetGroup = networkSource.assetGroup(assetGroupName);
                            if (assetGroup.assetType(assetTypeName) !== null) {
                                let assetType = assetGroup.assetType(assetTypeName);
                                startingLocation = createElementWithAssetType(assetType, globalId);
                            }
                        }
                    }

                    if (startingLocation === null)
                        return;

                    // display starting location
                    featuresForElements([startingLocation]);

                    // populate the combo box choices
                    let allCategories = definition.categories;
                    categories = [];
                    for (let i = 0; i < allCategories.length; i++) {
                        categories.push(allCategories[i].name);
                    }
                    comboBox.model = categories;
                }
            }
        }

        ColumnLayout {
            anchors {
                left: parent.left
                top: parent.top
            }
            Rectangle {
                id: backgroundRect
                color: "#FBFBFB"
                height: childrenRect.height
                width: row.width * 1.25

                RowLayout {
                    id: titleRow
                    Rectangle {
                        color: backgroundRect.color
                        width: childrenRect.width
                        height: childrenRect.height
                        Text {
                            text: "Choose category for filter barrier:"
                            font.pixelSize: 14
                        }
                    }
                    anchors {
                        left: row.left
                        top: parent.top
                    }
                }

                RowLayout {
                    id: row
                    anchors {
                        horizontalCenter: parent.horizontalCenter
                        top: titleRow.bottom
                    }
                    ComboBox {
                        id: comboBox
                        enabled: uiEnabled
                        Layout.minimumWidth: 200
                        model: categories
                    }
                    Button {
                        text: "Trace"
                        onClicked: {
                            if (comboBox.currentIndex < 0)
                                return;

                            // disable UI and perform trace
                            uiEnabled = false;

                            // clear previous selection from the feature layers
                            for (let i = 0; i < map.operationalLayers.count; i++) {
                                map.operationalLayers.get(i).clearSelection();
                            }

                            let categoriesList = utilityNetwork.definition.categories;

                            // get the selected utility category
                            let selectedCategory = categoriesList[comboBox.currentIndex];
                            categoryComparison.category = selectedCategory;
                            categoryComparison.comparisonOperator = Enums.UtilityCategoryComparisonOperatorExists;

                            traceConfiguration.filter.barriers = null;

                            // set the category comparison to the barriers of the configuration's trace filter
                            if (filterBarriers.length > 0) {
                                traceParameters.filterBarriers = filterBarriers;
                            } else {
                                traceConfiguration.filter.barriers = categoryComparison;
                            }

                            // set whether to include isolated features
                            traceConfiguration.includeIsolatedFeatures = checkBox.checked;

                            // build parameters for the isolation trace
                            traceParameters.traceType = Enums.UtilityTraceTypeIsolation;
                            traceParameters.startingLocations = [startingLocation];
                            traceParameters.traceConfiguration = traceConfiguration;

                            utilityNetwork.trace(traceParameters);
                        }
                        enabled: uiEnabled
                    }
                    Button {
                        id: resetBtn
                        text: qsTr("Reset")
                        onClicked: {
                            filterBarriers = [];
                            traceParameters.filterBarriers = [];
                            filterBarriersOverlay.graphics.clear();
                            for (let i = 0; i < map.operationalLayers.count; i++) {
                                map.operationalLayers.get(i).clearSelection();
                            }
                        }
                        enabled: uiEnabled
                    }
                }

                RowLayout {
                    id: checkBoxRow
                    anchors {
                        top: row.bottom
                        left: row.left
                    }
                    CheckBox {
                        id: checkBox
                        text: "Include isolated features"
                        enabled: uiEnabled
                        leftPadding: 0
                    }
                }
            }
        }

        BusyIndicator {
            id: busyIndicator
            anchors.centerIn: parent
            running: utilityNetwork.traceStatus === Enums.TaskStatusInProgress
        }
    }

    TerminalPickerView {
        id: terminalPickerView
    }

    function selectTerminal(terminalIndex) {
        const terminal = createdElement.assetType.terminalConfiguration.terminals[terminalIndex];
        createdElement.terminal = terminal;

        let graphic = ArcGISRuntimeEnvironment.createObject("Graphic", {geometry: clickPoint});
        filterBarriersOverlay.graphics.append(graphic);

        filterBarriers.push(createdElement);
    }

    MessageDialog {
        id: messageDialog
        title: "Perform valve isolation trace"
        text: "Isolation trace returned no elements."
        visible: false
        onRejected: {
            visible = false;
        }
    }
}

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