13.07.2015 Views

python-altimeter Documentation - Read the Docs

python-altimeter Documentation - Read the Docs

python-altimeter Documentation - Read the Docs

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>python</strong>-<strong>altimeter</strong> <strong>Documentation</strong>Release 0.1.1Bruno Miguel CustódioNovember 06, 2012


CONTENTSi


<strong>python</strong>-<strong>altimeter</strong> <strong>Documentation</strong>, Release 0.1.1The <strong>python</strong>-<strong>altimeter</strong> package acts as a wrapper around <strong>the</strong> Google Elevation API. From <strong>the</strong> API’s official documentation:The Elevation API provides elevation data for all locations on <strong>the</strong> surface of <strong>the</strong> earth, including depthlocations on <strong>the</strong> ocean floor (which return negative values). In those cases where Google does not possessexact elevation measurements at <strong>the</strong> precise location you request, <strong>the</strong> service will interpolate and returnan averaged value using <strong>the</strong> four nearest locations.With <strong>the</strong> Elevation API, you can develop hiking and biking applications, mobile positioning applications,or low resolution surveying applications.CONTENTS 1


<strong>python</strong>-<strong>altimeter</strong> <strong>Documentation</strong>, Release 0.1.12 CONTENTS


CHAPTERONECONTENTS1.1 QuickstartThe <strong>python</strong>-<strong>altimeter</strong> package requires one of <strong>the</strong> following versions of Python:• Python 2.6• Python 2.7• Python 3.1• Python 3.2• Python 3.3Fur<strong>the</strong>rmore, it depends on <strong>the</strong> external requests package, which gets automatically installed when following any of<strong>the</strong> below methods. However, if you’re installing <strong>python</strong>-<strong>altimeter</strong> by different means make sure you install requestsproperly:pip install requests==0.14.11.1.1 InstallingYou can use pip to install <strong>python</strong>-<strong>altimeter</strong>:pip install <strong>altimeter</strong>Alternatively, you can checkout <strong>the</strong> code or download a tarball from <strong>the</strong> repository and install it using setup.py:<strong>python</strong> setup.py install1.1.2 Testing<strong>python</strong>-<strong>altimeter</strong> comes with a full test suite. To run this test suite against your installation you can use setup.py:<strong>python</strong> setup.py test1.2 Features<strong>python</strong>-<strong>altimeter</strong> let’s you query <strong>the</strong> Google Elevation API in two different ways:3


