Inkscape: deleting duplicate paths?


#1

This is totally defeating me. Trying to cut out a puzzle of the US states, from here. Of course, the SVG has been created from the outlines of the individual states just mashed together. I don’t want that because any shared borders get double cut.

I’ve tried combining paths (ctrl-k), and a “remove redundant paths” extension script I found attached to a bug report. Nothing appears to work. I really don’t want to go in manually and start detaching nodes on all those paths.

Any ideas?


What am I doing wrong here? Sketchup / Inkscape / Glowforge problem
#2

It’s not an answer to your question, but might be a solution to your problem: this map has the borders as their own lines, not just the outline of the states, so there’s no doubling-up of paths.

When I was doing a similar project I deleted the states (gray fill) and was left with a good set of lines for cutting borders.


#3

I’m stumped too. I took a quick look at the file. Problem is that each state shares border paths with a bunch of other states, and lots of the cases include T-intersections where you may not have a node in both paths. A couple of suggestions depending on you tolerance for waste of time vs materials:

  1. Just remove a bunch of interior states’ paths completely, and fix the rest by hand (breaking paths at a node is easy, and then you can mass-select)

  2. Move the states apart a touch and then let the double cuts happen. Cut the outside separately.

  3. would be to write something that parses the SVG and figures out which sequences of points are in fact reduntant, but I know I would screw that up, especially because you’d be looking for points in opposite orders…

Don’t know if that helps any; I’m an inkscape tyro, and maybe there is some magic.


#4

Thank you! I had looked at several others of the Wikimedia maps, but skipped over that one because I figured it would be like the others.

It doesn’t solve the problem in the general case, but for this one thing I want to do right now, it’s perfect.


#5

Also, may I say, damn Michigan and the “Delmarva peninsula” for making things difficult.


#6

My understanding is that the stroke and the fill both have an edge. You want one or the other, not both.


#7

You can use the union command or the join command. It might be tedious for all the states.


#8

I don’t think so. Tried both of those, didn’t work.


#9

It’s a little bit tedious but you need to use the node tool (second button down on the left and straight on till morning).
You can then delete all the overlapping points.
Outline mode (view->display mode->outline) makes it obvious where the lines overlap.


#10

The general case of this problem comes up again and again when I find random files and want to convert them to laser cuts. I’m frustrated that there isn’t a reliable, automated solution.


#11

I think that there just might not be a reliable automated solution. Or at least not a very clean one. Each decision about which closed path to leave alone and which one to convert to one or more open paths with endpoints (and a lot of nodes deleted) puts constraints on the next path-trimming operation, and I wouldn’t be surprised if a program had to be able to backtrack arbitrarily far. (And that’s for the “good” case where the doubled paths use exactly the same nodes – if they’re only visually the same path you have to apply tolerances to figure out what to get rid of, and that way lies a complete mess. )


#12

I gave the extension I found another shot. It’s not terrible, it works in a great number of cases. Here’s how you use it:

  1. Change your SVG output preference path string format to Absolute, rather than Relative or Optimized.
  2. Combine all the paths of interest into a single path (CTRL-k).
  3. Run the extension.
  4. Break apart and see if there are any duplicate paths left. Fix those by hand.

I also came up with an easy way to detect overlaid lines. Set your stroke outline to 2 px (or something suitably visible) and color to red. Set the opacity low, like 25. Doubled up lines will show up as a darker shade of red than single lines.


#13

I can talk to my watch and it understands what I’m saying and opens the garage door for me. Video game consoles that recognize your face and gestures are now yesterday’s technology. We live in a world where one or two people can throw something like this together. Software is pretty amazing… I suspect that a sufficiently motivated person could come up with an algorithm to find paths that are near each other and combine them.


#14

“Alexa, unlock the front door!”

I think that a group of people could build something that would get close to the results you want in many cases. But that’s not necessarily what I would call “reliable”. I’ve been a fascinated spectator on the Openscad developer forums for a while as people try to figure out how to perform geometric operations “reliably” on arbitrary imported STL files. No matter what methods or tolerances are used to figure out when points are “close enough” to be treated as being in the same place, it seems someone can always come up with an edge case that does a spectacularly wrong thing.

Expect to tweak the final result by hand as @jsc reports for that extension.


#15

It definitely IS possible, the internet says that Autocad has a tool called “Overkill” that sounds like it does exactly what is needed to fix this file, but I couldn’t find any other software with similar functionality.

SolidWorks almost has it, with its “Repair Sketch” command, but it doesn’t seem to have any options (surely it is utilizing variables, Dassault apparently choosing not to let the user edit them is really annoying). From my quick look at it, it basically automagically removes overlapping and almost overlapping lines, or it doesn’t. It also seems to give very little indication of what it’s actually done, if anything, after you execute the command.

Rhino has a tool called “SelDup”, which works perfectly (IMO) for finding lines that are exact duplicates of each other, but doesn’t seem to have any provisions for finding lines that are very close to each other but don’t quite overlap. It also doesn’t find lines that do overlap but don’t have the exact same end points - it only finds exact duplicates.

I was able to clean that file up using Inkscape to color the states (this might not have been necessary) and export a fairly high resolution PNG (I guess Rhino could have been used to do this step as well), then use Vector Magic to trace the PNG and create an SVG, then use Rhino to delete all the overlapping lines. That’s a lot of steps and software, and the vector to raster to vector conversion obviously degraded the detail.


#16

That seems almost worst lol : 500 duplicated lines. We removed 498. Have fun finding the extra 2 we weren’t sure about. :slight_smile:


#17

Seriously! Or maybe even worse yet: 501 lines. :grimacing:


#18

I messed with the SVG from the OP again, this time I tried to make the quality better than I had done before. I’m not saying it’s the most efficient possible, or the highest quality (it did get converted between vector and raster twice after-all), but it’s quite similar to the original and I don’t believe there are any overlapping lines. I also made the long border a single line, which might be good for some reason. And I removed Washington DC for some reason. Here’s the file…

Merk 1.1.zip (56.3 KB)

Source: https://www.amcharts.com/svg-maps/?map=usa (“High detail” version)

Uploaded a new file to try to be in compliance with the Creative Commons license.


#19

This is something that’s been bothering me too, and I’m sufficiently motivated to fix it. I’ll use this as a test case and see how well I can do with it.


#20

The problem with the removeredundant extension for the amcharts maps was that some paths were just ever so slightly not coincident with the ones they were overlaying. I made some changes to the code so that it would consolidate points that were within a certain distance to a previous point to that point (0.1 px on each axis considered independently, chosen because that’s what the map jitter was), and now it works perfectly on both high and low res US maps.

To use, install the extension files, then select all the paths you want to de-duplicate lines in. Run the extension. No need to combine them into a single path now.

https://bugs.launchpad.net/inkscape/+bug/521988/+attachment/4968144/+files/removeredundant.py