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).