1

I am trying to clip the road layer to district boundary layer in QGIS using clip and enabling 'iterate' option and I get the clipped road layers of individual districts. Later, I need to add the district names into the road layer attributes under field 'dist_name' manually. In order to add the dist_name I am opening the road layer and entering the district name using field calculator one by one.

Is there any way how I can add it automatically doing the clipping process?

enter image description here

4
  • 2
    I removed your PyQGIS tag because your question contains no code.
    – PolyGeo
    Jan 27, 2020 at 11:49
  • Please specify which QGIS version you're using, because in 3.4 there's no option to iterate during clip.
    – Erik
    Jan 27, 2020 at 11:50
  • I am using Qgis 3.10.2 Jan 27, 2020 at 11:54
  • I found iterate option in 3.4.15 Jan 27, 2020 at 16:56

2 Answers 2

2
+50

Seeing the label-placement of your district boundaries I assume they are actually polygons. If so, you can do the following:

Instead of using "clip", try "intersection". This will cut your roads at the edges of each district and add their attributes to the roads.

1) Two layers. A) Roads (not clipped) and B) Districts (labels show district names)

enter image description here

2) Run intersection tool. Choose roads as input and districts as overlay

enter image description here

3) The result. The roads are clipped into pieces at the district borders and contain the attributes of their intersecting district layer.

enter image description here

Additional info: In case your roads are splitted over several layers, you can use "batch processing" (you can find this option at the bottom of intersection tool).

0

If your districts are actual polygons, you can do join by location (after clip) and get the name of the polygon attached to each line. You may have to use field calculator too.

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.