3

I need to get a WFS 2.0 layer in QGIS through python code.

I am making a QGIS plugin that needs to download a specific WFS 2.0 layer. I have been looking at the code for wfs 2.0 client plugin, and by taking what i assume is the necessary part of the code I have managed to load the layer thru a python console script. I though I could simply put that code in my plugin and be done with it, but that unfortunately resulted in an error. I am rather new to all of this, but have to the best of my ability narrated the problem down too this: It seems that when i put my code in the plugin, the id that i got (through Qhttp.get()) is different from the requested id. Sometimes the ID's are not different, but then it signals an error through the Qhttp.requestFinnished that i have not been able to read yet.

I have been searching far and wide in order to fix this, but have only ended up empty handed. Therefore I ask here if someone can help me getting access to a WFS 2.0 layer through python in QGIS, or some good place for me to learn about this.

I got the URL for the WFS from this site: https://kartkatalog.geonorge.no/metadata/kartverket/tilgjengelighet-tettsted-wfs/3bec7256-86c2-4d43-a122-0760a6a21790

in wfs 2.0 client I use the URL https://wfs.geonorge.no/skwms1/wfs.tilgjengelighettettsted?, It holds 4 or 5 different layers, I would probably need all of them

I am new to programming with spatial data.

I have both seen and tried codes from this post: Loading a WFS layer using pyqgis, but I don't understand how they find what url to use. The url i find from my webpage is much shorter. Also, I am uncertain whether or not this method works for WFS 2.0.

2
  • 1
    Welcome to GIS SE. Please edit the question and include this section of code and provide the error message/info.
    – artwork21
    Commented Nov 1, 2017 at 16:19
  • You may want to wait for QGIS 3. think it has better WFS support, especially for complex feature types.
    – nmtoken
    Commented Nov 1, 2017 at 16:57

1 Answer 1

4

