The last time I posted a post "know a little about recent points (ask questions)", I will discuss this issue further today. Last time, it was implemented based on the MapX control. Today, it is implemented based on text files instead of MapX.
Problem Review: if the point P (latitude and longitude) is known, the nearest vertex D (point, line, and surface) is found. The name of D is returned, and the direction, position, and distance between D and P are returned, the total number of features is greater than 0.5 million.
Current functions: generate a vertex to judge the coordinates, distance, and direction of the vertex closest to the vertex; generate a vertex and generate a line segment, determine the shortest distance from a point to a straight line (whether or not the vertical foot falls on the line segment ).
The general idea is to find the nearest vertex and traverse it. Find the closest point on the line segment, first judge the vertical foot, here is the product of the slope of the two vertical lines is-1, then judge whether the vertical foot falls on the line segment, that is, to determine whether the vertical foot is the smallest range rectangular frame of the online segment. If the vertical foot falls on the line segment, the shortest distance is the distance from the point to the vertical foot. If not, the shortest distance is the distance from the closest endpoint of the line segment.
Found OriginalAlgorithmThe problem is a mathematical problem. I am not good at mathematics. Alas, a simple problem has taken me quite a long time. None of the above optimizations were made, and the Earth coordinates were treated as Cartesian coordinates (a bit inappropriate, but I think this error may be acceptable when the speed is given priority ), if you think there are any optimizations, you are welcome to raise them. For example, when traversing, you should first determine whether the rectangle is located at a fixed distance near a known point.
Code: Http://files.cnblogs.com/Tangf/neardis_new.rar
The interface is shown as follows: