4

I made a model, which works like this: from a polygon, it extract its edges coordinates, turns it into lines and add an extra line.shp who will store the distance between the points.

Because my skills are basic, I can't figure out, firstly, how to add a new field in the attribute table "distance", the command $length and secondly, how to add style in my new layers.

I have .qpt files with styles stored in my PC. I read the QGIS manual, I load them in the model which does normally all the work, but the result are some default style layers.

Generally, the model, does the job that I want, but I have to add the style to the new layers and add the length field... I want to improve it, to work faster.

Do you have any suggestions?

enter image description here

4
  • You can add any fieldcalculator operation to models, you just need to know how exactly the fields are named.
    – Erik
    Mar 28 '20 at 10:56
  • @Erik using the Field Calculator on the Processing Modeler you can create a new field choosing type, name and expression. Not necessary to have already a field and to know his name.
    – Val P
    Mar 28 '20 at 11:17
  • Yeah, but if you want to do operations based on fields, those need to be named exactly as in the model @ValP
    – Erik
    Mar 28 '20 at 11:27
  • @Erik Of course. In that case yes.
    – Val P
    Mar 28 '20 at 11:32
4

To add to your model the two required tasks, you must use the Algorithms Field Calculator and Set Style for Vector Layer.

This is how your model should appear:

enter image description here

Using the Field Calculator algorithm you can create a new field using an expression ($length in your case). This is how the algorithm should be compilated:

enter image description here

Now you can add to the output of this operation the requested style using the algorithm Set style for vector layer. This is how need to be compilated:

NOTE: in your question, you speak about .qpt files but they are layout template files. The style files in QGIS have .qml extension.

enter image description here

The final result of this model will be a linear vector layer with the requested symbol style and a new field distance in his Attribute table.

enter image description here

2
  • Thank you for your fast response and your analytical tutorial. I was thinking it wrong. I guessed that the modifications, I asked,had to work with the result boxes because they are the last export fields. With your guide it makes a new shp with the results I needed. And magically the custom styles are appearing. You have answered my question thank you again! But as I can see, that way creates a separate file for every new field I add. I mean if I had to add a length field, and a date field,if I follow your guide it will make 2 shp files.
    – Pitheas
    Mar 28 '20 at 12:04
  • 1
    You're welcome. If you need to add more than one new field you can just add another Field Calculator algorithm with the new field expression using as Input the previous Field Calculator algorithm and, then, apply to this last output the style. Technically, you can add n fields just replicating the process n times. Let me know if you have problems to do it and I will help you.
    – Val P
    Mar 28 '20 at 12:19

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.