2

I have a set of roads that I wish to clip. How ever I only need a segment of each road based on the state its located in. I can do this independently but seems like there should be a better way.

Ill try to explain it as best as I can:

I have road A, B AND C. I have states 1, 2 and 3.

All 3 roads run by all each of the states. However, I need to export only the part of road A within state 2, the part of road B within state 1 and the part of road C within state 3.

Hope its not too confusing. In reality i'm dealing with municipalities, not states but I feel this is a simpler way of explaining it.

Using QGIS 3.4 MADERIA

  • Is the use of 'expression' mandatory ? it's in your title not in the body of your question ... – snaileater Jul 20 at 6:21
3

Using Expression in QGIS Geometry by Expression tool -

Provided:

  • Road layername is roads and it has road_no field to represent the road name (A, B, C)
  • State layername is states and it has state_no field (1, 2, 3)

enter image description here

Start Geometry by expression tool in the QGIS Processing toolbox - Vector geometry

Select your roads layer as input (1), and choose Line as geometry type (2), then click on the epsilon mark (3).

enter image description here

Try an expression in the Expression Dialog window:

combine(
 combine(
  intersection(geometry(get_feature( 'roads',  'road_no', 'A')),
               geometry(get_feature('states', 'state_no', '2'))),
  intersection(geometry(get_feature( 'roads',  'road_no', 'B')),  
               geometry(get_feature('states', 'state_no', '1')))
  ),
  intersection(geometry(get_feature( 'roads',  'road_no', 'C')),  
               geometry(get_feature('states', 'state_no', '3')))
)

enter image description here

It will return a new temporally layer, Modified geometry.

enter image description here

0

I am not sure if you need the solution using expression only. However I suggest to use the option

Intersect

this operation in QGIS to generate the lines separately crossing in each state/multiplicity polygons. The lines will have the attributes from the respective state polygon.

enter image description here

Results as below:

enter image description here

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.