First off, i'm trying to learn some python to automate scripts for basic tasks i carry out in QGIS (2.18).
Below I create a virtual layer (polyline) using the following script:
from qgis.core import QgsVectorLayer, QgsMapLayerRegistry
from qgis.utils import iface
from qgis.core import *
from qgis.utils import *
from qgis.gui import *
vlayer = QgsVectorLayer("?query=SELECT cm_code, cm_ndcode1 as 'nd_1', cm_ndcode2 as 'nd_2', COUNT() as 'Num CM', geometry FROM t_cheminement GROUP BY cm_ndcode1, cm_ndcode2 HAVING COUNT() > 1" , "CM_DUBLONS", "virtual" )
props = { 'width' : '3', 'color' : '255,0,0' } sl=QgsSymbolLayerV2Registry.instance().symbolLayerMetadata("SimpleLine").createSymbolLayer(props) s = QgsLineSymbolV2([sl])
vlayer.setRendererV2(QgsSingleSymbolRendererV2( s ))
QgsMapLayerRegistry.instance().addMapLayer(vlayer)
The above code works fine - but next I want to create a fixed distance buffer around the polylines.
I started off with this:
qgis_fixeddistancebuffer(input = CM_DUBLONS, output = 'c:/SIG_DEV_MODEL/buffer_test.shp', distance = 1000)
But it returns the error message below:
Traceback (most recent call last): File "< input >", line 1, in NameError: name 'qgis_fixeddistancebuffer' is not defined
I've also tried
processing.runalg('qgis:fixeddistancebuffer', CM_DUBLONS, 500, 6, dissolve, "C:/SIG/SIG_DEV_MODEL/CM_buf2.shp")
but likewise I get a similar error message "'processing' is not defined"
I'm probably missing something simple...
Otherwise I've since looked up the following:
Pyqgis Fixed Buffer Creation in Meters with Haversine
and
How to create dissolved buffer layer with pyqgis?
But it's not quite what I'm looking for, and I'm not sure how to adapt the script.