QGIS - LOADING A WFS LAYER
The QGIS documentation also provides an excellent walk-through on how to load a WFS layer. These instructions are adapted from the QGIS docs with additional details on the DataBC services.
- Open QGIS and create a new project.
- Open Data Source Manager > WFS/OGC API-Features tab.
- Create a New connection.
- Provide a name like
DataBC Layers
and set the URL tohttps://openmaps.gov.bc.ca/geo/ows?SERVICE=WFS&REQUEST=GetCapabilities
, and under WFS Options set Version to2.0
. - Click OK.
- Click Connect and allow a moment for the layers to load. You should see:
- Use the search bar to find a dataset of interest. For this tutorial we will add
BC Research Centres
. Find this layer and click on it. - Turn on Use title for layer name - this will show the plain-language dataset title instead of the BC Geographic Warehouse table name in the layer list.
-
Turn off Only request features overlapping the view extent - we want to retrieve all features across the province.
⚠ Loading large datasets
There is a hard limit on the maximum number of features the DataBC servers will return (10 000 at time of writing). Even when not hitting the feature limit, large and complex requests will often take too long to load, time out, and give a
Connection closed
error in QGIS.To avoid incomplete data loads, it is often best to turn on Only request features overlapping the view extent and zoom to your area of interest before adding the layer. Toggling off Render can provide a smoother map navigation experience, or you may choose to use Extract/clip by extent to save loaded features locally.
Occasionally it is necessary to reload features in the visible extent using refresh (F5).
Comparing against the WMS layer for the same dataset can provide a good cross-reference to visually confirm all features have been loaded.
- Click Add to load the layer.
- Close the Data Source Manager window.
- Right click the new layer and click Zoom to Layer(s).
- Explore the data - zoom in, pan around, and try selecting features.
-
Right click the layer in the Layers panel and click Open Attribute Table (F6). As a feature service (rather than a map service like WMS), it is possible to see attribute data, select features, and perform geoprocessing.
Viewing the attribute table
The normal Open Attribute Table function will try and load all features (even if the displayed layer is only requesting features by view extent) which is problematic for large datasets and can lead to failed requests or crashes. Instead, use Open Attribute Table (visible only), available from the Layer menu up top, or via CTRL+F6. The selection only option (SHIFT+F6) is also helpful.
-
WFS allows for custom layer styling. Change the styling from
Single Symbol
toCategorized
based on valueRESEARCH_CENTRE_AFFILIATION
, then click classify. -
Similarly, we can add labels.
-
We can filter the data we request from the WFS service to improve load times and reduce traffic. In the Data Source Manager, select the
BC Research Centres
layer, then click Build query at the bottom. Modify the query toSELECT * FROM "WHSE_IMAGERY_AND_BASE_MAPS.GSR_RESEARCH_CENTRES_SVW" WHERE "RESEARCH_CENTRE_AFFILIATION" = 'University'
. - Click OK and then Add the layer. A filter symbol will show next to the layer name showing the dataset is being filtered. The query can be modified from layer Properties > Source > Query Builder.
⚠ Duplicate features
For unclear reasons, QGIS can sometimes load duplicate features from the DataBC WFS services. To avoid this issue we can add a simple SQL filter to get unique features:
SELECT DISTINCT * FROM "<TABLE>"