[GIS] Snap existing line vertexes to nearest line in MapInfo

mapinfosmoothingsnapping

I have driven along some roads and registered some information about the state of the edge of the road. The GPS coordinates are not very precise, and I would like to smooth or snap the tracked lines to the actually edges of the road.
All data is registered driving at the right direction in the right side of the road. I have three layers with data.

  1. Red layer is the edges of the road.
  2. Blue layer is the center lines of the road.
  3. Green layers is the tracks registered by the GPS with some attributes about the state of the side of the road. Look at the image at the bottom.

I have many of these and would like to automatically smooth or snap the points of the green lines to the right side of the road, to make them follow the red line.

How can I do that using MapInfo?

Just some mathematical description how to solve it would be nice. I am not asking for a full MapBasic script that solves it.

My initial thought is to find the nearest red line to a chosen green line. For each vertex in the green line get a vector to the nearest point on a red line segment and move the vertex by this vector. But I can see the GPS is sometimes very unstable and the green line is on the wrong side of the center line. In some way I need to find the nearest red line to the "right" of the blue center line and move the vertices to this.

I put some white arrows on the image to illustrate where to move the green lines to.

Perhaps a totally different way can be used?

Map with vector data

Best Answer

Here are some ideas:

  1. Convert your green polygons into points where each node will be a point in a new table referring back to the original record and the node number.

  2. Use the Distance Calculator to calculate the two shortest distances between the "green" points and the red lines

  3. Use a query to find all the distance lines that intersect a green line with an ID different than the original ID. They seem to cross another green line to get to a red line. You don't want to use these. Delete those that were found.

  4. For each of the green lines, select the distance lines sort them by node and distance.

  5. For each of the sorted distance lines, get the Node ID, if you already have looked at this node ID ignore it, move the matching node of the current green line to the end point of the distance line and finally save back the edited green line to the current record in the green line table.

You might want to build in some extra validations too. Maybe check that the distance you are moving is less than a certain distance.