Browse OGC API Feature Service

View inQMLC++
View on GitHub
Sample viewer app

Browse an OGC API feature service for layers and add them to the map.

screenshot

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

  1. Create an OgcFeatureService object with a URL to an OGC API feature service.
  2. Create a list of feature collections from the OgcFeatureService.OgcFeatureServiceInfo.FeatureCollectionInfos.
  3. When a feature collection is selected, create an OgcFeatureCollectionTable from the list of feature collections.
  4. Populate the OgcFeatureCollectionTable using PopulateFromService with QueryParameters that contain a MaxFeatures property.
  5. Create a feature layer from the feature table.
  6. 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
                                                                                                                                                                                           
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
// [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 2.12
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import Esri.ArcGISRuntime 100.12
import QtQuick.Dialogs 1.2

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

    property url serviceURL: "https://demo.ldproxy.net/daraa"
    property OgcFeatureService featureService: null
    property FeatureLayer featureLayer : null
    property string errorMessage: ""

    MapView {
        id: mapView
        anchors.fill: parent

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

                // When the map has loaded, connect to the OGC Feature Service
                onComponentCompleted: loadFeatureService(serviceURL);
            }
        }

        // Add the OGC feature service UI element
        Control {
            id: uiControl
            anchors {
                right: parent.right
                top: parent.top
                margins: 10
            }
            padding: 10
            background: Rectangle {
                color: "white"
                border.color: "black"
            }
            contentItem: GridLayout {
                columns: 2
                Label {
                    id: instructionLabel
                    text: "Load the service, then select a layer for display"
                    font.bold: true
                    verticalAlignment: "AlignVCenter"
                    horizontalAlignment: "AlignHCenter"
                    Layout.columnSpan: 2
                    Layout.fillWidth: true
                }
                TextField {
                    id: serviceURLBox
                    text: serviceURL
                    Layout.fillWidth: true
                    selectByMouse: true
                }
                Button {
                    id: connectButton
                    text: "Load service"
                    enabled: featureService.loadStatus !== Enums.LoadStatusLoading
                    onClicked: {
                        serviceURL = serviceURLBox.text;
                        loadFeatureService(serviceURL);
                    }
                }
                ComboBox {
                    id: featureCollectionListComboBox
                    Layout.columnSpan: 2
                    Layout.fillWidth: true
                    Layout.fillHeight: true
                    textRole: "title"
                    model: featureService.loadStatus === Enums.LoadStatusLoaded ? root.featureService.serviceInfo.featureCollectionInfos : [];
                }
                Button {
                    id: loadLayerButton
                    text: "Load selected layer"
                    enabled: featureLayer.loadStatus !== Enums.LoadStatusLoading
                    onClicked: loadFeatureCollection(featureCollectionListComboBox.currentIndex);
                    Layout.columnSpan: 2
                    Layout.fillWidth: true
                }
            }
        }

        // Pop-up error message box
        MessageDialog {
            id: errorMessageBox
            title: "Error message!"
            text: errorMessage
            icon: StandardIcon.Warning
            visible: errorMessage === "" ? false : true;
            onAccepted: errorMessage = "";
        }

        QueryParameters {
            id: queryParameters
            maxFeatures: 1000
        }
    }

    function loadFeatureService(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();
    }

    function handleError(error) {
        if (!error.additionalMessage)
            errorMessage = error.message;
        else
            errorMessage = error.message + "\n" + error.additionalMessage;
    }

    function checkForLoadingErrors() {
        if (root.featureService.loadStatus === Enums.LoadStatusFailedToLoad) {
            handleError(root.featureService.loadError);
        }
    }

    function loadFeatureCollection(selectedFeature) {
        // Create featureCollectionTable object
        let 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();
    }

    function checkIfLayerLoaded() {
        if (root.featureLayer.loadStatus === Enums.LoadStatusFailedToLoad) {
            handleError(root.featureLayer.loadError);
            return;
        }
        else if (root.featureLayer.loadStatus !== Enums.LoadStatusLoaded) {
            return;
        }
        addFeatureLayerToMap();
    }

    function addFeatureLayerToMap() {
        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);
    }
}

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