|
Written by Gordon Tillman
|
|
Monday, 08 December 2008 22:51 |
|
geopy is a really cool Python module that is hosted on Google code. Makes it dead easy to do geocoding from your Python program.
Installation
When possible I just like to check out a copy of a project from its repository. This makes it quite easy to update it in the future. The geopy project keeps its code in a subversion repository.
$ mkdir -p ~/projects
$ svn checkout http://geopy.googlecode.com/svn/trunk/ ~/projects/geopy
$ cd !$
$ sudo python setup.py install
Geopy supports many different geocoding services. I decided to test using the Yahoo! Maps Web Services. I logged into their site and generated an application ID, and then did this very simple test:
$ python
>>> app_id="put_your_yahoo_application_id_here"
>>> from geopy.geocoders import yahoo
>>> y = yahoo.Yahoo(app_id)
>>> l = y.geocode_one("1600 Pennsylvania Avenue NW Washington, DC 20500")
Fetching http://api.local.yahoo.com/MapsService/V1/geocode?output=xml&\
location=1600+Pennsylvania+Avenue+NW+Washington%2C+DC+20500&\
appid=G5cBqBnV34GeLlNVvyHnmeJP7HdMHQs0DKepEHQrQIA7gTyA022oOjfLwnKJiVyS7_9EQyA-...
>>> print l
Location(u'1600 Pennsylvania Ave NW, Washington, DC 20006, US', \
Point(38.898589999999999, -77.035971000000004, 0.0))
How easy is that? |
|
Last Updated on Monday, 08 December 2008 23:17 |