The first thing to do with any WFS is to fetch and read the GetCapabilities document (that's the link they provide on the download page).

There is a version section that tells you which versions you can ask for:

<ows:Parameter name="AcceptVersions">
<ows:AllowedValues>
<ows:Value>2.0.0</ows:Value>
<ows:Value>1.1.0</ows:Value>
</ows:AllowedValues>
</ows:Parameter>

So first good news you can ask for version 2.0.0!

Now look for the GetFeature section:

<ows:Operation name="GetFeature">
<ows:DCP>
<ows:HTTP>
<ows:Get xlink:href="https://wfs.geonorge.no/skwms1/wfs.tilgjengelighettettsted?"/>
<ows:Post xlink:href="https://wfs.geonorge.no/skwms1/wfs.tilgjengelighettettsted?"/>
</ows:HTTP>
</ows:DCP>
</ows:Operation> 

This lists the 2 methods (GET and POST) and endpoints you can ask for data from.

Finally, you need to look at the Features list:

<FeatureTypeList>
<FeatureType>
<Name xmlns:app="http://skjema.geonorge.no/SOSI/produktspesifikasjon/TilgjengelighetTettsted/4.5">app:TettstedHCparkering</Name>
<Title>app:TettstedHCparkering</Title>
<DefaultCRS>urn:ogc:def:crs:EPSG::4258</DefaultCRS>
<OtherCRS>urn:ogc:def:crs:EPSG::25832</OtherCRS>
<OtherCRS>urn:ogc:def:crs:EPSG::25833</OtherCRS>
<OtherCRS>urn:ogc:def:crs:EPSG::25835</OtherCRS>
<OtherCRS>urn:ogc:def:crs:EPSG::3035</OtherCRS>
<OtherCRS>urn:ogc:def:crs:EPSG::3044</OtherCRS>
<OtherCRS>urn:ogc:def:crs:EPSG::3045</OtherCRS>
<OtherCRS>urn:ogc:def:crs:EPSG::3047</OtherCRS>
<OtherCRS>urn:ogc:def:crs:EPSG::4326</OtherCRS>
<OtherCRS>EPSG:900913</OtherCRS>
<OtherCRS>urn:ogc:def:crs:EPSG::3857</OtherCRS>
<OtherCRS>urn:ogc:def:crs:EPSG::3575</OtherCRS>
<OtherCRS>urn:ogc:def:crs:EPSG::3034</OtherCRS>
<OutputFormats>
<Format>text/xml; subtype=gml/3.2.1</Format>
<Format>application/gml+xml; version=3.2</Format>
</OutputFormats>
<ows:WGS84BoundingBox>
<ows:LowerCorner>-13.488699 0.000523</ows:LowerCorner>
<ows:UpperCorner>-13.488475 0.000638</ows:UpperCorner>
</ows:WGS84BoundingBox>
</FeatureType>
<FeatureType>
<Name xmlns:app="http://skjema.geonorge.no/SOSI/produktspesifikasjon/TilgjengelighetTettsted/4.5">app:TettstedInngangBygg</Name>
<Title>app:TettstedInngangBygg</Title>
<DefaultCRS>urn:ogc:def:crs:EPSG::4258</DefaultCRS>
<OtherCRS>urn:ogc:def:crs:EPSG::25832</OtherCRS>
<OtherCRS>urn:ogc:def:crs:EPSG::25833</OtherCRS>
<OtherCRS>urn:ogc:def:crs:EPSG::25835</OtherCRS>
<OtherCRS>urn:ogc:def:crs:EPSG::3035</OtherCRS>
<OtherCRS>urn:ogc:def:crs:EPSG::3044</OtherCRS>
<OtherCRS>urn:ogc:def:crs:EPSG::3045</OtherCRS>
<OtherCRS>urn:ogc:def:crs:EPSG::3047</OtherCRS>
<OtherCRS>urn:ogc:def:crs:EPSG::4326</OtherCRS>
<OtherCRS>EPSG:900913</OtherCRS>
<OtherCRS>urn:ogc:def:crs:EPSG::3857</OtherCRS>
<OtherCRS>urn:ogc:def:crs:EPSG::3575</OtherCRS>
<OtherCRS>urn:ogc:def:crs:EPSG::3034</OtherCRS>
<OutputFormats>
<Format>text/xml; subtype=gml/3.2.1</Format>
<Format>application/gml+xml; version=3.2</Format>
</OutputFormats>
<ows:WGS84BoundingBox>
<ows:LowerCorner>-13.488699 0.000523</ows:LowerCorner>
<ows:UpperCorner>-13.488474 0.000638</ows:UpperCorner>
</ows:WGS84BoundingBox>
</FeatureType>
...
</FeatureTypeList>

From that, you can see what data is available, what projections are available, where the data covers and what output formats are available. Often there is an abstract to tell you more about the data.

You just need to pick the relevant bits from the feature of your choice to make the getFeature request.

5
  • Thank you for the information, but I am still a bit confused. If I for instance would like to add the fist featuretype to my map, app:TettstedInngangBygg, do i only need the method from the qgis coockbook (vlayer = QgsVectorLayer(uri, "my wfs layer", "WFS")). Or is it more compicated that that. Also, from what i gather I can create a url looking a bit like this "uri2 = 'wfs.geonorge.no/skwms1/…'", but i don't understand what i need to take out from the feature list Commented Nov 2, 2017 at 13:17
  • that should do it according to the Q you linked to.
    – Ian Turton
    Commented Nov 2, 2017 at 13:20
  • Could you come with an example of an url from this data? That might help me understand how you use the data to construct a url to get a layer Commented Nov 6, 2017 at 14:06
  • It looks like wfs.geonorge.no/skwms1/… should work, but I can't import any layers from that server into QGIS
    – Ian Turton
    Commented Nov 6, 2017 at 14:29
  • Me neither, but wfs 2 client gets the layers, I suppose it has to be a bit more complex. wfs 2 client use Qhttp in order to gather the layers i think Commented Nov 7, 2017 at 11:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.