Modules for interacting with external web services.
geocode | This module provides classes for geocoding bibliographic data. |
This module provides classes for geocoding bibliographic data.
Each geocoder class should be based on BaseCoder, and provide code and get_location methods that can be used by BaseCoder.code_this() and BaseCoder.code_list().
BaseCoder should not be used directly. Instead, instantiate a child class, e.g. GoogleCoder. For example:
>>> from tethne.services.geocode import GoogleCoder
>>> google = GoogleCoder()
>>> location = google.code_this("Marine Biological Laboratory")
>>> location
<tethne.services.geocode.Location object at 0x10153af10>
>>> location.__dict__
{'latitude': 41.5250098, 'place': u'Marine Biological Laboratory, 7 M B L Street, Woods Hole, MA 02543, USA', 'longitude': -70.6712845}
To avoid making redundant and costly requests, BaseCoder implements a rather crude cacheing system, using Pickle. Previous results are held in memory until the BaseCoder is destroyed, at which time the placename-Location mapping is pickled in the current working directory as .geocache.pickle. Disable by setting persistent to False.
sleep_interval determines the wait (in seconds) between API calls, to avoid triggering rate-limiting.
Location([place, latitude, longitude]) | Minimal geographic datum yielded by geocoders. |
BaseCoder(**kwargs) | Base class for geocoders. |
GoogleCoder(**kwargs) | Uses the Google Geocoding API, via the geopy.geocoders.GoogleV3 coder. |
YahooCoder(yahoo_id, **kwargs) | Uses the Yahoo PlaceMaker API. |
Bases: object
Base class for geocoders.
Methods
code_list(placenames) | Retrieve Location for a list of placenames. |
code_this(placename) | Retrieve a Location for a placename. |
Retrieve Location for a list of placenames.
Parameters : | placenames : list |
---|---|
Returns : | locations : dict
|
Retrieve a Location for a placename.
Parameters : | placename : str or unicode |
---|---|
Returns : | location : Location |
Bases: tethne.services.geocode.BaseCoder
Uses the Google Geocoding API, via the geopy.geocoders.GoogleV3 coder.
Methods
code(query[, bounds, region, language, ...]) | Geocode a location query. |
code_list(placenames) | Retrieve Location for a list of placenames. |
code_this(placename) | Retrieve a Location for a placename. |
get_location(response) | Yields Location based on a response from Google Geocoding API. |
Geocode a location query.
Parameters: |
|
---|
Bases: object
Minimal geographic datum yielded by geocoders.
Bases: tethne.services.geocode.BaseCoder
Uses the Yahoo PlaceMaker API.
Methods
code(name) | Constructs and sends a Yahoo PlaceMaker API query. |
code_list(placenames) | Retrieve Location for a list of placenames. |
code_this(placename) | Retrieve a Location for a placename. |
get_location(response) | Yields Location based on a response from Yahoo PlaceMaker API. |
Constructs and sends a Yahoo PlaceMaker API query.
Parameters : | name : string |
---|---|
Returns : | HTTPResponse : |
Yields Location based on a response from Yahoo PlaceMaker API.
Parameters : | response : HTTPResponse |
---|---|
Returns : | location : Location |