0

I have a layer with the road network (lines) and a layer with municipalities (polygons). I'd like to split the lines by municipality borders and then attain the name/id for the municipality the road is located in.

I did split the road correctly with SAGA's line-polygon intersection inside QGIS, but then when trying to "Extract by location" and using 'within' it doesn't really work, since the lines are still touching the border of the polygons.

To solve this I extracted the centroids of the lines and used "Extract by location" on them instead and it seems to work quite nicely for my dataset, with only one missing value (where the centroid was outside the polygon). So there's always a risk this might not work.

I feel like there might be a simpler solution to this, without using centroids? I'm open to suggestions using QGIS or Python (GeoPandas).

1
  • 2
    You might look at the Vector Overlay Union tool.
    – johns
    Jul 27, 2021 at 12:59

1 Answer 1

1

You can use the native tool intersection (under vector -> vector overlay).

It extracts the portions of features from the input layer that overlap features in the overlay layer.

Features in the intersection layer are assigned the attributes of the overlapping features from both the input and overlay layers.

Beware that this removes all line parts not covered by your polygons.

3
  • Thank you for your answer! I tried the native tool, but my dataset is so big that it was taking hours for it to run so I used SAGA's tool instead. Any idea on how to speed things up a bit with the native tool? I don't want to simplify my geometries because I will need them later.
    – jeemil
    Jul 27, 2021 at 13:06
  • Since this doesn't seem to be a repetitive task, you could simply run the task once, and be done with it.
    – Erik
    Jul 27, 2021 at 13:15
  • True! I'll time for a coffee while I wait.
    – jeemil
    Jul 27, 2021 at 13:29

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.