Following Dad on the PCT

Every evening I get an email from my dad’s SPOT Satellite Messenger letting me know his latitude and longitude along the Pacific Crest Trail (and that he’s OK). He asked me to track his mileage, so at first I put his coordinates into Google Maps, which actually has the PCT plotted, but the mileages didn’t seem to match the “official” mile markers that he’s referencing from Halfmile. They offer a KMZ file of the PCT for Google Earth, but I totally failed at getting it installed on Ubuntu. Eventually I was able to commandeer Stephanie’s Mac to get it to work, but it seemed like a hassle when all I really wanted was a quick way to enter his current latitude and longitude from the email and find out what half-mile marker he’s the closest to.

Mile 156 of the PCT on Google Earth
The PCT on Google Earth

So of course I decided to write a quick Python program! I unzipped the KMZ file to read the uncompressed 11.9MB KML file within, I figured out how to extract the half-mile waypoints and their coordinates, and I ripped a haversine equation off the web to calculate the distance between any two latitude-longitude coordinates. I didn’t bother with optimization; each time the program runs, it calculates the distance from all the waypoints (there are only 5338) to his current position, and then returns the one that’s closest. Tonight, after 8 days on the trail, it says he’s sleeping near mile 156:

./ 33.59556,-116.57129
0156 33.59643,-116.57026 0.1mi

Here’s the code for anyone who’s interested. It just requires downloading the KMZ file from Halfmile, unzipping it, and putting it in the same directory as the script. Itch, scratched.