Crop closed paths into open paths

In a few operations, how can I crop closed paths and have the result be a set of open paths? It’s important that the solution be as few operations as possible, and not rely on point and click. (I’m looking for something scalable to perform operations on very complex map images.)

Someone asked the same question here: https://www.reddit.com/r/Inkscape/comments/75xjfa/intersection_with_open_paths_or_equivalent/

Here’s a very simple example of the objects I’m starting with:
start

The orange area is a closed path that I want to crop to, and the black lines are a bunch of closed paths that I want to be cropped. This is what I want the result to look like:

end

The lines must be open in the final result. That is, each line is just that – a line with no fill. (Ideally, they’d keep the stroke I’ve set initially, but not required.)

It’s important that this solution applies to much more complex scenarios too. For example, I’d want to crop the lines in this example down to the purple areas:

more complex example

The images I’m working with are extremely large, and can have thousands of islands to crop out. (Point and click with a mouse to delete paths won’t work…)

I’m open to using any software available, but I’d prefer something open source / scriptable. Illustrator or Inkscape would do.

Answer

Let’s start with this… Notice that shapes used for trimming are in front of objects that need to be trimmed.
stage-1 starting situation

Select All then apply Pathfinder / Outline.
stage-2 result of Outline filter

Ungroup everything. Select any line that doesn’t have any stroke (those are the lines outside of trimming areas). Then select objects with same stroke color and delete them.
stage-3 selected objects without strokes

Now, we are left with ALMOST what we need. We should still get rid of the lines of original trimming shapes. Here I have changed the width of the strokes so it is more clear.
On the Layers palette we can see that all of these lines are on top of all others.
stage-4 selected objects on the edges

We should locate the first one that is not on the edges:
stage-5 located first object not on the edge

Now, just select (in Layers pallete, using Shift key) all above it and delete them through Layers palette.
stage-6 objects above it selected in Layers pallete

Attribution
Source : Link , Question Author : saucewaffle , Answer Author : mirjanaM

Leave a Comment