Browse an OGC API feature service for layers and add them to the map.
Use case
OGC API standards are used for sharing geospatial data on the web. As an open standard, the OGC API aims to improve access to geospatial or location information and could be a good choice for sharing data internationally or between organizations. That data could be of any type, including, for example, transportation layers shared between government organizations and private businesses.
How to use the sample
Select a layer to display from the drop-down list of layers available from the OGC API service. The Daraa data is used as the default feature service, however, alternative feature services can be used.
How it works
Create an OgcFeatureService object with a URL to an OGC API feature service.
Create a list of feature collections from the OgcFeatureService.OgcFeatureServiceInfo.FeatureCollectionInfos.
When a feature collection is selected, create an OgcFeatureCollectionTable from the list of feature collections.
Populate the OgcFeatureCollectionTable using PopulateFromService with QueryParameters that contain a MaxFeatures property.
Create a feature layer from the feature table.
Add the feature layer to the map.
Relevant API
OgcFeatureCollectionInfo
OgcFeatureCollectionTable
OgcFeatureService
OgcFeatureServiceInfo
About the data
The Daraa, Syria test data is OpenStreetMap data converted to the Topographic Data Store schema of NGA.
Additional information
See the OGC API website for more information on the OGC API family of standards.
Tags
browse, catalog, feature, layers, OGC, OGC API, service, web
Sample Code
BrowseOGCAPIFeatureService.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
// [WriteFile Name=BrowseOGCAPIFeatureService, Category=Layers]// [Legal]// Copyright 2021 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
Rectangle {
id: rootclip: truewidth: 800height: 600property url serviceURL: "https://demo.ldproxy.net/daraa"property OgcFeatureService featureService: nullproperty FeatureLayer featureLayer : nullproperty string errorMessage: ""MapView {
id: mapViewanchors.fill: parentComponent.onCompleted: {
// Set the focus on MapView to initially enable keyboard navigation forceActiveFocus();
}
Map {
id: mapBasemap {
initStyle: Enums.BasemapStyleArcGISTopographic
// When the map has loaded, connect to the OGC Feature ServiceonComponentCompleted: loadFeatureService(serviceURL);
}
}
// Add the OGC feature service UI elementControl {
id: uiControlanchors {
right: parent.right
top: parent.top
margins: 10 }
padding: 10background: Rectangle {
color: "white"border.color: "black" }
contentItem: GridLayout {
columns: 2Label {
id: instructionLabeltext: "Load the service, then select a layer for display"font.bold: trueverticalAlignment: "AlignVCenter"horizontalAlignment: "AlignHCenter"Layout.columnSpan: 2Layout.fillWidth: true }
TextField {
id: serviceURLBoxtext: serviceURL
Layout.fillWidth: trueselectByMouse: true }
Button {
id: connectButtontext: "Load service"enabled: featureService.loadStatus !== Enums.LoadStatusLoading
onClicked: {
serviceURL = serviceURLBox.text;
loadFeatureService(serviceURL);
}
}
ComboBox {
id: featureCollectionListComboBoxLayout.columnSpan: 2Layout.fillWidth: trueLayout.fillHeight: truetextRole: "title"model: featureService.loadStatus === Enums.LoadStatusLoaded ? root.featureService.serviceInfo.featureCollectionInfos : [];
}
Button {
id: loadLayerButtontext: "Load selected layer"enabled: featureCollectionListComboBox.model.length > 0onClicked: loadFeatureCollection(featureCollectionListComboBox.currentIndex);
Layout.columnSpan: 2Layout.fillWidth: true }
}
}
// Pop-up error message boxDialog {
id: errorMessageBoxvisible: errorMessage === ""? false : truetitle: errorMessage
standardButtons: Dialog.Ok
x: (parent.width - width) / 2y: (parent.height - height) / 2 }
QueryParameters {
id: queryParametersmaxFeatures: 1000 }
}
functionloadFeatureService(currentUrl) {
// Create feature service object and assign to featureService property root.featureService = ArcGISRuntimeEnvironment.createObject("OgcFeatureService", {url: currentUrl}, map);
// Connect loaded signal to checkForLoadingErrors() function root.featureService.loadStatusChanged.connect(checkForLoadingErrors);
featureService.load();
}
functionhandleError(error) {
if (!error.additionalMessage)
errorMessage = error.message;
else errorMessage = error.message + "\n" + error.additionalMessage;
}
functioncheckForLoadingErrors() {
if (root.featureService.loadStatus === Enums.LoadStatusFailedToLoad) {
handleError(root.featureService.loadError);
}
}
functionloadFeatureCollection(selectedFeature) {
// Create featureCollectionTable objectlet featureCollectionTable = ArcGISRuntimeEnvironment.createObject("OgcFeatureCollectionTable");
// Set request mode to manual cache featureCollectionTable.featureRequestMode = Enums.FeatureRequestModeManualCache;
// Copy info for selected feature collection into featureCollectionTable featureCollectionTable.featureCollectionInfo = featureService.serviceInfo.featureCollectionInfos[selectedFeature];
// Populate featureCollectionTable featureCollectionTable.populateFromService(queryParameters, true, []);
// Create feature layer object and assign to featureLayer property root.featureLayer = ArcGISRuntimeEnvironment.createObject("FeatureLayer", { featureTable: featureCollectionTable } );
// Connect loadStatusChanged to checkIfLayerLoaded function root.featureLayer.loadStatusChanged.connect(checkIfLayerLoaded);
root.featureLayer.load();
}
functioncheckIfLayerLoaded() {
if (root.featureLayer.loadStatus === Enums.LoadStatusFailedToLoad) {
handleError(root.featureLayer.loadError);
return;
}
elseif (root.featureLayer.loadStatus !== Enums.LoadStatusLoaded) {
return;
}
addFeatureLayerToMap();
}
functionaddFeatureLayerToMap() {
map.operationalLayers.clear();
// Add selected feature layer to the map map.operationalLayers.append(root.featureLayer);
// Set the viewpoint of the map mapView.setViewpointGeometry(root.featureLayer.fullExtent);
}
}