2

I'm doing a spatial join, but the styling doesn't work. What needs to be fixed?

##Style=name
##drivetimepoints=vector
##gridwgs84layer=vector
##DriveTimeGrid=output vector
outputs_QGISJOINATTRIBUTESBYLOCATION_1=processing.runalg('qgis:joinattributesbylocation', gridwgs84layer,drivetimepoints,['intersects'],0.0,0,'sum,mean,min,max,median',0,DriveTimeGrid)
layer = processing.getObject(outputs_QGISJOINATTRIBUTESBYLOCATION_1['OUTPUT'])
layer.loadNamedStyle("C:/QGIS Style File/Drive Time Grids.qml")
layer.triggerRepaint()
asked Dec 20, 2018 at 10:31

1 Answer 1

2

Once your script has finished, your output is loaded onto canvas. What you are doing is applying the style before the output is loaded into QGIS. So the style is not applied correctly. There is an option in the interface when you run your script:

Script interface


You can apply the style in a couple of ways:

  1. Load the layer in your script and uncheck the option from the interface:

    ##Style=name
    ##drivetimepoints=vector
    ##gridwgs84layer=vector
    ##DriveTimeGrid=output vector
    from qgis.core import QgsMapLayerRegistry
    outputs_QGISJOINATTRIBUTESBYLOCATION_1=processing.runalg('qgis:joinattributesbylocation', gridwgs84layer,drivetimepoints,['intersects'],0.0,0,'sum,mean,min,max,median',0,DriveTimeGrid)
    layer = processing.getObject(outputs_QGISJOINATTRIBUTESBYLOCATION_1['OUTPUT'])
    QgsMapLayerRegistry.instance().addMapLayer(layer)
    layer.loadNamedStyle("C:/QGIS Style File/Drive Time Grids.qml")
    layer.triggerRepaint()
    
  2. Add the Set style for vector layer algorithm and again uncheck the option from the interface:

    ##Style=name
    ##drivetimepoints=vector
    ##gridwgs84layer=vector
    ##DriveTimeGrid=output vector
    outputs_QGISJOINATTRIBUTESBYLOCATION_1=processing.runalg('qgis:joinattributesbylocation', gridwgs84layer,drivetimepoints,['intersects'],0.0,0,'sum,mean,min,max,median',0,DriveTimeGrid)
    layer = processing.getObject(outputs_QGISJOINATTRIBUTESBYLOCATION_1['OUTPUT'])
    outputs_QGISSETSTYLEFORVECTORLAYER=processing.runalg("qgis:setstyleforvectorlayer", layer, "C:/QGIS Style File/Drive Time Grids.qml")
    
answered Dec 20, 2018 at 11:10

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.