Last night I was reading through Hello World!, an introductory programming book loaned to me by a coworker, and decided to give Python a crack. Here’s my first attempt. Just paste it into a text editor and save as ‘lat2dms.py’. Then run it in IDLE GUI (free download) with F5. If you type lat2dms(###) in IDLE it will convert the decimal degree value ‘###’ to degree-minute-second format (four outputs, including N/S to indicate direction). I originally wrote it to output a concatenated string of those values but couldn’t figure out how to include the degree, minute, or second symbols (eg ‘ and ”). My ultimate goal is to use this as a building block for a script that will import a CSV file with geodata in one format and output a new CSV file with the same data in a different format, suitable to be used with Excel or any compatible geographic information system. I’m about halfway through the loops chapter, so hopefully that will come in handy. This has been a fun exercise and I hope I can continue learning on the side.
#this is a program to convert a decimal latitude value into degrees minutes seconds format
#by Will Townes 25 AUG. 2009
#this conditional defines whether the lat. is north or south
direction = 'North'
direction = 'South'
ilat = abs(ilat)
#here we parse the initial, decimal value into degrees minutes and seconds.
degrees = int(ilat)
rawminutes = 60*(ilat-degrees)
minutes = int(rawminutes)
seconds = int(60*(rawminutes-minutes))
if ilat > 90:
print "ERROR- invalid latitude value. Please enter a value between -90 and 90."
print "(degrees, minutes, seconds, direction)"
return degrees, minutes, seconds, direction
21 March 2008. (click here for photos) After finishing my Fulbright period in the Philippines, I spent a month independently traveling around Southeast Asia. My first stop was Hong Kong, where I visited my friend Sonia Siu, who was a Rotary Scholar at Hong Kong University studying their welfare system. My first impression was delight at the efficiency of the train I took from the airport to Central station on Hong Kong Island, and the glistening, modern shopping mall with a free (!) internet cafe in the International Financial Center above the terminus. I later discovered, however, that this was the most expensive possible way I could have taken! I wandered the Blade Runner-esque streets toward Lan Kwai Fong, the popular expatriate hang-out, where I met Sonia and grabbed a cab to HKU. When I mentioned that I had just arrived from the Philippines, I was taken aback when the driver reacted by expressing his fear of “dangerous” Muslims in that country. The next day the air was foggy, and somewhat polluted (from the vast number of factories in nearby Guangdong, China). We joined several local rotarians for a dimsum (dumpling) breakfast that included eel, squid, chicken feet, lotus paste, and many other tasty but unidentifiable Cantonese delicacies. Having consumed a massive amount of green tea, and minimal water to dilute it, my head was spinning! I spent the day riding around on the almost century old trolleys and memorizing Chinese characters. I enjoyed identifying some of the plants in the Conservatory in the Hong Kong Park, and randomly made the acquaintance of an amicable business school professor from Brigham Young University, who cautioned that not all finance professionals strike it rich. In the shadow of the Citigroup tower, an Indian man accosted me. Brandishing a picture of his (apparently levitating) guru, he offered to predict my future. Without waiting for my reply, he did so and immediately offered a chart of how I might repay him (in American or Hong Kong dollars, of course!). When I explained I had no cash, he stormed away angrily. Hong Kong also has an abundance of Filipino workers, many of them house maids. I chuckled upon observing, at city hall, signs in English, Chinese, AND TAGALOG warning would-be picnickers to stay off the grass!
The next day, Letitia, a couchsurfing host and nurse, was gracious enough to take me on the tram ride to Victoria Peak, a promontory behind the city in the center of Hong Kong Island. From the top, we gained an excellent vista of Kowloon and the many ships traversing the narrow strait between that peninsula and our island. As we hiked through the surprisingly lush vegetation down the back (Southwest) side of the mountain. Letitia related her experience working in the hospital during the deadly SARS outbreak, which even claimed the lives of some of her colleagues. The virus apparently came to Hong Kong by a man infected in Guangdong while hunting wild game. In the distance, we could see a large coal fired power plant on a smaller adjacent island, a power source for the bustling metropolis of 7 million people. Later, Letitia introduced me to a crunchy, spicy local variety of seafood, and congee, a creamy rice porridge that reminded me of grits.
Another interesting experience was joining Sonia’s rotary colleague Brad and others for an Indian meal in the menacingly labyrinthine Chungking Mansions on Kowloon. Brad explained that, while widely acknowledged as the most affordable place to live in the city, it had a history of fires and crime. Most of the residents appeared to be import/export businesspeople from South Asia, the Middle East, and Africa. I was disoriented when I arrived, because I had just caught the last sky tram down to Tung Chung after climbing Lantau Peak (second highest in Hong Kong) earlier that day. Overall, I thoroughly enjoyed Hong Kong and would love to go back. It’s hard to imagine any other cosmopolitan city (it really is the “New York of Asia”) with so much natural beauty in close proximity. On my final day, I rode the ferry to Macau (home of the world’s largest casino, and a former Portuguese colony!) and spent the night in a hostel owned by a Bangladeshi man next to two Chinese Malaysians and a Filipina. As I closed my eyes I knew that I would have colorful dreams after living in such a fascinating, heterogeneous microcosm for a brief but exhilarating five days.