2

Currently, I am trying to figure out how to set a subsymbol for a PyQGIS generated geometrygeneratorsymbol layer. As can be found in the code I tried multiple things resulting in crashing the kernel or nothing at all. The images represent the manual workflow which works fine. I am interested in transferring this 'Simple line' option to 'Arrow' in an automated way. Geometry generated line Geometry generated line with arrow as subsymbol

from qgis.core import (
    QgsVectorLayer,
    QgsSingleSymbolRenderer,
    QgsLineSymbol,
    QgsFillSymbol,
    QgsProject,
    QgsRectangle,
    QgsArrowSymbolLayer,
    QgsMultiRenderChecker,
    QgsProperty,
    QgsSymbolLayer,
    QgsMapSettings,
    QgsSymbol
)

from qgis.core import QgsVectorLayer,  QgsProject
layer = QgsVectorLayer( "?query=SELECT from_country, ubc_processing_plant, delivered_tonnes_2019, make_line(Centroids_countries.geometry, UBC_processing_2030.geometry) FROM ubc_flows JOIN Centroids_countries ON ubc_flows.from_country = Centroids_countries.NUTS_NAME JOIN UBC_processing_2030 ON ubc_flows.ubc_processing_plant = UBC_processing_2030.name", "vlayer", "virtual" )
QgsProject.instance().addMapLayer(layer)

def test_3(self):
        sym = self.renderer().symbol()
        
        shape_sym = QgsGeometryGeneratorSymbolLayer.create({'geometryModifier': 'difference(difference(make_line(start_point($geometry), centroid(offset_curve($geometry, length($geometry)/-10.0)), end_point($geometry)), buffer(start_point($geometry), 10000)), buffer(end_point( $geometry), 10000))', 'outline_color': 'black', 'symbolType': '1'})
        shape_sym.setSymbolType(QgsSymbol.Line)
        
        arrow = QgsArrowSymbolLayer.create(
            {
                "arrow_width": "3",
                "head_length": "3",
                "head_thickness": "3",
                "head_type": "0",
                "arrow_type": "0",
                "is_curved": "1",
                "arrow_start_width": "3"
            }
        )
        fill_sym = QgsFillSymbol.createSimple(
            {"color": "#8bcfff", "outline_color": "#000000", "outline_style": "solid", "outline_width": "0.1"}
        )
        
        #shape_sym.setSubSymbol(arrow)
        #shape_sym.setSubSymbol(sym_layer)
        sym.changeSymbolLayer(0, shape_sym)

test_3(layer)
0
0

The answer to set a subsymbol in PYQGIS qgis 3.x

Replace the sub symbol with the new marker symbol:

shape_sym.subSymbol().changeSymbolLayer(0, arrow) 

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.