I have created a line shapefile layer (memory layer) created in Python Console of QGIS. Now I want to define the thickness of the line features that are being created. I am aware of the method by which the line styles/symbology can be imported from the existing '.qml' file.
self.setLayerSymbology(vlayer, "Parent_PermanentMarks.qml")
Is there any way by which symbology (line thickness) of the lines can be defined 'on the go' via python console?
Answer
The below script worked for me.
from qgis.utils import iface
from qgis.core import *
from qgis.utils import *
from qgis.gui import *
vlayer = QgsVectorLayer("C:\SampleData\world_borders_lines.shp", "world_borders", "ogr")
props = { 'width' : '2', 'color' : '0,0,255' }
sl = QgsSymbolLayerV2Registry.instance().symbolLayerMetadata("SimpleLine").createSymbolLayer(props)
s = QgsLineSymbolV2([sl])
vlayer.setRendererV2( QgsSingleSymbolRendererV2( s ) )
QgsMapLayerRegistry.instance().addMapLayer(vlayer)
No comments:
Post a Comment