<strong>python</strong>-<strong>altimeter</strong> <strong>Documentation</strong>, Release 0.1.1• Request elevation data for one or more points on <strong>the</strong> surface of <strong>the</strong> Earth (a positional request);• Request elevation data for a set of equidistant points sampled along <strong>the</strong> length of a path (a path request).1.2.1 Positional requestsTo make a positional request to <strong>the</strong> Google Elevation API you need to instantiate a GoogleElevationClientand call its positional method with a list of tuples representing valid coordinates:from <strong>altimeter</strong>.core import GoogleElevationClientclient=GoogleElevationClient()points=[(39.7391536, -104.9847034), (36.455556, -116.866667)]results=client.positional(points)The above commands will assign to results a list of GoogleElevationResult objects containing <strong>the</strong> resultsof your query:[, ]1.2.2 Path requestsMaking a path request to <strong>the</strong> Google Elevation API is pretty similar to making a positional request, with two subtledifferences: you must use <strong>the</strong> path method instead of positional, and you must supply as <strong>the</strong> first parameter aninteger representing <strong>the</strong> number of samples you want to obtain elevation data for:from <strong>altimeter</strong>.core import GoogleElevationClientclient=GoogleElevationClient()samples=3points=[(36.578581, -118.291994), (36.23998, -116.83171)]results=client.path(samples, points)Just as with <strong>the</strong> above example, <strong>the</strong>se commands will assign to results a list of GoogleElevationResultobjects containing <strong>the</strong> results of your query:[, ,


<strong>python</strong>-<strong>altimeter</strong> <strong>Documentation</strong>, Release 0.1.11.2.4 Request timeoutsBoth positional and path take an optional float argument, timeout, which can be used to define <strong>the</strong> amountof time (in seconds) <strong>python</strong>-<strong>altimeter</strong> should wait before giving up on establishing a connection with <strong>the</strong> GoogleElevation API. The default value for timeout is 60 seconds.from <strong>altimeter</strong>.core import GoogleElevationClientclient=GoogleElevationClient()points=[(39.7391536, -104.9847034), (36.455556, -116.866667)]results=client.positional(points, timeout=5)Please note that <strong>the</strong> value of <strong>the</strong> timeout parameter only affects <strong>the</strong> connection process itself, not <strong>the</strong> download of<strong>the</strong> results <strong>the</strong>mselves.1.3 API Reference1.3.1 GoogleElevationClientThe GoogleElevationClient object used to query <strong>the</strong> API exposes <strong>the</strong> following methods:<strong>altimeter</strong>.core.GoogleElevationClient.positional(coordinates, sensor=False, timeout=60)Requests elevation data for all <strong>the</strong> points in coordinates. coordinates must be a list containing tuples of coordinatesexpressed in decimal degrees. The sensor parameter, a boolean defaulting to False, indicates whe<strong>the</strong>r<strong>the</strong> application making <strong>the</strong> request is using a sensor (e.g., a GPS device) to determine <strong>the</strong> user’s location. Thetimeout parameter, an integer defaulting to 60, can be used to define <strong>the</strong> amount of time (in seconds) <strong>the</strong> methodshould wait before giving up on establishing a connection with <strong>the</strong> API.Returns a list of GoogleElevationResult objects containing <strong>the</strong> requested elevation data.<strong>altimeter</strong>.core.GoogleElevationClient.path(samples, coordinates, sensor=False, timeout=60)Requests elevation data for a set of samples equidistant points sampled along <strong>the</strong> length of a path defined bycoordinates. samples must be an integer greater than or equal to 2, while coordinates must be a list containingtuples of coordinates expressed in decimal degrees. The sensor parameter, a boolean defaulting to False,indicates whe<strong>the</strong>r <strong>the</strong> application making <strong>the</strong> request is using a sensor (e.g., a GPS device) to determine <strong>the</strong>user’s location. The timeout parameter, an integer defaulting to 60, can be used to define <strong>the</strong> amount of time (inseconds) <strong>the</strong> method should wait before giving up on establishing a connection with <strong>the</strong> API.Returns a list of GoogleElevationResult objects containing <strong>the</strong> requested elevation data.1.3.2 GoogleElevationResultA GoogleElevationResult object has three main attributes:<strong>altimeter</strong>.core.GoogleElevationResult.elevationA float representing <strong>the</strong> elevation (in meters) of <strong>the</strong> associated coordinates.<strong>altimeter</strong>.core.GoogleElevationResult.locationA GoogleElevationLocation object containing <strong>the</strong> location associated with <strong>the</strong> query.<strong>altimeter</strong>.core.GoogleElevationResult.resolutionA float representing <strong>the</strong> maximum distance (in meters) between data points from which <strong>the</strong> elevation was interpolated(being None if this value is not known).1.3. API Reference 5


<strong>python</strong>-<strong>altimeter</strong> <strong>Documentation</strong>, Release 0.1.11.3.3 GoogleElevationLocationA GoogleElevationLocation object has two main attributes:<strong>altimeter</strong>.core.GoogleElevationLocation.latitudeA float representing <strong>the</strong> latitude of <strong>the</strong> location associated with <strong>the</strong> query.<strong>altimeter</strong>.core.GoogleElevationLocation.longitudeA float representing <strong>the</strong> longitude of <strong>the</strong> location associated with <strong>the</strong> query.1.3.4 ExceptionsAll exceptions explicitly raised by <strong>python</strong>-<strong>altimeter</strong> derive from ei<strong>the</strong>r ValueError (used for signaling argumentvalidation errors) or <strong>altimeter</strong>.exceptions.AltimeterError (used for signaling errors in <strong>the</strong> request process).class <strong>altimeter</strong>.exceptions.AltimeterErrorActs as a base class for all errors thrown by <strong>the</strong> library. Never is it raised explicitly.class <strong>altimeter</strong>.exceptions.BadRequestErrorIndicates that a bad request has been made to <strong>the</strong> Google Elevation API. Derives from<strong>altimeter</strong>.exceptions.AltimeterError.class <strong>altimeter</strong>.exceptions.CommunicationErrorIndicates that <strong>the</strong>re has been an error while processing <strong>the</strong> request to <strong>the</strong> Google Elevation API. Derives from<strong>altimeter</strong>.exceptions.AltimeterError.class <strong>altimeter</strong>.exceptions.GoogleElevationApiErrorActs as a base class for all errors thrown by <strong>the</strong> Google Elevation API. Derives from<strong>altimeter</strong>.exceptions.AltimeterErrorclass <strong>altimeter</strong>.exceptions.InvalidRequestErrorIndicates that <strong>the</strong> request to <strong>the</strong> Google Elevation API was malformed. Derives from<strong>altimeter</strong>.exceptions.GoogleElevationApiError.class <strong>altimeter</strong>.exceptions.OverQueryLimitErrorIndicates that <strong>the</strong> requestor has exceeded quota. Derives from <strong>altimeter</strong>.exceptions.GoogleElevationApiError.class <strong>altimeter</strong>.exceptions.RequestDeniedErrorIndicates that <strong>the</strong> Google Elevation API did not complete <strong>the</strong> request. Derives from<strong>altimeter</strong>.exceptions.GoogleElevationApiError.class <strong>altimeter</strong>.exceptions.UnknownErrorIndicates an unknown error. Derives from <strong>altimeter</strong>.exceptions.GoogleElevationApiError.1.4 Changelog1.4.1 0.1.1 - 2012/11/06• Changed <strong>the</strong> package’s versioning utilities.• Corrected a few errors in <strong>the</strong> documentation.• Added integration with tox.6 Chapter 1. Contents


<strong>python</strong>-<strong>altimeter</strong> <strong>Documentation</strong>, Release 0.1.11.4.2 0.1 - 2012/11/02• Initial release.1.4. Changelog 7


<strong>python</strong>-<strong>altimeter</strong> <strong>Documentation</strong>, Release 0.1.18 Chapter 1. Contents


CHAPTERTWOCONTRIBUTINGWe’d love you to contribute to <strong>the</strong> development of <strong>python</strong>-<strong>altimeter</strong>. If you’d like to help us here are some of <strong>the</strong>things you can do:• Fork <strong>the</strong> project and submit a pull request;• Report any errors or problems on <strong>the</strong> project’s issue tracker.9

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!