I need to sort the coordinate list for the rectangle counterclockwise and make the northeast corner the first coordinate. These are geographic coordinates (i.e. Longitude, Latitude) in decimal form. one
For example, here are 4 corners of a rectangle, starting from the northwest corner and moving clockwise:
[ { "lat": 34.495239, "lng": -118.127747 }, # north-west { "lat": 34.495239, "lng": -117.147217 }, # north-east { "lat": 34.095174, "lng": -117.147217 }, # south-east { "lat": 34.095174, "lng": -118.127747 } # south-west ]
I need to sort them counterclockwise and change the anchor / starting point to the northeast:
[ { "lat": 34.495239, "lng": -117.147217 }, # north-east { "lat": 34.495239, "lng": -118.127747 }, # north-west { "lat": 34.095174, "lng": -118.127747 }, # south-west { "lat": 34.095174, "lng": -117.147217 } # south-east ]
I do not know what order the list will have initially (i.e. clockwise or counterclockwise). I do not know in which corner the first coordinate in the list will be displayed.
1 This is not a real rectangle when displayed on the surface of the earth, however, since I have 2 opposite angles, I call it a rectangle for readability. Forms that wrap + 180 / -180 longitude or + 90 / -90 latitude are not a problem.
python sorting algorithm coordinates geospatial
Crescent fresh
source share