Steven P Posted Sunday at 12:40 PM Posted Sunday at 12:40 PM 1 hour ago, SLW210 said: For AutoCAD, it helps if BOTH polylines go the same direction. I think Lee Mac had something to work out polyline direction, so should be able to check and reverse a polyline if necessary. Reverse back again after Quote
PGia Posted Sunday at 03:37 PM Author Posted Sunday at 03:37 PM 4 hours ago, SLW210 said: From what I have gathered, no easy task to do this, many GIS programs seem to struggle with pinpoint accuracy as well. The method for QGIS, is involved, so I didn't get time to run through it with the plugin, but I did dig into reddit and some GIS sites. Basically they do similar method, they just add a lot of points down the "polyline/line" and run the appropriate "centerline tool". Where someone posted results, I saw some in some of them the same "off center through some areas" as in the methods posted here. This was apparently plenty good enough for most GIS users, though I only did a relatively quick dig. In a similar method for AutoCAD, maybe adding more points to the polylines would help. I might have time Monday at home to check QGIS. Though I did import the OPs drawings into a session, the first one comes in very strange, the second seemed to be correct. The OP still hasn't answered why the second .dwg posted comes up as not an AutoCAD drawing. For AutoCAD, it helps if BOTH polylines go the same direction. I’m sorry. I didn’t think this was important — but maybe I was wrong. I usually copy drawings from my PC to edit them on my smartphone. The app I use on my smartphone is DWG FastView. I don’t remember where I sent it from, but if that message appeared when opening it, it must be because I saved the drawing on my smartphone for some reason and sent it from there. Quote
BIGAL Posted Monday at 02:48 AM Posted Monday at 02:48 AM "Plines in same direction", Yes Lee-Mac has a method also. Note the use of Pedit as Bricscad does not have a "Reverse" command, as at V25. ; Checking if pline is CW or CCW and set to CCW ; Orignal idea by Kent Cooper, 1 August 2018 Offsetinorout.lsp ; By Alan H July 2020 (defun AH:chkcwccw (ent / objnew area1 area2 obj minpoint maxpoint) (setq obj (vlax-ename->vla-object ent)) (vla-GetBoundingBox obj 'minpoint 'maxpoint) (setq pointmin (vlax-safearray->list minpoint)) (setq pointmax (vlax-safearray->list maxpoint)) (setq dist (/ (distance pointmin pointmax) 20.0)) (vla-offset obj dist) (setq objnew (vlax-ename->vla-object (entlast))) (setq area1 (vlax-get objnew 'Area)) (vla-delete objnew) (vla-offset obj (- dist)) (setq objnew (vlax-ename->vla-object (entlast))) (setq area2 (vlax-get objnew 'Area)) (vla-delete objnew) (if (> area1 area2) (command "Pedit" ent "R" "") ) (princ) ) (defun c:CWCCW ( / *error* x ent oldsnap doc ss) (setq doc (vla-get-activedocument (vlax-get-acad-object))) (vla-startundomark doc) (setq oldsnap (getvar 'osmode)) (setvar 'osmode 0) (prompt (strcat "\nSelect Plines to check")) (if (setq ss (ssget '((0 . "*POLYLINE")))) (progn (repeat (setq x (sslength ss)) (setq ent (ssname ss (setq x (- x 1)))) (AH:chkcwccw ent) ) ) ) (vla-endundomark doc) (alert (strcat (rtos y 2 0) " Plines reversed")) (setvar 'osmode oldsnap) (princ) ) (vl-load-com) (prompt "\nType CWCCW to set plines to CCW") (c:CWCCW) 1 Quote
SLW210 Posted Monday at 07:09 PM Posted Monday at 07:09 PM On 11/6/2025 at 9:56 AM, PGia said: I suppose a method based on calculating many points helps to average out those errors, but the result can only be an approximation. And IMO, the result shouldn’t be an approximation — it should be exact. There lies the main issue with this, the last sentence is actually incorrect. Unless you have 2 exactly parallel lines/polylines the result is always going to be an approximation, the less different the better, but still just an approximation, even if you compare every conceivable point, if they are different lengths it's odd man out. If it's a very complicated pair of lines, you would need a lot of points to calculate, hence very slow. Jeffery P Sanders Rolling_Ball.lsp appears to get pretty close. This issue comes up all the time, just go to anything related to Civil 3D, GIS, etc. Example https://discourse.mcneel.com/t/finding-the-average-curve-between-two-curves/149668 If you want some unattainable perfection, I suggest you invest in modern software. Quote
SLW210 Posted Tuesday at 12:27 PM Posted Tuesday at 12:27 PM I'll try to see how QGIS works if I get any CAD time at home, I started yesterday on it, but I had the latest with QT6 experimental downloaded and the plug-in for centerlines need the non-QT6 version, so spent the time removing and installing the correct version. So, if anybody was interested, be sure to download a version that the plug-in will work with. I also found more information on how the GIS folk tackle this issue and some new Plug-Ins to try for QGIS. Finding centrelines from polygons in QGIS - Geographic Information Systems Stack Exchange line - Creating centerline of river in QGIS? - Geographic Information Systems Stack Exchange HCMGIS — QGIS Python Plugins Repository Geo Simplification (processing) — QGIS Python Plugins Repository Voronoi diagram - Wikipedia Even better, just get the proper tool for the job. Probably less hoops to jump through for ArcGIS Pro, you can utilize the Polygon To Centerline tool. I'll try to remember to check with my daughter what she uses at work. Quote
PGia Posted yesterday at 02:00 AM Author Posted yesterday at 02:00 AM I assume there are complex cases where determining a centerline that’s perfectly equidistant from both edges can be quite challenging. However, I don’t think the examples we’ve discussed in this thread fall into that category. I guess I can live without a perfectly accurate solution. My question was more of a spontaneous one — I thought it might be feasible to achieve in less demanding cases. In any case, the subject is really interesting and seems to be turning into a bit of a trending topic. Quote
SLW210 Posted yesterday at 12:07 PM Posted yesterday at 12:07 PM Speaking of @marko_ribar here is some of his work at the SWAMP. To AutoCAD yours are complicated, if you would pay attention to what's been posted they all get off center in pretty much the same areas, sharp curves that get very wide and very narrow. The inside is shorter than the outside and the reference points differ in number. I posted links to Civil/GIS forums where lots of different software struggle with this. You'll probably have to be satisfied with Gian's solution. If I have time I "might" work on a [send points to Excel/CSV and bring them back in solution], though IMO, I like the QGIS solution or Python might be a way to go for more accuracy. What type of work are you doing? What you have posted looks to be Civil and/or GIS work. Why don't you have the proper programs for this type of work? Quote
Danielm103 Posted yesterday at 01:19 PM Posted yesterday at 01:19 PM Apparently, it’s a difficult task, people write papers on them https://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=8625416 1 Quote
dexus Posted 7 hours ago Posted 7 hours ago (edited) Using a voronoi diagram (code by ymg, ElpanovEvgeniy and Marko Ribar) You can get some very good reference points. Just have to find a way to get rid of all the 'branches' and then take al the midpoints of every line to get a good centerline. centerline-voronoi.lsp Edited 7 hours ago by dexus 3 Quote
dexus Posted 5 hours ago Posted 5 hours ago I copied another function of dijkstra's algorithm to find the shortest path. It might need a lot of optimization, but just as a proof of concept. centerline voronoi dijkstra.lsp 3 Quote
GLAVCVS Posted 4 hours ago Posted 4 hours ago 1 hour ago, dexus said: I copied another function of dijkstra's algorithm to find the shortest path. It might need a lot of optimization, but just as a proof of concept. centerline voronoi dijkstra.lsp 13.7 kB · 2 downloads Is it possible that your attached code is incomplete? Quote
dexus Posted 3 hours ago Posted 3 hours ago Does it not create a polyline for you? I did post it without the 'animation' if that is what you mean. Quote
SLW210 Posted 3 hours ago Posted 3 hours ago 22 hours ago, Danielm103 said: Apparently, it’s a difficult task, people write papers on them https://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=8625416 I have been trying to explain the issues to the OP to no avail. From what I gather from my daughter, her coworker does the centerlines in CAD not ArcGIS, then imports them. From what I gather, CAD is better for tweaking a more accurate line manually after running a LISP or other program. Which is apparently what some if not most of the surveyors, geologist, map/civil, etc. are doing no matter the GIS software or CAD software. Getting it close with a tool then tweaking it if needed, or probably if just a one time deal completely manually. I have a couple of new LISPs, I left one of them to draw a different centerline depending on which polyline is picked first, between the two centerlines, one goes close to perfect through the right curves, the other close to perfect through the left curves on the OPs AxisExample.dwg. As I posted, a Voronoi is what most of the tools use, apparently they can get off center as well, but generally work the best. The other option is to go LRM's method or along the lines of Jeffery P. Sanders rolling ball, but the rolling ball can take a while it seems to if looking for accuracy. Daniel's Python method would probably be the best IMO. I still plan on seeing QGIS results when I get the time. Quote
GLAVCVS Posted 3 hours ago Posted 3 hours ago 42 minutes ago, dexus said: Does it not create a polyline for you? I did post it without the 'animation' if that is what you mean. The "removeDuplicates" function is missing. Quote
mhupp Posted 2 hours ago Posted 2 hours ago (edited) 4 hours ago, dexus said: Just have to find a way to get rid of all the 'branches' I think ronjonp posted something that if you clicked two points on a polyline it would find the shortest path. (traveling salesman) The method I was working on but haven't finished. two open polylines find start and end points of each test how they are oriented and revers one to use to make a closed polyline find the longest distance between the two original polyline divide that by like 500 and offset in using entlast and eventually will end (cant offset anymore) find the polyline with the lowest area but still has the same amount of vertex as the original boundary. using that smaller boundary to draw vector lines between smallest and original boundary. (where im at now) take all other polylines inside smallest and add them to a point list. remove any points that are Collinear with any of the drawn vector lines. this should leave only the points on the center line. starting at one end need to start group points that are Collinear to each other. of those points entmake a line on the farthest distance. these lines are incomplete segments or might not be touching and will need to be extended to each other or the vector lines or both. problem i am finding/trying to solve what slw210 pointed out about if two segments are close to being parallel points wont be found. need three points to calculate collinear working over a group of points to split out each segment. Edited 2 hours ago by mhupp 1 Quote
GLAVCVS Posted 2 hours ago Posted 2 hours ago Everything SLW210 has researched is very interesting. I had no idea this had been such a thoroughly discussed topic — and with such limited success. I guess that makes it even more interesting. In my opinion, it is possible to obtain a center polyline that is equidistant from both edges. But two conditions must be met: 1. The user must ensure that the geometry of both edges is correct: they must be 2D polylines with no repeated points and no geometric inconsistencies of any kind. And, in principle, to avoid extending the search for a solution, these polylines should not contain arcs. 2. One must accept that any edge containing “recesses” (“recodos”) must be handled using auxiliary axes. What is a recess? It is a geometric setback, in any direction, along one of the edges. For example: if you advance segment by segment along an edge (in either direction), the start of a recess would be defined as any vertex from which the shortest distance to the opposite edge forces the projection to intersect its own edge. My conclusion: for edges without recesses, I believe it is possible to find an equidistant centerline or axis. And for edges with recesses, although considerably more code will be needed, they should be solvable using auxiliary axes. I hope to have code soon that supports all of this. 1 Quote
SLW210 Posted 1 hour ago Posted 1 hour ago @Marko Ribar has a Travelling Salesman here at CADTutor. TSP.ZIP (Travelling Salesman Problem) - AutoLISP - Programs and Scripts - AutoCAD Forums I was just thinking of the relationship of this to the Travelling Salesman. One of the examples I ran across was similar to @GLAVCVS recess example, as well as the problem of a river that splits around an island or branches ( even a road, ROW, etc.). Even GIS tools need pre and post work and have conditions... Polygon To Centerline (Topographic Production)—ArcGIS Pro | Documentation I think I see why my daughters coworkers use CAD to do the center lines, I am guessing as haven't heard back on details, but I wouldn't be surprised if they used Gian's LISP or similar or just do manually like lrm's demonstration. I also saw an example of that on Bentley MicroStation forums. You may have seen a recurring tool on the GIS forums, etc. called v.centerline. v.centerline - GRASS GIS manual -A link to the source code is at the bottom. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.