[GIS] Force geometry type in mixed geometry WFS layer in QGIS

geometrylayersqgisstylewfs

I have an external WFS source serving mixed geometry types – in other words, I have no control of the source. When adding the layer QGIS sets the geometry type to line and thus I am unable to style the points and polygons also contained within the layer.

Nathan W states in a comment that a layer in QGIS can contain only one geometry type. If I was able to explicitly set the geometry type on a layer, I could add the layer three times and use one layer for each geometry type.

Is it possible to force the geometry type on a (WFS) layer in QGIS?

Or is there another method I could use to correctly style all the features in my WFS layer?

Best Answer

In QGIS 3.6 this is not possible if adding the WFS through the browser panel. However, if you add the WFS through Layer > Add Layer > Add WFS Layer you are then able to apply SQL to the layer.

So, from scratch, do the following:

  • After you select Layer > Add Layer > Add WFS Layer, in the next window select New to add a new service.
  • Enter a Name and the URL of the service.
  • Click the Basic tab and enter your credentials if required.
  • Leave the WFS Options settings as default and click OK.
  • If you entered credentials you will receive a warning about storing passwords. Press OK to continue.
  • Click Connect to connect to the newly added service and highlight the layer you want and click Build query.
  • In the Where clause add the following: geometryType(geom_field) = 'LineString' replacing geom_field with the name of the field that stores the geometry. You should be able to find this in the Columns dropdown to the right. Geometry options include Point, MultiPoint, LineString, LinearRing, MultiLineString, Polygon, MultiPolygon, GeometryCollectionClick OK.
  • Click Add to add the layer to the map.
  • Click Close to return to map.

I couldn't find this anywhere and have figured it out myself using part of the answer to this question as a starting point. I hope it helps others looking for the same workaround until QGIS makes it a bit easier.

Related Question