Inkscape: deleting duplicate paths?

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.

2 Likes

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

5 Likes

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

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

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

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.

3 Likes

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.

2 Likes

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. )

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.

11 Likes

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.

3 Likes

“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.

2 Likes

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.

1 Like

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

4 Likes

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

2 Likes

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.

1 Like

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.

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

4 Likes

Just update Inkscape to version 0.92.3 . Although the inx and py files for removeredundant are in the extensions file, it no longer shows up in Extensions -> Modify Path .

Has anyone else had this problem?
Suggestions?

After two re-boots, removeredundant is now wotking on Windows 7 machine, Inkscape version 0.92.3.

It is not clear why things started working. But YEAH!