From da915dbb7184db792e3926d38fe70128a09034d6 Mon Sep 17 00:00:00 2001 From: ijl Date: Thu, 24 Oct 2013 21:16:29 -0400 Subject: [PATCH] Sphinx docs --- .gitignore | 1 + Makefile | 5 + RELEASES | 4 +- docs/Makefile | 177 ++++++++++++++++++++ docs/conf.py | 266 +++++++++++++++++++++++++++++++ docs/index.rst | 55 +++++++ geopy/__init__.py | 34 +++- geopy/compat.py | 11 -- geopy/geocoders/bing.py | 22 ++- geopy/geocoders/dot_us.py | 8 + geopy/geocoders/geonames.py | 8 + geopy/geocoders/googlev3.py | 34 +--- geopy/geocoders/mapquest.py | 8 + geopy/geocoders/openmapquest.py | 13 +- geopy/geocoders/placefinder.py | 30 +++- geopy/geocoders/smartystreets.py | 5 + geopy/geocoders/wiki_gis.py | 12 +- geopy/point.py | 66 +++++--- 18 files changed, 678 insertions(+), 81 deletions(-) create mode 100644 docs/Makefile create mode 100644 docs/conf.py create mode 100644 docs/index.rst diff --git a/.gitignore b/.gitignore index f26b27138..ebf2a4734 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ build dist *.egg *.egg-info +docs/_build diff --git a/Makefile b/Makefile index cc6e706a2..ddae82ed3 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ .PHONY: lint .PHONY: test .PHONY: clean +.PHONY: docs develop: virtualenv .venv --distribute @@ -14,3 +15,7 @@ test: clean: find . -name "*.pyc" -print0 | xargs -0 rm -rf + +docs: + touch docs/_build/html/index.rst + cd docs && make html diff --git a/RELEASES b/RELEASES index f4e7a4583..78732eff9 100644 --- a/RELEASES +++ b/RELEASES @@ -1,8 +1,6 @@ 0.96dev ========== -REMOVED: Google V2 geocoder has been removed. Please use the Google V3 - geocoder instead. ADDED: SmartyStreets LiveAddress geocoder implemented. Contributed by Michael Whatcott. @@ -31,6 +29,8 @@ FIXED: `format_degrees` now rounds minutes properly. Contributed by avdd. FIXED: No longer warn if the optional dependency `BeautifulSoup` is not present. +REMOVED: Google V2 geocoder has been removed as its API was shutdown. + 0.95.1 - March 22, 2013 ========== diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 000000000..1a1756616 --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,177 @@ +# Makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +PAPER = +BUILDDIR = _build + +# User-friendly check for sphinx-build +ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) +$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) +endif + +# Internal variables. +PAPEROPT_a4 = -D latex_paper_size=a4 +PAPEROPT_letter = -D latex_paper_size=letter +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . +# the i18n builder cannot share the environment and doctrees with the others +I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . + +.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext + +help: + @echo "Please use \`make ' where is one of" + @echo " html to make standalone HTML files" + @echo " dirhtml to make HTML files named index.html in directories" + @echo " singlehtml to make a single large HTML file" + @echo " pickle to make pickle files" + @echo " json to make JSON files" + @echo " htmlhelp to make HTML files and a HTML help project" + @echo " qthelp to make HTML files and a qthelp project" + @echo " devhelp to make HTML files and a Devhelp project" + @echo " epub to make an epub" + @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" + @echo " latexpdf to make LaTeX files and run them through pdflatex" + @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" + @echo " text to make text files" + @echo " man to make manual pages" + @echo " texinfo to make Texinfo files" + @echo " info to make Texinfo files and run them through makeinfo" + @echo " gettext to make PO message catalogs" + @echo " changes to make an overview of all changed/added/deprecated items" + @echo " xml to make Docutils-native XML files" + @echo " pseudoxml to make pseudoxml-XML files for display purposes" + @echo " linkcheck to check all external links for integrity" + @echo " doctest to run all doctests embedded in the documentation (if enabled)" + +clean: + rm -rf $(BUILDDIR)/* + +html: + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." + +dirhtml: + $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml + @echo + @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." + +singlehtml: + $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml + @echo + @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." + +pickle: + $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle + @echo + @echo "Build finished; now you can process the pickle files." + +json: + $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json + @echo + @echo "Build finished; now you can process the JSON files." + +htmlhelp: + $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp + @echo + @echo "Build finished; now you can run HTML Help Workshop with the" \ + ".hhp project file in $(BUILDDIR)/htmlhelp." + +qthelp: + $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp + @echo + @echo "Build finished; now you can run "qcollectiongenerator" with the" \ + ".qhcp project file in $(BUILDDIR)/qthelp, like this:" + @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/GeoPy.qhcp" + @echo "To view the help file:" + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/GeoPy.qhc" + +devhelp: + $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp + @echo + @echo "Build finished." + @echo "To view the help file:" + @echo "# mkdir -p $$HOME/.local/share/devhelp/GeoPy" + @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/GeoPy" + @echo "# devhelp" + +epub: + $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub + @echo + @echo "Build finished. The epub file is in $(BUILDDIR)/epub." + +latex: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo + @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." + @echo "Run \`make' in that directory to run these through (pdf)latex" \ + "(use \`make latexpdf' here to do that automatically)." + +latexpdf: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through pdflatex..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +latexpdfja: + $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex + @echo "Running LaTeX files through platex and dvipdfmx..." + $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja + @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." + +text: + $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text + @echo + @echo "Build finished. The text files are in $(BUILDDIR)/text." + +man: + $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man + @echo + @echo "Build finished. The manual pages are in $(BUILDDIR)/man." + +texinfo: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo + @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." + @echo "Run \`make' in that directory to run these through makeinfo" \ + "(use \`make info' here to do that automatically)." + +info: + $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo + @echo "Running Texinfo files through makeinfo..." + make -C $(BUILDDIR)/texinfo info + @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." + +gettext: + $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale + @echo + @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." + +changes: + $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes + @echo + @echo "The overview file is in $(BUILDDIR)/changes." + +linkcheck: + $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck + @echo + @echo "Link check complete; look for any errors in the above output " \ + "or in $(BUILDDIR)/linkcheck/output.txt." + +doctest: + $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest + @echo "Testing of doctests in the sources finished, look at the " \ + "results in $(BUILDDIR)/doctest/output.txt." + +xml: + $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml + @echo + @echo "Build finished. The XML files are in $(BUILDDIR)/xml." + +pseudoxml: + $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml + @echo + @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 000000000..2278eaebd --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,266 @@ +# -*- coding: utf-8 -*- +# +# GeoPy documentation build configuration file, created by +# sphinx-quickstart on Thu Oct 24 19:28:11 2013. +# +# This file is execfile()d with the current directory set to its +# containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import sys +import os + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +#sys.path.insert(0, os.path.abspath('.')) + +# -- General configuration ------------------------------------------------ + +# If your documentation needs a minimal Sphinx version, state it here. +#needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + 'sphinx.ext.autodoc', + 'sphinx.ext.doctest', + 'sphinx.ext.intersphinx', +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix of source filenames. +source_suffix = '.rst' + +# The encoding of source files. +#source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'GeoPy' +copyright = u'2013, GeoPy Contributors' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = '0.96.0' +# The full version, including alpha/beta/rc tags. +release = '0.96.0' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +#language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +#today = '' +# Else, today_fmt is used as the format for a strftime call. +#today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = ['_build'] + +# The reST default role (used for this markup: `text`) to use for all +# documents. +#default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +#add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +#add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +#show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# A list of ignored prefixes for module index sorting. +#modindex_common_prefix = [] + +# If true, keep warnings as "system message" paragraphs in the built documents. +#keep_warnings = False + + +# -- Options for HTML output ---------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +html_theme = 'default' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +#html_theme_options = {} + +# Add any paths that contain custom themes here, relative to this directory. +#html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +#html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +#html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +#html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +#html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +# Add any extra paths that contain custom files (such as robots.txt or +# .htaccess) here, relative to this directory. These files are copied +# directly to the root of the documentation. +#html_extra_path = [] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +#html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +#html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +#html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +#html_additional_pages = {} + +# If false, no module index is generated. +#html_domain_indices = True + +# If false, no index is generated. +#html_use_index = True + +# If true, the index is split into individual pages for each letter. +#html_split_index = False + +# If true, links to the reST sources are added to the pages. +#html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +#html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +#html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +#html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +#html_file_suffix = None + +# Output file base name for HTML help builder. +htmlhelp_basename = 'GeoPydoc' + + +# -- Options for LaTeX output --------------------------------------------- + +latex_elements = { +# The paper size ('letterpaper' or 'a4paper'). +#'papersize': 'letterpaper', + +# The font size ('10pt', '11pt' or '12pt'). +#'pointsize': '10pt', + +# Additional stuff for the LaTeX preamble. +#'preamble': '', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + ('index', 'GeoPy.tex', u'GeoPy Documentation', + u'GeoPy Contributors', 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +#latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +#latex_use_parts = False + +# If true, show page references after internal links. +#latex_show_pagerefs = False + +# If true, show URL addresses after external links. +#latex_show_urls = False + +# Documents to append as an appendix to all manuals. +#latex_appendices = [] + +# If false, no module index is generated. +#latex_domain_indices = True + + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + ('index', 'geopy', u'GeoPy Documentation', + [u'GeoPy Contributors'], 1) +] + +# If true, show URL addresses after external links. +#man_show_urls = False + + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + ('index', 'GeoPy', u'GeoPy Documentation', + u'GeoPy Contributors', 'GeoPy', 'One line description of project.', + 'Miscellaneous'), +] + +# Documents to append as an appendix to all manuals. +#texinfo_appendices = [] + +# If false, no module index is generated. +#texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +#texinfo_show_urls = 'footnote' + +# If true, do not generate a @detailmenu in the "Top" node's menu. +#texinfo_no_detailmenu = False + + +# Example configuration for intersphinx: refer to the Python standard library. +intersphinx_mapping = {'http://docs.python.org/': None} diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 000000000..7d8f16832 --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,55 @@ +.. GeoPy documentation master file, created by + sphinx-quickstart on Thu Oct 24 19:28:11 2013. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to GeoPy's documentation! +================================= + +.. automodule:: geopy + :members: __doc__ + +Geocoders +~~~~~~~~~ +Geocoders each define at least a ``geocode`` method, for resolving a location +from a string, and may define a ``reverse`` method, which resolves a pair of +coordinates to an address. Each Geocoder accepts any credentials +or settings needed to interact with its service, e.g., an API key or +locale, during its initialization. + +.. autoclass:: geopy.geocoders.Bing + :members: __init__, geocode, reverse + +.. autoclass:: geopy.geocoders.GoogleV3 + :members: __init__, geocode, reverse + +.. autoclass:: geopy.geocoders.GeocoderDotUS + :members: __init__, geocode + +.. autoclass:: geopy.geocoders.GeoNames + :members: __init__, geocode + +.. autoclass:: geopy.geocoders.MapQuest + :members: __init__, geocode + +.. autoclass:: geopy.geocoders.OpenMapQuest + :members: __init__, geocode + +.. autoclass:: geopy.geocoders.MediaWiki + :members: __init__, geocode + +.. autoclass:: geopy.geocoders.YahooPlaceFinder + :members: __init__, geocode + +Data +~~~~ + +.. autoclass:: geopy.point.Point + :members: __new__, from_string, from_sequence, from_point + +Indices and search +================== + +* :ref:`genindex` +* :ref:`search` + diff --git a/geopy/__init__.py b/geopy/__init__.py index 1d2e2d3a0..a6ee0b399 100644 --- a/geopy/__init__.py +++ b/geopy/__init__.py @@ -1,5 +1,37 @@ """ -Public access... +geopy is a Python client for several popular geocoding web services. + +geopy makes it easy for Python developers to locate the coordinates of +addresses, cities, countries, and landmarks across the globe using +third-party geocoders and other data sources. + +To geolocate a query to an address and coordinates:: + + from geopy.geocoders import GoogleV3 + geolocator = GoogleV3() + address, (latitude, longitude) = geolocator.geocode("175 5th Avenue NYC") + print address, latitude, longitude + # 175 5th Avenue, New York, NY 10010, USA 40.7410262 -73.9897806 + +To find the address corresponding to a set of coordinates:: + + from geopy.geocoders import GoogleV3 + geolocator = GoogleV3() + address, (latitude, longitude) = geolocator.reverse("40.752067, -73.977578", exactly_one=True) + print address, latitude, longitude + # 77 East 42nd Street, New York, NY 10017, USA 40.7520802 -73.9775683 + + +Locators' ``geolocate`` and ``reverse`` methods may return three +types of values: + +- When there are no results found, returns ``None``. + +- When the method's ``exactly_one`` argument is ``True`` and at least one result is found, returns a tuple of: + (address, (latitude, longitude)). + +- When ``exactly_one`` is False, and there is at least one result, returns a list of tuples: + [(address, (latitude, longitude)), [...]] """ from geopy.point import Point diff --git a/geopy/compat.py b/geopy/compat.py index eeae66422..56a616a52 100644 --- a/geopy/compat.py +++ b/geopy/compat.py @@ -27,14 +27,3 @@ def __init__(self): "BeautifulSoup was not found. Please install BeautifulSoup " "in order to use the SemanticMediaWiki Geocoder." ) # pylint: disable=C0103 - -try: - import oauth2 # pylint: disable=W0611,F0401 -except ImportError: - class oauth2(object): # pylint: disable=R0903 - """ - Raise import error. - """ - - def __init__(self): - raise ImportError('No module named oauth2') diff --git a/geopy/geocoders/bing.py b/geopy/geocoders/bing.py index 1b2689918..ea80ce074 100644 --- a/geopy/geocoders/bing.py +++ b/geopy/geocoders/bing.py @@ -21,9 +21,9 @@ def __init__(self, api_key, format_string=None): """Initialize a customized Bing geocoder with location-specific address information and your Bing Maps API key. - ``api_key`` should be a valid Bing Maps API key. + :param string api_key: should be a valid Bing Maps API key. - ``format_string`` is a string containing '%s' where the string to + :param string format_string: is a string containing '%s' where the string to geocode should be interpolated before querying the geocoder. For example: '%s, Mountain View, CA'. The default is just '%s'. """ @@ -35,8 +35,17 @@ def geocode(self, query, exactly_one=True, user_location=None): # pylint: disabl """ Geocode an address. - ``user_location`` should be an instance of geopy.Point. user_location - position prioritizes results that are closer to this location. + :param string query: The address or query you wish to geocode. + + :param bool exactly_one: Return one result or a list of results, if + available. + + :param user_location: Prioritize results closer to + this location. + + .. versionadded:: 0.96.0 + + :type user_location: :class:`geopy.point.Point` """ super(Bing, self).geocode(query) params = { @@ -58,7 +67,10 @@ def reverse(self, point, exactly_one=True): # pylint: disable=W0221 """ Reverse geocode a point. - ``point`` should be an instance of :class:`geopy.point.Point`. + :param point: Location which you would like an address for. + :type point: :class:`geopy.point.Point` + + :param bool exactly_one: Return one result, or a list? """ params = {'key': self.api_key} url = "%s/%s,%s?%s" % ( diff --git a/geopy/geocoders/dot_us.py b/geopy/geocoders/dot_us.py index cc520c78b..7bc8f2e26 100644 --- a/geopy/geocoders/dot_us.py +++ b/geopy/geocoders/dot_us.py @@ -41,6 +41,14 @@ def _get_url(self): return 'http://%sgeocoder.us/%s' % (auth, resource) def geocode(self, query, exactly_one=True): # pylint: disable=W0613,W0221 + """ + Geocode a location query. + + :param string query: The address or query you wish to geocode. + + :param bool exactly_one: Return one result or a list of results, if + available. + """ super(GeocoderDotUS, self).geocode(query) query_str = self.format_string % query diff --git a/geopy/geocoders/geonames.py b/geopy/geocoders/geonames.py index 86676983c..3a6464a30 100644 --- a/geopy/geocoders/geonames.py +++ b/geopy/geocoders/geonames.py @@ -33,6 +33,14 @@ def __init__(self, country_bias=None, username=None): self.api = "http://api.geonames.org/searchJSON" def geocode(self, query, exactly_one=True): # pylint: disable=W0221 + """ + Geocode a location query. + + :param string query: The address or query you wish to geocode. + + :param bool exactly_one: Return one result or a list of results, if + available. + """ super(GeoNames, self).geocode(query) params = { 'q': query, diff --git a/geopy/geocoders/googlev3.py b/geopy/geocoders/googlev3.py index 51d32ec11..77694124a 100644 --- a/geopy/geocoders/googlev3.py +++ b/geopy/geocoders/googlev3.py @@ -1,10 +1,5 @@ """ :class:`.GoogleV3` is the Google Maps V3 geocoder. - -Largely adapted from the existing v2 geocoder with modifications made where -possible to support the v3 API as well as to clean up the class without -breaking its compatibility or diverging its API too far from the rest of the -geocoder classes. """ import base64 @@ -97,10 +92,7 @@ def geocode_url(self, url, exactly_one=True): def geocode(self, query, bounds=None, region=None, # pylint: disable=W0221,R0913 language=None, sensor=False, exactly_one=True): """ - Geocode an address or other text query. For example: - - address, latitude, longitude = \ - GoogleV3().geocode("1 Central Wharf Boston MA") + Geocode a location query. :param string query: The address or query you wish to geocode. @@ -113,13 +105,11 @@ def geocode(self, query, bounds=None, region=None, # pylint: disable=W0221,R0913 :param string language: The language in which to return results. Default None. - :param boolean sensor: Whether the geocoding request comes from a + :param bool sensor: Whether the geocoding request comes from a device with a location sensor. Default False. - :param boolean exactly_one: Return one result or a list of results, if - available. Default True. - - :rtype: (address, (latitude, longitude)) + :param bool exactly_one: Return one result or a list of results, if + available. """ super(GoogleV3, self).geocode(query) @@ -145,18 +135,12 @@ def geocode(self, query, bounds=None, region=None, # pylint: disable=W0221,R0913 def reverse(self, point, language=None, # pylint: disable=W0221 sensor=False, exactly_one=False): """ - Given a point, find an address. For example: - - address, (latitude, longitude) = \ - GoogleV3().reverse( - "40.75376406311989, -73.98489005863667", - exactly_one=True - ) + Given a point, find an address. :param point: The coordinates for which you wish to obtain the closest human-readable addresses. - :type limit: :class:`geopy.point.Point`, list or tuple of (latitude, - longitude), or string as "latitude, longitude" + :type point: :class:`geopy.point.Point`, list or tuple of (latitude, + longitude), or string as "%(latitude)s, %(longitude)s" :param string language: The language in which to return results. Default None. @@ -165,9 +149,7 @@ def reverse(self, point, language=None, # pylint: disable=W0221 device with a location sensor. Default False. :param boolean exactly_one: Return one result or a list of results, if - available. Default True. - - :rtype: (address, (latitude, longitude)) + available. """ params = { 'latlng': self._coerce_point_to_string(point), diff --git a/geopy/geocoders/mapquest.py b/geopy/geocoders/mapquest.py index f33ddb588..a0c59b209 100644 --- a/geopy/geocoders/mapquest.py +++ b/geopy/geocoders/mapquest.py @@ -27,6 +27,14 @@ def __init__(self, api_key=None, format_string=None): self.api = "http://www.mapquestapi.com/geocoding/v1/address" def geocode(self, query, exactly_one=True): # pylint: disable=W0221 + """ + Geocode a location query. + + :param string query: The address or query you wish to geocode. + + :param bool exactly_one: Return one result or a list of results, if + available. + """ super(MapQuest, self).geocode(query) params = { 'key': self.api_key, diff --git a/geopy/geocoders/openmapquest.py b/geopy/geocoders/openmapquest.py index 2a6d62fc2..98f5f69e4 100644 --- a/geopy/geocoders/openmapquest.py +++ b/geopy/geocoders/openmapquest.py @@ -18,11 +18,12 @@ class OpenMapQuest(Geocoder): # pylint: disable=W0223 """ def __init__(self, api_key=None, format_string=None): - """Initialize an Open MapQuest geocoder with location-specific + """ + Initialize an Open MapQuest geocoder with location-specific address information, no API Key is needed by the Nominatim based platform. - ``format_string`` is a string containing '%s' where the string to + :param string format_string: is a string containing '%s' where the string to geocode should be interpolated before querying the geocoder. For example: '%s, Mountain View, CA'. The default is just '%s'. """ @@ -33,6 +34,14 @@ def __init__(self, api_key=None, format_string=None): "?format=json&%s" def geocode(self, query, exactly_one=True): # pylint: disable=W0221 + """ + Geocode a location query. + + :param string query: The address or query you wish to geocode. + + :param bool exactly_one: Return one result or a list of results, if + available. + """ super(OpenMapQuest, self).geocode(query) params = { 'q': self.format_string % query diff --git a/geopy/geocoders/placefinder.py b/geopy/geocoders/placefinder.py index 2084d9011..17ebe2c0d 100644 --- a/geopy/geocoders/placefinder.py +++ b/geopy/geocoders/placefinder.py @@ -5,7 +5,7 @@ from __future__ import absolute_import, division from __future__ import print_function, unicode_literals -from geopy.compat import json, oauth2 +from geopy.compat import json import time import urllib @@ -13,6 +13,11 @@ from geopy.geocoders.base import Geocoder, GeocoderError +try: + import oauth2 # pylint: disable=F0401 +except ImportError: + oauth2 = None + class YahooPlaceFinder(Geocoder): """ @@ -24,17 +29,16 @@ def __init__(self, consumer_key, consumer_secret): """ Sets consumer key and secret. """ + if oauth2 is None: + raise ImportError('oauth2 is needed for YahooPlaceFinder') super(YahooPlaceFinder, self).__init__() self.consumer_key = consumer_key self.consumer_secret = consumer_secret def _build_request(self, string, reverse): - """ - returns a signed oauth request for the given query - + Returns a signed oauth request for the given query """ - request = oauth2.Request( method='GET', parameters={ @@ -135,7 +139,21 @@ def humanize(location): def geocode(self, query, min_quality=0, raw=False, reverse=False, valid_country_codes=None): """ - Returns a geocoded location using Yahoo's PlaceFinder API. + Geocode a location query. + + :param string query: The address or query you wish to geocode. + + :param int min_quality: TODO. + + :param bool raw: TODO. + + :param bool reverse: TODO. + + :param valid_country_codes: TODO. + :type valid_country_codes: list or tuple + + :param bool exactly_one: Return one result or a list of results, if + available. """ super(YahooPlaceFinder, self).geocode(query) request = self._build_request(query, reverse=reverse) diff --git a/geopy/geocoders/smartystreets.py b/geopy/geocoders/smartystreets.py index 3d50969b6..d2b44a46e 100644 --- a/geopy/geocoders/smartystreets.py +++ b/geopy/geocoders/smartystreets.py @@ -38,6 +38,11 @@ def __init__(self, auth_id, auth_token, candidates=None): self.url = 'https://api.qualifiedaddress.com/street-address' def geocode(self, query): + """ + Geocode a location query. + + :param string query: The address or query you wish to geocode. + """ super(LiveAddress, self).geocode(query) url = self._compose_url(query) logger.debug("%s.geocode: %s", self.__class__.__name__, url) diff --git a/geopy/geocoders/wiki_gis.py b/geopy/geocoders/wiki_gis.py index 8193f2308..7ce5f3658 100644 --- a/geopy/geocoders/wiki_gis.py +++ b/geopy/geocoders/wiki_gis.py @@ -16,13 +16,14 @@ class MediaWiki(Geocoder): # pylint: disable=W0223 """ def __init__(self, format_url, transform_string=None): - """Initialize a geocoder that can parse MediaWiki pages with the GIS + """ + Initialize a geocoder that can parse MediaWiki pages with the GIS extension enabled. - ``format_url`` is a URL string containing '%s' where the page name to + :param string format_url: is a URL string containing '%s' where the page name to request will be interpolated. For example: 'http://www.wiki.com/wiki/%s' - ``_transform_string`` is a callable that will make appropriate + :param callable _transform_string: is a callable that will make appropriate replacements to the input string before requesting the page. If None is given, the default _transform_string which replaces ' ' with '_' will be used. @@ -38,6 +39,11 @@ def _transform_string(string): # pylint: disable=E0202 return string.replace(' ', '_') def geocode(self, query): + """ + Geocode a location query. + + :param string query: The address or query you wish to geocode. + """ super(MediaWiki, self).geocode(query) wiki_string = self._transform_string(query) url = self.format_url % wiki_string diff --git a/geopy/point.py b/geopy/point.py index ef5d6251e..06c93ced9 100644 --- a/geopy/point.py +++ b/geopy/point.py @@ -1,8 +1,13 @@ +""" +:class:`Point` data structure. +""" + import re from itertools import islice -from geopy import util, units, format +from geopy import util, units, format # pylint: disable=W0622 + -class Point(object): +class Point(object): # pylint: disable=R0924 """ A geodetic point with latitude, longitude, and altitude. @@ -13,32 +18,38 @@ class Point(object): Points can be created in a number of ways... - With longitude, latitude, and altitude: + With longitude, latitude, and altitude:: + >>> p1 = Point(41.5, -81, 0) >>> p2 = Point(latitude=41.5, longitude=-81) - With a sequence of 0 to 3 values (longitude, latitude, altitude): + With a sequence of 0 to 3 values (longitude, latitude, altitude):: + >>> p1 = Point([41.5, -81, 0]) >>> p2 = Point((41.5, -81)) - Copy another `Point` instance: + Copy another `Point` instance:: + >>> p2 = Point(p1) >>> p2 == p1 True >>> p2 is p1 False - Give an object with a 'point' attribute, such as a `Location` instance: + Give an object with a 'point' attribute, such as a `Location` instance:: + >>> p = Point(location) - Give a string containing at least latitude and longitude: + Give a string containing at least latitude and longitude:: + >>> p1 = Point('41.5,-81.0') >>> p2 = Point('41.5 N -81.0 W') >>> p3 = Point('-41.5 S, 81.0 E, 2.5km') >>> p4 = Point('23 26m 22s N 23 27m 30s E 21.0mi') >>> p5 = Point('''3 26' 22" N 23 27' 30" E''') - Point values can be accessed by name or by index: + Point values can be accessed by name or by index:: + >>> p = Point(41.5, -81.0, 0) >>> p.latitude == p[0] True @@ -47,7 +58,8 @@ class Point(object): >>> p.altitude == p[2] True - When unpacking (or iterating), a (latitude, longitude, altitude) tuple is returned + When unpacking (or iterating), a (latitude, longitude, altitude) tuple is returned:: + >>> latitude, longitude, altitude = p """ @@ -79,6 +91,11 @@ class Point(object): """ % UTIL_PATTERNS, re.X) def __new__(cls, latitude=None, longitude=None, altitude=None): + """ + :param float latitude: Latitude of point. + :param float longitude: Longitude of point. + :param float altitude: Altitude of point. + """ single_arg = longitude is None and altitude is None if single_arg and not isinstance(latitude, util.NUMBER_TYPES): arg = latitude @@ -225,7 +242,7 @@ def parse_altitude(cls, distance, unit): @classmethod def from_string(cls, string): """ - Create and return a Point instance from a string containing latitude + Create and return a ``Point`` instance from a string containing latitude and longitude, and optionally, altitude. Latitude and longitude must be in degrees and may be in decimal form @@ -243,21 +260,21 @@ def from_string(cls, string): Altitude, if supplied, must be a decimal number with given units. The following unit abbrevations (case-insensitive) are supported: - km (kilometers) - m (meters) - mi (miles) - ft (feet) - nm, nmi (nautical miles) + - ``km`` (kilometers) + - ``m`` (meters) + - ``mi`` (miles) + - ``ft`` (feet) + - ``nm``, ``nmi`` (nautical miles) Some example strings the will work include: - 41.5;-81.0 - 41.5,-81.0 - 41.5 -81.0 - 41.5 N -81.0 W - -41.5 S;81.0 E - 23 26m 22s N 23 27m 30s E - 23 26' 22" N 23 27' 30" E + - 41.5;-81.0 + - 41.5,-81.0 + - 41.5 -81.0 + - 41.5 N -81.0 W + - -41.5 S;81.0 E + - 23 26m 22s N 23 27m 30s E + - 23 26' 22" N 23 27' 30" E """ match = re.match(cls.POINT_PATTERN, string) @@ -287,10 +304,9 @@ def from_string(cls, string): @classmethod def from_sequence(cls, seq): """ - Create and return a new Point instance from any iterable with 0 to + Create and return a new ``Point`` instance from any iterable with 0 to 3 elements. The elements, if present, must be latitude, longitude, and altitude, respectively. - """ args = tuple(islice(seq, 4)) return cls(*args) @@ -298,7 +314,7 @@ def from_sequence(cls, seq): @classmethod def from_point(cls, point): """ - Create and return a new Point instance from another Point instance. + Create and return a new ``Point`` instance from another ``Point`` instance. """ return cls(point.latitude, point.longitude, point.altitude)