Is there an obvious mathematical formula to convert a lat/long coordinates into a Cardinal directions (north, south, east, west)?
0
votes
Hmm. Coordinate is a point. Direction is.. a direction (a unitary vector). Do you mean: from a fix point, having a coordinate, which direction it is such point? To have good answers: is the second point nearby or you want to handle the special cases (half Earth away)?
– Giacomo Catenazzi
I'm probably not fully understanding the concept. But I would love to turn a lat/long into a N/S/E/W position for additional data.
– Zach Smith
a sketch and an example (with real numbers, so we understand what are your expected input and outputs) may be useful to understand what you are asking.
– Giacomo Catenazzi
1 Answers
0
votes
I think you will find this example of converting lat long to include the cardinal directions to be very interesting:
#here is a code snippet from Luciano Ramalho - Pythonic Objects: idiomatic OOP in Python - #PyCon 2019
def __str__(self): ns =”NS”[self.lat <0} #boolean expression using 0 or 1, and 1 means S we =”EW”[self.long <0] return f”{abs(self.lat):.1f}{ns},{abs(self.long):.1f}{we}”
#A link to the video is here #https://youtu.be/mUu_4k6a5-I?t=2445
So the trick is to use booleans as they inherit from the in class, so your string "NS" will yield the 0 position or the 1st position because of the boolean. then the return takes the absolute value and puts the cardinal direction as a suffix. Very cool idea from Mr. Ramalho.