2

I have some difficulties with a task I have.

Data: layer 1 (tmc_segments), layer 2(regional_roads(earth)). Layer one contains simplified geometry of the road network (just simple lines with data about movement). Layer two contains some roads from Layer one, but these roads have more detailed geometry. Objective: to get from layer 1 only those roads that are present on layer 2. Layer one contains two distinctive attributes:road_numbe and road name. Layer two contains one attribute Name, wich contains both number and name.

two road layers

As you can see, road geometry is very diferent, so Select by location not working that well.

atributes layer 1 atributes layer 2

1
  • Try this expression in the Select by Expression tool: "road_name" in aggregate('name of layer 2', 'array_agg', "road_name"). It should work if the aggregate() function accepts array_agg as a parameter.
    – csk
    Commented Jan 28, 2020 at 17:18

1 Answer 1

5

In Layer 1's (or a copy thereof's) layer properties, under Joins create a join to Layer 2, matching road_name as the join and target fields. Choose layer 2's FID as the joined field.

Then filter/select based on this joined FID (which will have a prefix in its name) not being null. Or run the Extract by attribute processing algorithm on this layer with the joined FID is not null as the operator.

Alternately, I think you should be able to do the whole thing with the Join attributes by field value processing algorithm with the Discard records which could not be joined box selected.

6
  • Thank you for answer but I do not quite understand it. What is FID?
    – PeaceFrog
    Commented Feb 2, 2020 at 18:38
  • Layers will have some sort of field which is an (indexed) unique identifier: by convention usually called the FID, for Feature IDentifier. It may be called something else in your layers. In any case if you join Layer 2 to Layer 1, Layer2_FID in the join is a reliable tell that no matching feature was found in Layer 2.
    – Houska
    Commented Feb 2, 2020 at 20:45
  • You can actually use any field in Layer 2 that is different than the one you are joining by and that you know won’t be null in actual records in Layer 2
    – Houska
    Commented Feb 2, 2020 at 20:55
  • It's not working for me, I joined atribute, but all field is null. I think it's because names in two layers is not the same. I added that to the question. Layer one contains two attributes:road_numbe and road_name. Layer two contains only attribute Name, wich contains both number and name. So, for example, one road has 'Name: SR1 FERENTINO' on one layer and 'road_name: Ferentino', 'road_numbe: SS 1' on another
    – PeaceFrog
    Commented Feb 3, 2020 at 21:31
  • Indeed, the answer was predicated on (original) assumption that the names in both layers would be identical. As in absolutely identical, coming from the same source, with same spelling, capitalization, punctuation, etc. You have 2 ways forward: you can figure out how to manipulate the names to create something same, with functions to adjust the capitalization, concatenate the number and name, etc. Or you can try with QGIS' fuzzy matching logic. But we're beginning to veer off into different questions/tutorials. Good luck!
    – Houska
    Commented Feb 3, 2020 at 21:45

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.