Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

QgsVectorLayer Right click->Properties->Style->Single symbol->click on simple line in tree node ->symbol layer type -> Marker line

Kindly help me to set marker line symbol programmatically by using Python.

share|improve this question
up vote 4 down vote accepted

The only documentation I found is here, but it doesn't help much in practice.

Here is an example I used to set the renderer of the current layer to a symbol with two layers: one 'Simple Line' and one 'Marker Line'. The marker line is tricky, because you need to work with a subSymbol.

# Use the currently selected layer
layer = qgis.utils.iface.mapCanvas().currentLayer()

registry = QgsSymbolLayerV2Registry.instance()
lineMeta = registry.symbolLayerMetadata("SimpleLine")
markerMeta = registry.symbolLayerMetadata("MarkerLine")

symbol = QgsSymbolV2.defaultSymbol(layer.geometryType())

# Line layer
lineLayer = lineMeta.createSymbolLayer({'width': '0.26', 'color': '255,0,0', 'offset': '-1.0', 'penstyle': 'solid', 'use_custom_dash': '0', 'joinstyle': 'bevel', 'capstyle': 'square'})

# Marker layer
markerLayer = markerMeta.createSymbolLayer({'width': '0.26', 'color': '255,0,0', 'interval': '3', 'rotate': '1', 'placement': 'interval', 'offset': '-1.0'})
subSymbol = markerLayer.subSymbol()
# Replace the default layer with our own SimpleMarker
triangle = registry.symbolLayerMetadata("SimpleMarker").createSymbolLayer({'name': 'filled_arrowhead', 'color': '255,0,0', 'color_border': '0,0,0', 'offset': '0,0', 'size': '1.5', 'angle': '0'})

# Replace the default layer with our two custom layers

# Replace the renderer of the current layer
renderer = QgsSingleSymbolRendererV2(symbol)

You can also inspect (and probably modify) the symbols for a layer, for example:

share|improve this answer
Thanks a lot. its working fine. – venkat May 20 '13 at 11:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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