This is a continuation of the question QGIS Extract by Expression with multiple polylines in Processing Modeler I have polylines with increasing values, Gabriel De Luca helped me to automate the digitization of the lines using the procedure given in as answer in the above link. Is it possible to define from which number the line value should start instead of 0 or by what value it should increment?
2 Answers
From what I understand from the linked question, you already have a bunch of features numbered from 0 to n (using a field you created and named "order").
You have two choices: actually modify the order field by tweaking the model in the modeler, or keep the underlying data as is, and use a labelling rule.
Solution 1: Tweak model
- Add new
NumberInputs in your custom model (e.g.startvalueandstep) - Add a new "Field calculator step" in your custom model
Be sure to set "Create new field" to "No" to modify the existing "order" field.
The formula becomes @startvalue + "order" * @step. Note the use of "@" to call model inputs. Also note that model input names MUST be lowercase in the formula field (i.e, if you name the input StartValue, you still need to refer to it with @startvalue in the formula field)
Alternatively, you may want to tweak you existing Field Calculator step using the same principle.
Solution 2: Use labeling rule
Just use an expression in the labels settings (Edit the "Label with" field)
This is far easier, but it is just a cosmetic solution.
- 1,989
- 11
- 15
You have several ways of doing this. I'll give you an example. You have a layer with 30 polylines, you want to do a treatment every 5 lines starting with the 3rd line.
First step, you store the index of the lines you want to process in a list.
layer = iface.activeLayer() # My layer
index = [i for i in range(2,30,5)] # My list : Loop with range(start,end,increment)
print(index)
[2, 7, 12, 17, 22, 27] # Result
Then, you will go through all the lines of your layer by adding a condition that is: I do a treatment if and only if the identifier of my line is included in the list I created previously.
for feature in layer.getFeatures(): # Loop on features of my layer
if feature.id() in index: # My condition
print(feature.id()) # My treatment : I print the index of my line
#Output
2
7
12
17
22
27
The above example retrieves the value of the line index and not the value of a certain field in your line. Tell me if it's satisfying for you. If not, can you be more specific?
- 4,090
- 7
- 23


@step,@startvalue,"order","order" * 10 + 100And see which one produces NULL.
Just to be sure: The field you create in the previous step is named "order", not "ordered"?
– Yoann Quenach de Quivillic Dec 04 '19 at 13:58