A few days ago Cy T posted an interesting question about creating virtual layers using the Python console:
Creating new Virtual Layer programmatically in QGIS?
Is it also possible to create virtual layers through the processing toolbox?
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# ----- define interface -----
##Virtual Layers=group
##Point on surface (ST_PointOnSurface)=name
##Input_polygons=vector
from qgis.core import QgsVectorLayer, QgsMapLayerRegistry
inptlyr = processing.getObject(Input_polygons)
vlayer = QgsVectorLayer( "?query=SELECT rowid AS gid,ST_PointOnSurface(geometry)AS geom FROM inptlyr.name()", "vlayer", "virtual" )
QgsMapLayerRegistry.instance().addMapLayer(vlayer)
The log says Algorithm Point on surface (ST_PointOnSurface) finished, but nothing happens.
Edit: ?query= added
?query=missing? I mean, does it change something using?query=SELECT? – mgri Feb 11 '17 at 11:29