4

I am writing a model that takes a polygon shapefile as input, converts it to polylines, explodes it to individual lines and finally applies a (tested) style, khLineLength1.qml, which labels each line with its length.

[png]

Here is the log:

Algorithm Polygon_Sides starting...
Prepare algorithm: QGISPOLYGONSTOLINES_1
Running Polygons to lines [1/3]
Parameters: INPUT =C:/Users/DAZ/QGIS_maps/Kaihu/epsg3706/routes_PG.shp
Converting outputs
OK. Execution took 0.187 ms (1 outputs).
Prepare algorithm: QGISEXPLODELINES_1
Running Explode lines [2/3]
Parameters: INPUT =C:\Users\DAZ\AppData\Local\Temp\processing\98fbdd36b519415f9e9bc25e9939916d\OUTPUT.shp
Converting outputs
OK. Execution took 0.234 ms (1 outputs).
Prepare algorithm: QGISSETSTYLEFORVECTORLAYER_1
Running Set style for vector layer [3/3]
Parameters: INPUT =C:\Users\DAZ\AppData\Local\Temp\processing\140dc16954394bd58455470538e300e9\OUTPUT.shp, STYLE =khLineLength1.qml
Converting outputs
OK. Execution took 0.123 ms (1 outputs).
Model processed ok. Executed 3 algorithms total
Converting outputs
Loading resulting layers
Algorithm Polygon_Sides finished

According to this https://docs.qgis.org/2.6/en/docs/user_manual/processing_algs/qgis/vector_general_tools/setstyleforvectorlayer.html the Set style for vector layer algorithm should have a definable output Styled layer. The modeling dialog is allowing me to define the parameters Vector layer and Style file but that is all.

To clarify: In the modeler, for example, when I edit the Explode lines algorithm, I see a title Output layer and beneath it a box with the hint [Enter name if this is a final result]. I do not see this for the styling algorithm and this seems to 'dead-end' the event sequence, preventing rendering and disallowing further styling and the successful execution of any subsequent algorithm.

This is a 'first experience' with the Modeler. Apart from 'little grey cells', what am I missing here?

Supplementary diagram Supplementary diagram

  • Ehm, what happens if you add another processing tool? You should be able to use the styled layer as an input. – Thomas Oct 8 '15 at 22:14
  • Thank-you, I agree (but cannot achieve), and when I add another algorithm, I am sure to specify its input as 'Styled layer' from algorithm 'Set style for vector layer'! So for example, running the same styling algorithm twice in succession, the log output additional to the above looks like this: Prepare algorithm: QGISSETSTYLEFORVECTORLAYER_2 <br> Running Set style TWO [4/4] <br/> Parameters: INPUT =None, STYLE =khLineLength1.qml <br> Failed Error executing algorithm Set style TWO 'NoneType' object has no attribute '__getitem__' See log for more details – Bad Loser Oct 8 '15 at 22:47
  • Seems to me that SetVectorStyle.py is doing everything right when trying to define the output vector: self.addOutput(OutputVector(self.OUTPUT, self.tr('Styled layer'), True)) so the problem is more likely to be with the modeler editing routines. Running QGIS 2.8.3 & 2.10.1 under Windows 8. – Bad Loser Oct 9 '15 at 1:54
3

I don't think the docs are very clear on this. From my understanding, the Set style for vector layer algorithm does not create a new output layer. The end result is the input layer with the style file applied. I believe this is why there is no "output" option for the algorithm.

From the QGIS 2.8 docs and checking the parameters from the Python console, both mention an Output:

import processing

processing.alghelp("qgis:setstyleforvectorlayer")
ALGORITHM: Set style for vector layer
    INPUT <ParameterVector>
    STYLE <ParameterFile>
    OUTPUT <OutputVector>

However, when you check the Console usage, you will see that there is no parameter for Output:

processing.runalg("qgis:setstyleforvectorlayer", input, style)

So if you want to add more than one style to a shapefile, you may need to create another set of the same algorithms within your model.

Hope this helps!

  • 5
    The output is hidden, since there has to be an output...but it is automatically set by the algorithm itself to be equal to the input. This is a strange case, and this algorithm is not a normal one, it's a very peculiar case. That's the reason why the behaviour seems a bit strange...It is more of a hack to add this kind of functionality that is not the normal processing algorithm which takes a layer and produces new stuff – Victor Olaya Oct 9 '15 at 10:54
  • 2
    @VictorOlaya - Thanks buddy, you should post your comment as an answer and I will remove mine. Afterall, it has your name on it :) – Joseph Oct 9 '15 at 10:59
  • Meanwhile, precariously orbiting planet QGIS, I still cannot render a styled result. [See supplementary diagram above.] I have edited step 'Explode lines' to define a final, output layer 'Exploded_lines'. This (latter) layer, although rendered, is not specifically offered as input to the 'Set style' step. Catch-22? – Bad Loser Oct 9 '15 at 20:15
  • Most welcome buddy and hope you get the results you're looking for! And if Victor ever posts an answer here, I would rather you accept his :) – Joseph Oct 12 '15 at 9:21

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.