Reputation: 2326
Currently in the process of implementing a service call the fetches some (Lat, lng) pairs from the DB and then process them to determine a definitive order so that the points are arranged in a way so that if I start with a pencil from first point and go through the ordered points I end up drawing a closed polygon with N sides.
To make it more clear consider the (Lat, Lng) pairs as below:
(42.45, -73), (34, -78), (42.78, -72.45), (42.98, -72.56)..and so on..
What I could think of was like if we determine four points:
(topLeft)
(bottomLeft)
(bottomRight)
then we may start drawing the first line like (topLeft)--->(bottomLeft) and as there will be many points that fall in the line so we go through scanning them on the way to (bottomLeft) and so on...
The criteria for topLeft may be like (min(lat), max(lng)) out of all the (lat, lng) pairs.
Please advice if the above Algorithm is a way to accomplish the task or there are better ways to do the same?
Note:- Using Java.
Upvotes: 1
Views: 200
Reputation: 5034
I'd do it by
Just be VERY careful if the points can span the date line (180 degrees longitude)
Upvotes: 1