Combine lots of disconnected lines

General discussions about Inkscape.
monast
Posts: 8
Joined: Mon Aug 27, 2012 9:20 pm

Combine lots of disconnected lines

Postby monast » Mon Aug 27, 2012 9:39 pm

Hello everyone,

I'm facing a huge problem. I have very large svg files in which all path lines are disconnected. I know I can merge or group them together, but I would like to have them reconnected into single paths. I have marked and separated them into the paths-to-be but there are x00k lines to be connected. Is there a simple way to do this or do I have to merge one by one?
Note that there are overlapping connection points which makes it difficult to select points for joining. I will have to delete the in-between lines and establish a new connection line for simplicity. Still there's tons to do to finish one path, and there are numerous more to come.

User avatar
brynn
Posts: 10308
Joined: Wed Sep 26, 2007 4:34 pm
Location: western USA
Contact:

Re: Combine lots of disconnected lines

Postby brynn » Tue Aug 28, 2012 1:38 pm

Hi monast,
It might be fairly easy, but I'm not entirely clear about the situation. Are the endnodes that overlap, supposed to be connected? Or do some endnodes overlap segments that they aren't supposed to be connected to? You can select the overlapping nodes by using the selection box type of selection with the Node tool (click + drag until there's a dotted line box around the 2 overlapping nodes, and only those 2). Then holding Shift key, you can do the same for the next set of overlapping nodes. And so on.

If all the overlapping endnodes in the image are to be connected together, you can do Ctrl + A to select everything in the image. Then Path menu > Combine. That makes them all subpaths of a single compound path. Now when you select one segment, they are all selected. Then you can do Ctrl + A again, to select all the nodes. As long as each set of overlapping nodes are meant to be joined, you can then click "Join selected endnodes" button on Node tool control bar, and they will all be joined. Note that if the resulting path is not meant to be a closed path, you'll have to be sure to deselect the nodes which will be the new endnodes, or else they will be joined into a closed path.

If all the overlapping endnodes are not meant to be joined, could you show us a screenshot of this image, or part of it, indicating which segments need to be joined? If it's much more complicated, we might need to see the SVG file. But probably a screenshot will do.

When say you have sort of prepared the image, did the image start out as disconnected paths? If there are many, many nodes, and you have the file before they are disconnected, there might be a way to reduce the number of nodes, and thereby, the amount needing to be reconnected. But it's not clear if you have that opportunity.

monast
Posts: 8
Joined: Mon Aug 27, 2012 9:20 pm

Re: Combine lots of disconnected lines

Postby monast » Wed Aug 29, 2012 8:59 pm

Originally I converted 3D data which gave me the problem of having duplicate lines (vertical faces eg rectangle got 2 triangles giving same 3 lines in 2D). Any or all conversions create disconnected paths, even for surfaces alone.
After I separated them for each path and deleted duplicates they are all supposed to be connected into a closed path. (Having a function that recognizes duplicates would be nice too.)

Thank you very much. It worked. The only problem is some additional lines/edges have been added which are duplicates.
Image
Here I moved the edges to show the added lines.
Needless to say it would mean my paths will have thousands of those new lines added. :/

I did thought about manipulating the svg file to get rid of duplicates and or reconnect paths, but there is no simple "conversion" possible as path are differently stored compared to lines.

the original svg:

Code: Select all

<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 65535 65535" >
  <title>Export to SVG</title>
<line x1="24607" y1="31998" x2="21328" y2="31998" style="stroke:#000000; fill:None; stroke-width:10;"/>
<line x1="21328" y1="31998" x2="24631" y2="31974" style="stroke:#000000; fill:None; stroke-width:10;"/>
.
.
.
</svg>

User avatar
brynn
Posts: 10308
Joined: Wed Sep 26, 2007 4:34 pm
Location: western USA
Contact:

Re: Combine lots of disconnected lines

Postby brynn » Thu Aug 30, 2012 10:28 am

Uummm.....we may be getting a little over my head here. I'm not sure I've ever seen a "line" attribute in the Inkscape XML. It must come from the original document. So since I haven't seen it before, I'm not sure what the difference is between a line and a path. In Inkscape, it's only paths. Do you know the difference? Or can you infer from which objects are called lines and which called paths?

I'm not sure if I understand what you mean by
The only problem is some additional lines/edges have been added which are duplicates.

In your illustration, what you see in the image is on the left? But when you select with Node tool, you see extra nodes on what would otherwise be a straight segment with 2 nodes? And you've dragged them aside to show that? If I understand correctly, that could not have happened.....oh, well, I need to be more clear. No extra nodes would have been added with my instructions for joining nodes. Those nodes would have been there already, and were simply joined together.

By the way, how did you convert from 3D to 2D? I'm not familiar at all with the inner workings of 3D graphics. If you used Inkscape's Trace Bitmap, or some other trace engine, that could definitely account for those "extra" nodes. The engine tries as best as it can, but even with a simple rectangle which should have 4 nodes, the trace might still end up with 6 or 8 nodes. I don't know any way to avoid that. You could try Path menu > Simplify, which will reduce the number of nodes, but I'm afraid it would round some corners or curve straight lines.

As long as you don't have a problem with excess nodes though, I don't know why they couldn't just stay there. A problem with excess nodes would show up as a performance issue in Inkscape (despite apparently having plenty of RAM). Although I guess I don't know what your plans are for the final image. Maybe the excess nodes would be a problem that I can't imagine.

Well, as I said, we may be close to the limit of my knowledge, especially with the line attribute. Anyone else please feel free to jump in :D

monast
Posts: 8
Joined: Mon Aug 27, 2012 9:20 pm

Re: Combine lots of disconnected lines

Postby monast » Thu Aug 30, 2012 9:24 pm

The difference is a path stores the starting point and lists the relative positions of the following points. So only one real point position is stored all others have to be recalculated relative to it. Therefore, it's impossible to prepare or manipulate a purely line & point svg file into paths. You end up doing a total conversion. This problem has impact on things like rotation if you haven't noticed yet.

Code: Select all

<path
       id="line916"
       style="stroke:#000000;stroke-width:10;stroke-miterlimit:4;display:inline;fill:none"
       d="m 26399,36291 l 2514,-915 l -229,-628 l -2513,915 z"
       inkscape:connector-curvature="0"
       sodipodi:nodetypes="ccccc" />


brynn wrote:I'm not sure if I understand what you mean by
The only problem is some additional lines/edges have been added which are duplicates.

In your illustration, what you see in the image is on the left? But when you select with Node tool, you see extra nodes on what would otherwise be a straight segment with 2 nodes? And you've dragged them aside to show that? If I understand correctly, that could not have happened.....oh, well, I need to be more clear. No extra nodes would have been added with my instructions for joining nodes. Those nodes would have been there already, and were simply joined together.

Correct. But this happened with combining, then mark all & joining. I had to mark the nodes to join them again to get rid of the nodes.
Obviously duplicate nodes were no deleted or merged only connected.

brynn wrote:By the way, how did you convert from 3D to 2D? I'm not familiar at all with the inner workings of 3D graphics. If you used Inkscape's Trace Bitmap, or some other trace engine, that could definitely account for those "extra" nodes. The engine tries as best as it can, but even with a simple rectangle which should have 4 nodes, the trace might still end up with 6 or 8 nodes. I don't know any way to avoid that. You could try Path menu > Simplify, which will reduce the number of nodes, but I'm afraid it would round some corners or curve straight lines.

This is a solution I choose because 3D DWG print can have extra obstructive details, and vector graphics can do smoother curves. Also there's a problem of print sizes. I used Total CAD Converter, others give the similar results so it doesn't really matter which program is used.
Well, I didn't use trace because that's what I expect to happen. I know it's a difficult topic but sometime it looks like tracing programs don't actually use structure recognition. But I dunno if old wavelet algorithm and such structure recognition technologies are any good for this either.

Well, the extra nodes aren't a problem visually, but as is I would expect to have several thousand duplicates left in large outline paths. I'm going to use standard object paths so those will be fixed. Then build up everything else based on them with custom adjustments. I would guess I will end up with several million lines. This way it's a bit faster than rejoining all the 3D objects. *shrugs*

User avatar
druban
Posts: 1867
Joined: Fri Nov 20, 2009 10:48 pm

Re: Combine lots of disconnected lines

Postby druban » Fri Aug 31, 2012 1:50 am

monast wrote:The difference is a path stores the starting point and lists the relative positions of the following points... This problem has impact on things like rotation if you haven't noticed yet.

I am not sure if this will help you, but Inkscape has a preference checkbox for "allow relative coordinates". it's under SVG output. To get the program to rewrite all the path data you will have to move the path (move it back afterwards and it will write it again...). I use arrow up and arrow down, but in your case there maybe a long wait in between. I am nor sure how the preference works; to be absolutely sure I would uncheck this box, close Inkscape and then reopen it. Usually the prefs that need a restart of the program say so, but it seems an okay precaution to take.
Please note that your paths cannot be in a group or Inkscape will create a transform attribute for the group instead. Ungroup all groups if your work will allow it.

About the extra nodes - while the simplify command will change the path shape and is not appropriate for precision work, the union operation will get rid of overlapping nodes with no change to the path. (This is a one-shot operation; repeating will have absolutely no benefit). Be aware it will join overlapping paths. if all your objects are separated from each other this will not affect you. Try it on a few selected objects first to see what improvement you get, if any. In fact it will work on a single object so you can see (from the info bar if you are in selector tool mode) exactly how many nodes have been eliminated.
Caution:unclosed paths that don't touch another path will be left untouched if they are a straight line segment and will be closed if they are any other open shape. Line segments that intersect will disappear so if you have any objects that are made up of unconnected line segments they need to be joined first.
Attachments
rect4037.png
Before and after Union operation
rect4037.png (8.42 KiB) Viewed 7176 times
Your mind is what you think it is.

User avatar
brynn
Posts: 10308
Joined: Wed Sep 26, 2007 4:34 pm
Location: western USA
Contact:

Re: Combine lots of disconnected lines

Postby brynn » Fri Aug 31, 2012 10:28 am

Except for druban's suggestion to use Union to get rid of overlapping line/paths, which is brilliant btw, the rest of the discussion has officially gone over my head. Perhaps ~suv, or someone with adequate knowledge, might address your technical comments re line vs path, trace vs CAD converter, etc., if you need them addressed.

~suv
Posts: 2272
Joined: Sun May 10, 2009 2:07 am

Re: Combine lots of disconnected lines

Postby ~suv » Fri Aug 31, 2012 5:42 pm

monast wrote:Therefore, it's impossible to prepare or manipulate a purely line & point svg file into paths.

This is not true - both SVG 1.1 (and Inkscape) allow to define 'd' path data with relative or absolute path commands.

Maybe you could attach (or share otherwise) a sample file (SVG) with a small portion of the huge ones you are dealing with - this would allow others to investigate and possibly provide tips based on actual test data.

monast
Posts: 8
Joined: Mon Aug 27, 2012 9:20 pm

Re: Combine lots of disconnected lines

Postby monast » Sat Sep 01, 2012 7:37 am

Thank you for the suggestion, druban.
After trying back and forth there is no difference as it doesn't get that far... The union command for some reason deletes all lines involved with or without "allow relative coordinates". Nothing is left for marking.

Despite any flaw of functions, getting rid of the majority of problems is good enough for me. Tackling the minor ones left is easier or less time consuming.

~suv wrote:
monast wrote:Therefore, it's impossible to prepare or manipulate a purely line & point svg file into paths.

This is not true - both SVG 1.1 (and Inkscape) allow to define 'd' path data with relative or absolute path commands.

Maybe you could attach (or share otherwise) a sample file (SVG) with a small portion of the huge ones you are dealing with - this would allow others to investigate and possibly provide tips based on actual test data.

Well, it still requires excessive editing/manipulation; can as well do it manually.
Attached a simple path in two original conversion versions: 1. being a volume conversion 2. being a surface conversion
So you can see some visual "difference" and problems of 3D to 2D. The files themselves are technically not different in how they are made up.
Since the raw files don't contain line attributes you need to Ctr + A mark all lines, and using the object editor to set the line width to 10.0 for them to become visible. I recommend 1% zoom.

I have thought up two ways of getting rid of duplicate lines:
1. Converting to html and using a link grabber program to sort out the line tags.
2. Converting to text list and using "Create Multiple Files From Text File List" program to create and sort out duplicates. List size may be too big and need to be divided into smaller lists. Also this needs to be done in empty folders. After getting rid of duplicates just use a Dos terminal and print out a text file with "dir /b>newlist.svg". Complete it with the missing tags and it's done.
Attachments
send.zip
(3.59 KiB) Downloaded 189 times


Return to “General Discussions”

Who is online

Users browsing this forum: No registered users and 3 guests