2

A newbie here trying to learn QGIS for work.

How can I select specific features of a polyline with the same values as the attributes of the buffer polygons I generated?

I have a layer of polylines with numerical values as one of their attributes.

I was able to generate buffer polygons using the midpoint of each line and used the join by attributes function to determine the maximum values of the attributes of the lines within each buffer.

I now need to select the lines that contain the said maximum values for each buffer zone. Since I have a lot of lines to work with, manually finding each one is not an option.

2
  • Which version of QGIS are you using?
    – Ben W
    Commented Feb 18, 2019 at 5:26
  • I am currently using the 2.18 version Commented Feb 18, 2019 at 8:03

2 Answers 2

2

Not an elegant way (, but it works)

Assuming that you have a "lines" layer with a numeric field named "id".
Assuming also that you have a "polygons" layer with a numeric field named "max_id", which represents the maximum id value of the linestrings that are within each polygon.

You can Select by Expression the linestring features that have an id value that matches with any max_id value in the polygons layer, using the lines layer as input and the following expression:

concat( 
    ',,', 
    aggregate( 
        layer:='polygons', 
        aggregate:='concatenate', 
        expression:= to_string("max_id"), 
        concatenator:= ','), 
    ',,') 
LIKE 
concat( 
    '%,',
    to_string("id"), 
    ',%')   

First, the expression builds an aggregate (by concatenation) of the values in the max_id field of the polygons layer. Returns something like: '4,25,76'.
Then, builds a new string with that one, which starts and ends with two commas. Returns something like: ',,4,25,76,,'.
In the other hand, also builds a string with the "id" attribute for each linestring feature, which starts with %, and ends with ,%. Returns something like '%,4,%' for the feature with the id value = 4.

Finally, it compares, if ',,4,25,76,,' is like '%,4,%' (% symbols are wildcards), and returns true or false. That determines if the feature must be selected or not.


DISCLAIMER: Tested with a few features. The performance for a lot of them is not guaranteed.

0
1

I found a way to solve my problem.

The function I used to find the maximum values of the attributes for the lines within each buffer zone is the join attributes by location. I discovered that the values generated had a different precision from the original values of the attributes. As such I used the refactor fields function to change the precision of the original values of the attributes to match those of the ones in the buffer zones.

After, I used the join attributes table function to find the lines with the same values as those in the buffer zones. Then I just filtered the results with the non-null value and saved the new shapefile.

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.