I'm designing a symbol for an external application that needs to be a vector field marker combined with a simple point marker, displaying a line at a certain angle around the center point. In PyQGIS, it's easy to instantiate the vector field class, as well as the field type (Polar), and angle units (Degrees). However, since it's polar, I need to set the length and angle attributes from the table of the layer I'm trying to display. I'm seeing in the API documentation for the QgsVectorFieldSymbolLayer that there are functions to set the X and Y attributes, which is necessary for a cartesian vector field marker, but irrelevant for a polar vector field marker. I need something like "setLengthAttribute()" and "setAngleAttribute()", much like what is possible in the QGIS GUI:
My relevant snippet of code currently looks like this:
symbol = QgsMarkerSymbolV2.createSimple({})
symbol.deleteSymbolLayer(0)
symbol_layer = QgsSimpleMarkerSymbolLayerV2()
symbol_layer.setSize(.5)
symbol_layer.setColor(QColor("yellow"))
symbol_layer.setOutputUnit(QgsSymbolV2.MapUnit)
symbol.appendSymbolLayer(symbol_layer)
symbol_layer = QgsVectorFieldSymbolLayer()
symbol_layer.setColor(QColor("yellow"))
symbol_layer.VectorFieldType(QgsVectorFieldSymbolLayer.Polar)
symbol_layer.AngleUnits(QgsVectorFieldSymbolLayer.Degrees)
symbol_layer. # lengthAttribute?
symbol_layer. # angleAttribute?
symbol.appendSymbolLayer(symbol_layer)
renderer = QgsSingleSymbolRendererV2(symbol)
self.mylayer.setRendererV2(renderer)
Any idea how to set the angle and length attribute?
QgsMarkerSymbol.setAngle()
or.setDataDefinedAngle()
work for the angle? (qgis.org/api/…) – alphabetasoup Oct 1 '15 at 18:33symbol_layer.setDataDefinedAngle(QgsMarkerSymbolV2("attribute field"))
– Alex92 Oct 1 '15 at 20:07