1

I have a polygon shapefile that consists of different polygon features. Each polygon features can be identified by a unique group_id. I also have a line shapefile with different straight line features that lie on top of the polygons. Similar to the polygon file, each line feature has a unique 'group_id', which are the same as the ones found in the polygon file.

I would like to cut each polygon feature by these line features, but only those that share the same group_id. I'm aware I can use the Split by Line features, however this will use all line features to cut all polygon features, neglecting the group_id.

enter image description here

Any ideas how I could perform some sort of group by function?

2
  • I've included it in the question Mar 1 at 20:14
  • How many different groups do you have? If there aren't many you could apply a definition query to your polygons for each group ID and the same for you lines. Then run the split by lines tool. (This tool allows you to edit features in place. ) Then click on the filter icon of each layer and replace the group ID in the filter to the next group ID and run the tool again. Repeat until done. I'd save edits after each run. It isn't elegant but it's easy to change the definition query group IDs this way. If you have too many groups for this manual procedure you could put it in a model.
    – John
    Mar 1 at 20:36

1 Answer 1

3

Here's a three step approach.

  1. Use Split Vector Layer to split both the polygons and lines by the unique id (eg fid). This should give you two directories of files, one for the polygons and the other for the lines - with the same names.

  2. Use Split by Lines in Batch Processing Mode.

    • Use Add files by pattern... to load up the polygon files in the Input layer field.
    • Then use Calculate by Expression to load the line files in the Split layer field eg <lines directory> + base_file_name( @INPUT)`.
    • You can similarly use Calculate by Expression to create the names for the Output files
  3. Finally, use Merge Vector Layers to merge the files from step (2) into a single file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.