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:

Available options for polar vector field marker symbol

My relevant snippet of code currently looks like this:

    symbol = QgsMarkerSymbolV2.createSimple({})

    symbol_layer = QgsSimpleMarkerSymbolLayerV2()

    symbol_layer = QgsVectorFieldSymbolLayer()
    symbol_layer. # lengthAttribute?
    symbol_layer. # angleAttribute?

    renderer = QgsSingleSymbolRendererV2(symbol)


Any idea how to set the angle and length attribute?

  • Does QgsMarkerSymbol.setAngle() or .setDataDefinedAngle() work for the angle? (qgis.org/api/…) – alphabetasoup Oct 1 '15 at 18:33
  • @alpha-beta-soup Maybe I'm not doing it correctly, but it doesn't seem to be working. setDataDefinedAngle is a function of QgsMarkerSymbolV2, not QgsVectorFieldSymbolLayer, so it doesn't seem to be recognizing it. My code looks like this, in varying orders: symbol_layer.setDataDefinedAngle(QgsMarkerSymbolV2("attribute field")) – Alex92 Oct 1 '15 at 20:07

You have two options:

  • using api directly:
  • using data defined properties:
symbol_layer.setDataDefinedProperty("x_attribute", "length_attribute")
symbol_layer.setDataDefinedProperty("y_attribute", "angle_attribute")

Hope this helps.

| improve this answer | |

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.