1

I need to set a point on a map as an ASCII symbol with python.

I'd like to do this in a rule based renderer.

something like:

rule.setSymbolAsFontMarker("✫")

So I'd have something like this in my existing code:

renderer = QgsRuleBasedRendererV2(symbol)
root_rule = renderer.rootRule()
rule = root_rule.children()[0].clone()
rule.setSymbolAsFontMarker("✫")
rule.setScaleMinDenom(70000)
rule.setScaleMaxDenom(1000000) 
root_rule.appendChild(rule)
## delete the default rule
root_rule.removeChildAt(0)
## apply the renderer to the layer
layer.setRendererV2(renderer)

Any guidance is welcome!

2

This code works for a single symbol renderer:

layer = iface.activeLayer()
properties = {'name': "✫"}
symbol = QgsSymbolV2.defaultSymbol(layer.geometryType())
renderer = QgsSingleSymbolRendererV2(symbol)
symbol_layer = QgsFontMarkerSymbolLayerV2.create(properties)
renderer.symbols()[0].changeSymbolLayer(0, symbol_layer)
layer.setRendererV2(renderer)

If you want a rule based renderer, you need to use QgsRuleBasedRendererV2

Here is a nice post. Scroll down to "Rule-based renderer".

  • Thanks! I've tried this with properties = {'name': "*"} but I only get a blank symbol (default circle maker)? – FredFury Apr 18 '16 at 13:57
  • Probably something with encoding. It works on my Debian Qgis 2.12 and display this star. – dmh126 Apr 18 '16 at 14:00
  • Solved encoding with: properties = {'chr': u'✫','color':'#000000','size':'7'} – FredFury Apr 19 '16 at 9:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.