Update feature attributes in an online feature service.
Use case
Online feature services can be updated with new data. This is useful for updating existing data in real time while working in the field.
How to use the sample
To change the feature's damage property, tap the feature to select it, and update the damage type using the drop down.
Features in the map represent damage inspection points and are symbolized based on an attribute specifying the type of damage. Selecting an inspection point displays a callout. The callout contains information about the type of damage. To change the type of damage, select the information button in the callout. An editing window appears, allowing you to choose new attribute values. Selecting the update button will update the inspection point with the new value.
This is done by first obtaining the inspection point feature after it is selected. Once the feature is obtained, the feature's attribute is updated by calling setAttributeValue. To update the feature in the feature table, call updateFeature and pass in the edited feature. Finally, to update the service, call applyEdits to apply the edits to the service.
How it works
Create a ServiceFeatureTable object from a URL.
When the table loads, you can get the domain to determine which options to present in your UI.
Create a FeatureLayer object from the ServiceFeatureTable.
Select features from the FeatureLayer.
To update the feature's attribute, first load it, then use the attributeValue.
Update the table with updateFeature.
After a change, apply the changes on the server using applyEdits.
Relevant API
ArcGISFeature
FeatureLayer
ServiceFeatureTable
Tags
amend, attribute, details, edit, editing, information, value
Sample Code
UpdateAttributesFeatureService.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
// [WriteFile Name=UpdateAttributesFeatureService, Category=EditData]// [Legal]// Copyright 2016 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
import QtQuick.Controls
import QtQuick.Layouts
import Esri.ArcGISRuntime
import Esri.ArcGISRuntime.Toolkit
Rectangle {
width: 800height: 600 readonly property var featAttributes: ["Destroyed", "Major", "Minor", "Affected", "Inaccessible"]
property string damageTypeproperty var selectedFeature: null// Create MapView that contains a MapMapView {
id: mapViewanchors.fill: parentwrapAroundMode: Enums.WrapAroundModeDisabled
Component.onCompleted: {
// Set the focus on MapView to initially enable keyboard navigation forceActiveFocus();
}
Map {
// Set the initial basemap to StreetsBasemap {
initStyle: Enums.BasemapStyleArcGISStreets
}
// set viewpoint over The United StatesViewpointCenter {
Point {
x: -10800000y: 4500000spatialReference: SpatialReference {
wkid: 102100 }
}
targetScale: 3e7 }
FeatureLayer {
id: featureLayer// declare as child of feature layer, as featureTable is the default propertyServiceFeatureTable {
id: featureTableurl: "https://sampleserver6.arcgisonline.com/arcgis/rest/services/DamageAssessment/FeatureServer/0"// make sure edits are successfully applied to the serviceonApplyEditsStatusChanged: {
if (applyEditsStatus === Enums.TaskStatusCompleted) {
console.log("successfully updated feature");
}
}
// signal handler for the asynchronous updateFeature methodonUpdateFeatureStatusChanged: {
if (updateFeatureStatus === Enums.TaskStatusCompleted) {
// apply the edits to the service featureTable.applyEdits();
}
}
}
// signal handler for selecting featuresonSelectFeaturesStatusChanged: {
if (selectFeaturesStatus === Enums.TaskStatusCompleted) {
if (!selectFeaturesResult.iterator.hasNext)
return;
selectedFeature = selectFeaturesResult.iterator.next();
damageType = selectedFeature.attributes.attributeValue("typdamage");
// show the callout callout.showCallout();
// set the combo box's default value damageComboBox.currentIndex = featAttributes.indexOf(damageType);
}
}
}
}
QueryParameters {
id: params }
// hide the callout after navigationonViewpointChanged: {
if (callout.visible)
callout.dismiss();
updateWindow.visible = false;
}
onMouseClicked: mouse => {
// reset the map callout and update window featureLayer.clearSelection();
if (callout.visible)
callout.dismiss();
updateWindow.visible = false;
mapView.identifyLayerWithMaxResults(featureLayer, mouse.x, mouse.y, 10, false, 1);
}
onIdentifyLayerStatusChanged: {
if (identifyLayerStatus === Enums.TaskStatusCompleted) {
if (identifyLayerResult.geoElements.length > 0) {
// get the objectid of the identifed object params.objectIdsAsInts = [identifyLayerResult.geoElements[0].attributes.attributeValue("objectid")];
// query for the feature using the objectid featureLayer.selectFeaturesWithQuery(params, Enums.SelectionModeNew);
}
}
}
calloutData {
// HTML to style the title text by centering it, increase pt size,// and bolding it.title: "<br><b><font size=\"+2\">%1</font></b>".arg(damageType)
location: selectedFeature ? selectedFeature.geometry : null }
Callout {
id: calloutcalloutData: parent.calloutData;
background: Rectangle {
border.color: "lightgrey"border.width: 1 }
leaderPosition: Callout.LeaderPosition.Automatic
onAccessoryButtonClicked: {
updateWindow.visible = true;
}
}
}
// Update WindowRectangle {
id: updateWindowwidth: childrenRect.width
height: childrenRect.height
anchors.centerIn: parentradius: 10visible: falseMouseArea {
anchors.fill: parentonClicked: mouse => mouse.accepted = true;
onWheel: wheel => wheel.accepted = true;
}
GridLayout {
columns: 2anchors.margins: 5Text {
Layout.columnSpan: 2Layout.margins: 5text: "Update Attribute"font.pixelSize: 16 }
ComboBox {
property int modelWidth: 0Layout.minimumWidth: modelWidth + leftPadding + rightPadding + (indicator ? indicator.width : 10)
Layout.columnSpan: 2Layout.margins: 5Layout.fillWidth: trueid: damageComboBoxmodel: featAttributes
Component.onCompleted : {
for (let i = 0; i < model.length; ++i) {
metrics.text = model[i];
modelWidth = Math.max(modelWidth, metrics.width);
}
}
TextMetrics {
id: metricsfont: damageComboBox.font
}
}
Button {
Layout.margins: 5text: "Update"functiondoUpdateAttribute(){
if (selectedFeature.loadStatus === Enums.LoadStatusLoaded) {
selectedFeature.onLoadStatusChanged.disconnect(doUpdateAttribute);
selectedFeature.attributes.replaceAttribute("typdamage", damageComboBox.currentText);
// update the feature in the feature table asynchronously featureTable.updateFeature(selectedFeature);
}
}
// once the update button is clicked, hide the windows, and fetch the currently selected featuresonClicked: {
if (callout.visible)
callout.dismiss();
updateWindow.visible = false;
selectedFeature.onLoadStatusChanged.connect(doUpdateAttribute);
selectedFeature.load();
}
}
Button {
Layout.alignment: Qt.AlignRight
Layout.margins: 5text: "Cancel"// once the cancel button is clicked, hide the windowonClicked: updateWindow.visible = false;
}
}
}
}