Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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
add comment

1 Answer

up vote 2 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
subSymbol.deleteSymbolLayer(0)
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'})
subSymbol.appendSymbolLayer(triangle)

# Replace the default layer with our two custom layers
symbol.deleteSymbolLayer(0)
symbol.appendSymbolLayer(lineLayer)
symbol.appendSymbolLayer(markerLayer)

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

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

layer.rendererV2().symbol().symbolLayer(0).properties()
share|improve this answer
    
Thanks a lot. its working fine. –  venkat May 20 '13 at 11:15
add comment

Your Answer

 
discard

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.