3

I'm trying to create virtual layer to calculate count of features in layer "polygon_layer". I have no problem to create virtual layer from DB Manager. But if I do it in my python plugin, the result is None. Code:

qStr = ('?query = select polygon_type, count(*) as cnt from polygon_layer group by polygon_type order by 1')
vlayer = QgsVectorLayer( qStr, "Count Types", "virtual" )

The virtual layer has not geometry. And as I understand it's necessary to determine geometry type of virtual layer as "No geometry". My QGIS version is 3.4.

1 Answer 1

3

Error in url. No spaces before "=".

qStr = ('?query=select polygon_type, count(*) as cnt from polygon_layer group by polygon_type order by 1&nogeometry')

If the key "nogeometry" is set then vlayer.geometryType() is QgsWkbTypes.NullGeometry, otherwise it's QgsWkbTypes.UnknownGeometry

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.