Tuesday 21 May 2019

How to add label to point without marker displaying in QGIS with python


I'm using a python script to manipulate the display of shapefiles in QGis.


My code basically selects an active layer and sets a field as the label of the point. Like this:



layer = qgis.utils.iface.activeLayer()
label = QgsPalLayerSettings()
label.readFromLayer(layer)
label.enabled = True
label.fieldName = 'objnam'
label.placement= QgsPalLayerSettings.OverPoint
label.setDataDefinedProperty(QgsPalLayerSettings.Size,True,True,'8','')
label.writeToLayer(layer)
QgsMapLayerRegistry.instance().addMapLayers([layer])


This give's me the following result:


Text label overlapping a default point marker


I would like to add code so that the coloured marker will not be visible. I've tried adding the following above my code in attempt to make the marker transparent:


renderer = layer.rendererV2()
symbol = QgsFillSymbolV2.createSimple({'style':'solid', 'color': '255,255,255,0', 'style_border':'no'})
renderer.setSymbol(symbol)

But this seems to do nothing. I have a feeling that I misunderstand how the symbol layer works. Any help or guidance is welcomed.



Answer



Size should be 0. Just add this parameter to the params dictionary like below:



symbol = QgsFillSymbolV2.createSimple({'size':'0'})

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...