I'm trying to get the matching features from an intersecting vector layer. I can manually open Extract by expression tool and put the expression like intersects($geometry, geometry(get_feature('Liness', 'id', '1'))) where 'Liness' is one of the polylines and I'm giving the other polyline as input. I would like to implement it using QGIS Processing Modeler.

Processing Modeler

Since in extract by expression can only give one input, I'm unable to get the desired output. Can anybody suggest a better method? I want to use the matching features to other further steps.

Or can I implement it using pyqgis? Is there any code sample to refer?

EDIT 1: As suggested by Gabriel De Luca, tried "Extract by Location". But it's selecting my input polyline in random order.

enter image description here enter image description here

Also, I would like to have each polyline with "id" of "Liness"(whose id changes based on the lines I plot for selection) to have a separate section. Why because, I would like to use its output to autoincrement function, where I can increase each of the input lines (whose selection came from different "id") values from zeros to a finite value based on the "Liness" intersection in order.

  • 1
    Do you want the model to return the intersections found between the input layer and all the features of the 'Liness' layer (not just the one with 'id' = '1')? Nov 9, 2019 at 15:29
  • @GabrielDeLuca Actually I want to get for all the "id". The id is ranges from 1 to around 1000. I was not aware of how to implement. So I started from at least from id=1 Nov 9, 2019 at 16:06
  • 1
    I think you would not have difficulty in doing what you are looking for with the Extract by location (intersect predicate) algorithm, instead of the Extract by expression one. Nov 9, 2019 at 18:00
  • @GabrielDeLuca. Thank you so much. It's great. I really appreciate your help. But it won't work in my application. I want to use it's output for autoincrement function. actually I'm trying to give contour values to lines. So Each line section should start from zero. With extract by location, every section values are incrementing randomly. I want to do the value incrementing for each line section(with different ids) to start from zero and should be continuous, not random. I think it's not appropriate to ask it here. But if you can help me, kindly can you give a solution? Nov 9, 2019 at 20:02
  • You are welcome! Feel free to edit the question to focus on the exact result you want. I am not understanding it at all, if you could clarify it with a graph that shows some two-layer multilines, labeled with their attributes, which helps to understand how the transfer of attributes you want to do is, I think it would help. Nov 9, 2019 at 22:02

1 Answer 1


We start with single-part line vector layers: 'Input' and 'Lines'.
'Input' layer contain countour lines as features.
'Lines' layer contain some dumb lines as features, wich we will use to rotulate the features of 'Input' layer.
Both layers are GeoPackage and cointain one "fid" field, autocompleted.


We need to know what features of the 'Input' layer, intersect what features of the 'Lines' layer. Thereforoe, we need to Join Attributes by Location in the modeler.


It returns both Joined and Unjoined outputs.
Joined output is a layer with a new field: "Lines_fid", wich has the "fid" attribute value of the dumb line intersected for each contour line.
It's a condition that each countour line must intersect only one dumb line.

We can use an Extract algorithm here, using the new "Lines_fid" field values to the match.
Instead of that, what we do is add a Field Calculator algorithm to create a new field in the Joined ouput, populated with the distance along dumb lines to each intersection, with the folowing expression:

    geometry:= geometry( get_feature( 'Lines', 'fid', attribute( 'Lines_fid'))), 
    point:= intersection( 
      $geometry, geometry( get_feature( 'Lines', 'fid', attribute( 'Lines_fid'))))), 


Now, we add a new Field Calculator algorithm to the model, to aggregate, as an array, the "dist" values, grouped by the "Lines_fid" value and ordered by "dist" values growing. To that array, we find the index position of the "dist" value of the current feature, and return it as an order number to the new field, named "order", with the following expression:

array_find( array_agg( "dist", group_by:= "Lines_fid", order_by:= "dist"), "dist")


We named the output as "Ordered" to get the new layer when run the model.


So, let's run it to see what it do.


The output is a new 'Ordered' layer, with only the features that intersect any dumb line, with new "Lines_fid", "dist" and "order" fields. We label them with the concatenation of the values in all the fields, with the expression: fid || '-' || Lines_fid || '-' || dist || '-' || order.


Here we can check if distances along dumb lines are correctly calculated and if the ordering is working fine.

Finally, this is the result, with just 'Ordered' layer labeled with "order" field values.


  • Thanks for your great help. Can we improve this further? Is it possible to define from which number the data should start instead of 0 or by what value it should increment? Dec 3, 2019 at 9:22
  • @bibinwilson Hi, I would think that it is possible. Since we have an "order" expression, something like to startvalue + "order" * stepvalue must work. Feel free to ask it in a new question if you can't solve, we will find the way to implement it. Dec 3, 2019 at 10:00

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.