Home - General / All posts - Closest point on a line
 sga30 post(s) #28-Mar-23 09:47 Hi all,In M9, I have a drawing with points and another with lines. For each point, I want to find the the closest point on the line. In other words, I'd like to snap the points to the lines. The GeomDistance tells me the distance to the closest line but does not return the point. I read somewhere in this forum (https://georeference.org/forum/t160399.6#160419) that we could normalize both layers at the same time, but then either the point or the line might be moved, which is problematic to me, since I only want to change points position.Our approach was then to draw a circle with the distance from GeomDistance as the radius and get the intersection between the line and the circle. The problem is that circles in manifold are not exact circles and sometimes the intesection returns nothing. We then added a tolerance of 1/1000 of the distance to make sure that the circle does indeed cross the line. However, we are left with two intersecting points. For our application, any of the two points is sufficiently accurate and we only consider the first point. A more accurate approach would be to calculate the middle point between the two points of the intersection.This technique does take some time when applied to hundreds of thousands of points, whereas GeomDistance itself is very fast. Is there a faster approach to get the point geometry we are looking for? It seems to me that the geometry of the nearest point should be calculated (as temporary result) when calling the GeomDistance function. Would it be possible (and would it make sense) to have a function similar to GeomDistance that would return the geometry of the nearest point?Any thoughts on the problem is welcome.
 geozap  264 post(s) #28-Mar-23 13:37 In case it helps, there has been a discussion for M8.https://georeference.org/forum/t133743.14#133744
 sga30 post(s) #29-Mar-23 06:10 Thank you very much geozap!I actually was aware of this technique, yet the circle solution, while beeing less accurate, is more rapid. Even though, I'd like to speed it up a little if possible
 Sloots      666 post(s) #30-Mar-23 13:09 Hi sga,I have developed an add-in for these kind of tasks.I took 23 seconds to snap 25k points to 6k lines (or 28k if splitted into segments).See the images below. If you are interested, send me an email. (info at mppng dot nl)Before: After: http://www.mppng.nl/manifold/pointlabeler