[pyosmium] 01/01: Imported Upstream version 0.0~20150331-2a93d5b

Sebastiaan Couwenberg sebastic at moszumanska.debian.org
Tue Mar 31 21:35:43 UTC 2015


This is an automated email from the git hooks/post-receive script.

sebastic pushed a commit to branch upstream
in repository pyosmium.

commit 73380a783ca7371833fb1f3cb6f3f37d32b12ec8
Author: Bas Couwenberg <sebastic at xs4all.nl>
Date:   Tue Mar 31 23:32:34 2015 +0200

    Imported Upstream version 0.0~20150331-2a93d5b
---
 doc/Makefile             | 177 ++++++++++++++++++++++++++++
 doc/conf.py              | 273 +++++++++++++++++++++++++++++++++++++++++++
 doc/index.rst            |  21 ++++
 doc/intro.rst            |   6 +
 doc/ref_geom.rst         |  17 +++
 doc/ref_index.rst        |  23 ++++
 doc/ref_io.rst           |  12 ++
 doc/ref_osm.rst          |  95 +++++++++++++++
 doc/ref_osmium.rst       |  23 ++++
 doc/reference.rst        |  16 +++
 lib/generic_handler.hpp  |  14 ++-
 lib/geom.cc              |  41 +++++--
 lib/index.cc             |  34 ++++--
 lib/io.cc                |  22 +++-
 lib/osm.cc               | 299 ++++++++++++++++++++++++++++++++++++++---------
 lib/osmium.cc            |  36 ++++--
 lib/std_pair.hpp         |  43 +++++++
 osmium/__init__.py       |   8 +-
 osmium/geom/__init__.py  |   1 +
 osmium/index/__init__.py |   1 +
 osmium/io/__init__.py    |   1 +
 osmium/osm/__init__.py   |   1 +
 setup.py                 |  18 ++-
 test/test_helper.py      |  33 ++++--
 test/test_osm.py         |  86 ++++++++++++--
 25 files changed, 1190 insertions(+), 111 deletions(-)

diff --git a/doc/Makefile b/doc/Makefile
new file mode 100644
index 0000000..f0463a5
--- /dev/null
+++ b/doc/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 <target>' where <target> 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/Pyosmium.qhcp"
+	@echo "To view the help file:"
+	@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/Pyosmium.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/Pyosmium"
+	@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/Pyosmium"
+	@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/doc/conf.py b/doc/conf.py
new file mode 100644
index 0000000..77ac1ec
--- /dev/null
+++ b/doc/conf.py
@@ -0,0 +1,273 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+#
+# Pyosmium documentation build configuration file, created by
+# sphinx-quickstart on Tue Mar 10 18:09:49 2015.
+#
+# 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 sysconfig
+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('.'))
+build_dir = "../build/lib.%s-%d.%d" % (
+                    sysconfig.get_platform(),
+                    sys.version_info[0], sys.version_info[1])
+
+# insert after the current directory
+sys.path.insert(0, os.path.normpath(os.path.join(os.path.abspath('.'), build_dir)))
+
+
+# -- 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.todo',
+]
+
+# 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 = 'Pyosmium'
+copyright = '2015, Sarah Hoffmann'
+
+# 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 = '2.0'
+# The full version, including alpha/beta/rc tags.
+release = '2.0.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
+# "<project> v<release> 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 <link> 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 = 'Pyosmiumdoc'
+
+
+# -- 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', 'Pyosmium.tex', 'Pyosmium Documentation',
+   'Sarah Hoffmann', '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', 'pyosmium', 'Pyosmium Documentation',
+     ['Sarah Hoffmann'], 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', 'Pyosmium', 'Pyosmium Documentation',
+   'Sarah Hoffmann', 'Pyosmium', '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
+
+autodoc_member_order = 'bysource'
+autodoc_defaut_flags = ['members', 'undoc-members']
diff --git a/doc/index.rst b/doc/index.rst
new file mode 100644
index 0000000..e7ac56a
--- /dev/null
+++ b/doc/index.rst
@@ -0,0 +1,21 @@
+.. Pyosmium documentation master file, created by
+   sphinx-quickstart on Tue Mar 10 18:09:49 2015.
+   You can adapt this file completely to your liking, but it should at least
+   contain the root `toctree` directive.
+
+Welcome to Pyosmium's documentation!
+====================================
+
+Pyosmium is a library to process OSM files in different formats. It is
+a wrapper of the C++ library osmium and profits from its fast implementation.
+
+.. toctree::
+   :maxdepth: 2
+
+   intro
+   reference
+    
+
+* :ref:`genindex`
+* :ref:`search`
+
diff --git a/doc/intro.rst b/doc/intro.rst
new file mode 100644
index 0000000..ee8c1e5
--- /dev/null
+++ b/doc/intro.rst
@@ -0,0 +1,6 @@
+Basic Usage
+===========
+
+The following chapter gives a practical introduction on how to use Pyosmium.
+For a more detailed introduction into the design of the library, the reader
+is referred to the osmium documentation.
diff --git a/doc/ref_geom.rst b/doc/ref_geom.rst
new file mode 100644
index 0000000..8886237
--- /dev/null
+++ b/doc/ref_geom.rst
@@ -0,0 +1,17 @@
+``geom`` - Geometry Helper Functions
+------------------------------------
+
+This module provides various helper functions for geometry handling.
+
+Geometry Factories
+^^^^^^^^^^^^^^^^^^
+
+.. autoclass:: osmium.geom.WKBFactory
+    :members:
+    :undoc-members:
+
+
+Other Functions
+^^^^^^^^^^^^^^^
+
+.. autofunction:: osmium.geom.haversine_distance
diff --git a/doc/ref_index.rst b/doc/ref_index.rst
new file mode 100644
index 0000000..e8cac63
--- /dev/null
+++ b/doc/ref_index.rst
@@ -0,0 +1,23 @@
+``index`` - Data Stores
+-----------------------
+
+The ``index`` submodule provides efficient storage containers for
+preprocessed OSM data.
+
+
+Node Location Storage
+^^^^^^^^^^^^^^^^^^^^^
+
+Node location can be cached in a ``LocationTable``. There are different
+implementations available which should be choosen according to the size of
+data and whether or not the cache should be permanent. See the Osmium manual
+for a detailed explaination. The compiled in types can be listed with the
+``map_types`` function, new storages can be created with ``create_map``.
+
+.. autofunction:: osmium.index.map_types
+
+.. autofunction:: osmium.index.create_map
+
+.. autoclass:: osmium.index.LocationTable
+    :members:
+    :undoc-members:
diff --git a/doc/ref_io.rst b/doc/ref_io.rst
new file mode 100644
index 0000000..2c875d1
--- /dev/null
+++ b/doc/ref_io.rst
@@ -0,0 +1,12 @@
+``io`` - Data In- and Output
+----------------------------
+
+This module exposes the generic file reader.
+
+.. autoclass:: osmium.io.Reader
+    :members:
+    :undoc-members:
+
+.. autoclass:: osmium.io.Header
+    :members:
+    :undoc-members:
diff --git a/doc/ref_osm.rst b/doc/ref_osm.rst
new file mode 100644
index 0000000..b52df63
--- /dev/null
+++ b/doc/ref_osm.rst
@@ -0,0 +1,95 @@
+``osm`` - Basic Datatypes
+-------------------------
+
+The ``osm`` submodule contains definition of the basic data types used
+throughout the library.
+
+OSM Objects
+^^^^^^^^^^^
+
+There are five classes representing the basic OSM entities.
+
+.. autoclass:: osmium.osm.OSMObject
+    :members:
+    :undoc-members:
+
+.. autoclass:: osmium.osm.Node
+    :members:
+    :undoc-members:
+
+.. autoclass:: osmium.osm.Way
+    :members:
+    :undoc-members:
+
+.. autoclass:: osmium.osm.Relation
+    :members:
+    :undoc-members:
+
+.. autoclass:: osmium.osm.Area
+    :members:
+    :undoc-members:
+
+.. autoclass:: osmium.osm.Changeset
+    :members:
+    :undoc-members:
+
+
+Node Reference Lists
+^^^^^^^^^^^^^^^^^^^^
+
+Line geometries in OSM are simply a sequence of nodes. To simplify processing
+osmium returns such node sequences using a special datatype that contains a
+reference to the node id and also the location geometry. The latter is only
+valid if the node locations have been cached by a location handler.
+
+.. autoclass:: osmium.osm.NodeRef
+    :members:
+    :undoc-members:
+
+.. autoclass:: osmium.osm.NodeRefList
+    :members:
+    :undoc-members:
+
+.. autoclass:: osmium.osm.WayNodeList
+    :members:
+    :undoc-members:
+
+.. autoclass:: osmium.osm.OuterRing
+    :members:
+    :undoc-members:
+
+.. autoclass:: osmium.osm.InnerRing
+    :members:
+    :undoc-members:
+
+Other OSM Entity Attributes
+^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Some of the attributes of the OSM entities are represented with more
+complex classes.
+
+.. autoclass:: osmium.osm.Box
+    :members:
+    :undoc-members:
+
+.. autoclass:: osmium.osm.Location
+    :members:
+    :undoc-members:
+
+.. autoclass:: osmium.osm.RelationMember
+    :members:
+    :undoc-members:
+
+.. autoclass:: osmium.osm.RelationMemberList
+    :members:
+    :undoc-members:
+
+.. autoclass:: osmium.osm.Tag
+    :members:
+    :undoc-members:
+
+.. autoclass:: osmium.osm.TagList
+    :members:
+    :undoc-members:
+
+
diff --git a/doc/ref_osmium.rst b/doc/ref_osmium.rst
new file mode 100644
index 0000000..8efbdac
--- /dev/null
+++ b/doc/ref_osmium.rst
@@ -0,0 +1,23 @@
+``osmium`` - Processing OSM files
+---------------------------------
+
+Osmium processes files by reading data from a file and applying them
+to a processing chain. Pyosmium offers a simplified wrapper to this
+interface with the ``SimpleHandler`` class from which an OSM file processor
+can easily be derived.
+
+For more fine grained control of the processing chain, the more basic
+functions and processors are exported as well in this module.
+
+Simple Handlers
+^^^^^^^^^^^^^^^
+
+.. autoclass:: osmium.SimpleHandler
+    :members:
+    :undoc-members:
+
+
+Low-level Functions and Classes
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+.. autofunction:: osmium.apply
diff --git a/doc/reference.rst b/doc/reference.rst
new file mode 100644
index 0000000..2d30d81
--- /dev/null
+++ b/doc/reference.rst
@@ -0,0 +1,16 @@
+Pyosmium Reference
+==================
+
+Pyosmium is a thin wrapper to the osmium library. Where possible it follows
+its structure and naming scheme. This reference provides a short description
+of the exported classes and interfaces. More details and background
+information can be found in the osmium manual.
+
+.. toctree::
+    :maxdepth: 2
+
+    ref_osmium
+    ref_osm
+    ref_io
+    ref_index
+    ref_geom
diff --git a/lib/generic_handler.hpp b/lib/generic_handler.hpp
index b15c8d0..916c965 100644
--- a/lib/generic_handler.hpp
+++ b/lib/generic_handler.hpp
@@ -1,7 +1,16 @@
+#ifndef PYOSMIUM_GENERIC_HANDLER_HPP
+#define PYOSMIUM_GENERIC_HANDLER_HPP
+
+#include <boost/python.hpp>
+
+#include <osmium/area/assembler.hpp>
+#include <osmium/area/multipolygon_collector.hpp>
 #include <osmium/handler.hpp>
+#include <osmium/handler/node_locations_for_ways.hpp>
 #include <osmium/index/map/all.hpp>
+#include <osmium/io/any_input.hpp>
+#include <osmium/visitor.hpp>
 
-using namespace boost::python;
 
 typedef osmium::index::map::Map<osmium::unsigned_object_id_type, osmium::Location> index_type;
 
@@ -89,6 +98,7 @@ void apply(const std::string &filename, osmium::osm_entity_bits::type types,
 
 };
 
+using namespace boost::python;
 
 struct SimpleHandlerWrap: BaseHandler, wrapper<BaseHandler> {
 
@@ -159,3 +169,5 @@ struct SimpleHandlerWrap: BaseHandler, wrapper<BaseHandler> {
         apply(filename, entities, handler, idx);
     }
 };
+
+#endif
diff --git a/lib/geom.cc b/lib/geom.cc
index 4da4c0c..9a0ba99 100644
--- a/lib/geom.cc
+++ b/lib/geom.cc
@@ -15,16 +15,37 @@ public:
 BOOST_PYTHON_MODULE(_geom)
 {
     using namespace boost::python;
-    def("haversine_distance", static_cast<double (*)(const osmium::WayNodeList&)>(&osmium::geom::haversine::distance));
+    docstring_options doc_options(true, true, false);
 
-    class_<WKBFactory>("WKBFactory")
-        .add_property("epsg", &WKBFactory::epsg)
-        .add_property("proj_string", &WKBFactory::proj_string)
-        .def("create_point", static_cast<std::string (WKBFactory::*)(const osmium::Location) const>(&WKBFactory::create_point))
-        .def("create_point", static_cast<std::string (WKBFactory::*)(const osmium::Node&)>(&WKBFactory::create_point))
-        .def("create_point", static_cast<std::string (WKBFactory::*)(const osmium::NodeRef&)>(&WKBFactory::create_point))
-        .def("create_linestring", static_cast<std::string (WKBFactory::*)(const osmium::WayNodeList&, osmium::geom::use_nodes, osmium::geom::direction)>(&WKBFactory::create_linestring))
-        .def("create_linestring", static_cast<std::string (WKBFactory::*)(const osmium::Way&, osmium::geom::use_nodes, osmium::geom::direction)>(&WKBFactory::create_linestring))
-        .def("create_multipolygon", &WKBFactory::create_multipolygon)
+    def("haversine_distance", static_cast<double (*)(const osmium::WayNodeList&)>(&osmium::geom::haversine::distance),
+        arg("list"),
+        "Compute the distance using the Haversine algorithm which takes the "
+        "curvature of earth into account. If a :py:class:`WayNodeList` is given "
+        "as a parameter the total length of the way in meters is computed.");
+
+    class_<WKBFactory>("WKBFactory",
+        "Factory that creates WKB from osmium geometries.")
+        .add_property("epsg", &WKBFactory::epsg,
+                      "(read-only) EPSG number of the output geometry.")
+        .add_property("proj_string", &WKBFactory::proj_string,
+                      "(read-only) projection string of the output geometry.")
+        .def("create_point", static_cast<std::string (WKBFactory::*)(const osmium::Location) const>(&WKBFactory::create_point),
+             (arg("self"), arg("location")),
+             "Create a point geometry from a :py:class:`osmium.osm.Location`.")
+        .def("create_point", static_cast<std::string (WKBFactory::*)(const osmium::Node&)>(&WKBFactory::create_point),
+             (arg("self"), arg("node")),
+             "Create a point geometry from a :py:class:`osmium.osm.Node`.")
+        .def("create_point", static_cast<std::string (WKBFactory::*)(const osmium::NodeRef&)>(&WKBFactory::create_point),
+             (arg("self"), arg("ref")),
+             "Create a point geometry from a :py:class:`osmium.osm.NodeRef`.")
+        .def("create_linestring", static_cast<std::string (WKBFactory::*)(const osmium::WayNodeList&, osmium::geom::use_nodes, osmium::geom::direction)>(&WKBFactory::create_linestring),
+             (arg("self"), arg("list"), arg("use_nodes")="unique", arg("direction")="forward" ),
+             "Create a LineString geometry from a :py:class:`osmium.osm.WayNodeList`.")
+        .def("create_linestring", static_cast<std::string (WKBFactory::*)(const osmium::Way&, osmium::geom::use_nodes, osmium::geom::direction)>(&WKBFactory::create_linestring),
+             (arg("self"), arg("way"), arg("use_nodes")="unique", arg("direction")="forward" ),
+             "Create a LineString geometry from a :py:class:`osmium.osm.Way`.")
+        .def("create_multipolygon", &WKBFactory::create_multipolygon,
+             (arg("self"), arg("area")),
+             "Create a MultiPolygon geometry from a :py:class:`osmium.osm.Area`.")
     ;
 }
diff --git a/lib/index.cc b/lib/index.cc
index ff66fbf..200eea8 100644
--- a/lib/index.cc
+++ b/lib/index.cc
@@ -19,15 +19,33 @@ std::vector<std::string> map_types() {
 
 BOOST_PYTHON_MODULE(_index)
 {
-    class_<LocationTable, boost::noncopyable>("LocationTable", no_init)
-        .def("set", &LocationTable::set)
-        .def("get", &LocationTable::get)
-        .def("size", &LocationTable::size)
-        .def("used_memory", &LocationTable::used_memory)
-        .def("clear", &LocationTable::clear)
+    docstring_options doc_options(true, true, false);
+
+    class_<LocationTable, boost::noncopyable>("LocationTable",
+        "A map from a node ID to a location object. This implementation works "
+        "only with positive node IDs.",
+        no_init)
+        .def("set", &LocationTable::set,
+             (arg("self"), arg("id"), arg("loc")),
+             "Set the location for a given node id.")
+        .def("get", &LocationTable::get,
+             (arg("self"), arg("id")),
+             "Return the location for a given id.")
+        .def("used_memory", &LocationTable::used_memory,
+             arg("self"),
+             "Return the size (in bytes) currently allocated by this location table.")
+        .def("clear", &LocationTable::clear,
+             arg("self"),
+             "Remove all entries from the location table.")
     ;
 
-    def("create_map", &create_map, return_value_policy<manage_new_object>());
-    def("map_types", &map_types);
+    def("create_map", &create_map, return_value_policy<manage_new_object>(),
+        (arg("map_type")),
+        "Create a new location store. The string parameter takes the type "
+        "and, where required, additional arguments separated by comma. For "
+        "example, to create a array cache backed by a file ``foo.store``, "
+        "the map_type should be ``dense_file_array,foo.store``.");
+    def("map_types", &map_types,
+        "Return a list of strings with valid types for the location table.");
 }
 
diff --git a/lib/io.cc b/lib/io.cc
index cc45cd1..6e8c44e 100644
--- a/lib/io.cc
+++ b/lib/io.cc
@@ -7,18 +7,28 @@
 BOOST_PYTHON_MODULE(_io)
 {
     using namespace boost::python;
+    docstring_options doc_options(true, true, false);
 
-    class_<osmium::io::Header>("Header")
+    class_<osmium::io::Header>("Header",
+        "File header with global information about the file.")
         .add_property("has_multiple_object_versions",
                       &osmium::io::Header::has_multiple_object_versions,
-                      make_function(&osmium::io::Header::set_has_multiple_object_versions, return_value_policy<reference_existing_object>()))
+                      make_function(&osmium::io::Header::set_has_multiple_object_versions, return_value_policy<reference_existing_object>()),
+                      "True if there may be more than one version of the same "
+                      "object in the file. This happens normally only in history "
+                      "files.")
     ;
 
-    class_<osmium::io::Reader, boost::noncopyable>("Reader", init<std::string>())
+    class_<osmium::io::Reader, boost::noncopyable>("Reader", 
+        "A class that reads OSM data from a file.",
+        init<std::string>())
         .def(init<std::string, osmium::osm_entity_bits::type>())
-        .def("eof", &osmium::io::Reader::eof)
-        .def("close", &osmium::io::Reader::close)
-        .def("header", &osmium::io::Reader::header)
+        .def("eof", &osmium::io::Reader::eof, arg("self"),
+             "Check if the end of file has been reached.")
+        .def("close", &osmium::io::Reader::close, arg("self"),
+             "Close any open file handles. The reader is unusable afterwards.")
+        .def("header", &osmium::io::Reader::header, arg("self"),
+             "Return the header with file information, see :py:class:`osmium.io.Header`.")
     ;
 
 }
diff --git a/lib/osm.cc b/lib/osm.cc
index 7824a3c..85d39eb 100644
--- a/lib/osm.cc
+++ b/lib/osm.cc
@@ -1,8 +1,13 @@
+#include <time.h>
 #include <boost/python.hpp>
+#include <datetime.h>
 
 #include <osmium/osm.hpp>
 #include <osmium/osm/entity_bits.hpp>
 
+#include "std_pair.hpp"
+
+
 inline const char *get_tag_by_key(osmium::TagList const& obj, const char *value)
 {
     const char* v = obj.get_value_by_key(value);
@@ -22,10 +27,29 @@ inline const char member_item_type(osmium::RelationMember& obj)
     return item_type_to_char(obj.type());
 }
 
+// Converter for osmium::Timestamp -> datetime.datetime
+struct Timestamp_to_python {
+    static PyObject* convert(osmium::Timestamp const& s) {
+        struct tm tm;
+        time_t sse = s.seconds_since_epoch();
+        gmtime_r(&sse, &tm);
+
+        return boost::python::incref(
+                PyDateTime_FromDateAndTime(tm.tm_year + 1900, tm.tm_mon + 1,
+                                           tm.tm_mday, tm.tm_hour, tm.tm_min,
+                                           tm.tm_sec, 0));
+    }
+};
+
 
 BOOST_PYTHON_MODULE(_osm)
 {
+    PyDateTime_IMPORT;
     using namespace boost::python;
+    docstring_options doc_options(true, true, false);
+
+    to_python_converter<osmium::Timestamp, Timestamp_to_python>();
+    std_pair_to_python_converter<int, int>();
 
     enum_<osmium::osm_entity_bits::type>("osm_entity_bits")
         .value("NOTHING", osmium::osm_entity_bits::nothing)
@@ -37,81 +61,242 @@ BOOST_PYTHON_MODULE(_osm)
         .value("CHANGESET", osmium::osm_entity_bits::changeset)
         .value("ALL", osmium::osm_entity_bits::all)
     ;
-    class_<osmium::Timestamp>("Timestamp")
-        .def("__str__", &osmium::Timestamp::to_iso)
-    ;
-    class_<osmium::Location>("Location")
+    class_<osmium::Location>("Location",
+        "A geographic coordinate in WGS84 projection. A location doesn't "
+         "have to be necessarily valid.")
         .def(init<double, double>())
-        .add_property("x", &osmium::Location::x)
-        .add_property("y", &osmium::Location::y)
-        .add_property("lon", &osmium::Location::lon)
-        .add_property("lat", &osmium::Location::lat)
-        .def("valid", &osmium::Location::valid)
+        .add_property("x", &osmium::Location::x,
+                      "(read-only) X coordinate (longitude) as a fixed-point integer.")
+        .add_property("y", &osmium::Location::y,
+                      "(read-only) Y coordinate (latitude) as a fixed-point integer.")
+        .add_property("lon", &osmium::Location::lon,
+                      "(read-only) Longitude (x coordinate) as floating point number.")
+        .add_property("lat", &osmium::Location::lat,
+                      "(read-only) Latitude (y coordinate) as floating point number.")
+        .def("valid", &osmium::Location::valid, args("self"),
+                      "Check that the location is a valid WGS84 coordinate, i.e. "
+                      "that it is within the usual bounds.")
+    ;
+    class_<osmium::Box>("Box",
+                        "A bounding box around a geographic area.")
     ;
-    class_<osmium::Tag, boost::noncopyable>("Tag", no_init)
-        .add_property("k", &osmium::Tag::key)
-        .add_property("v", &osmium::Tag::value)
+    class_<osmium::Tag, boost::noncopyable>("Tag",
+            "A single OSM tag.",
+            no_init)
+        .add_property("k", &osmium::Tag::key,
+                      "(read-only) Tag key.")
+        .add_property("v", &osmium::Tag::value,
+                      "(read-only) Tag value.")
     ;
-    class_<osmium::TagList, boost::noncopyable>("TagList", no_init)
+    class_<osmium::TagList, boost::noncopyable>("TagList",
+        "A fixed list of tags. The list is exported as an unmutable, "
+        "dictionary-like object where the keys are tag strings and the "
+        "items are :py:class:`osmium.osm.Tag`.",
+         no_init)
         .def("__len__", &osmium::TagList::size)
         .def("__getitem__", &get_tag_by_key)
         .def("__contains__", &taglist_contains_tag)
         .def("__iter__", iterator<osmium::TagList,return_internal_reference<>>())
     ;
-    class_<osmium::NodeRef>("NodeRef")
-        .add_property("x", &osmium::NodeRef::x)
-        .add_property("y", &osmium::NodeRef::y)
-        .add_property("lon", &osmium::NodeRef::lon)
-        .add_property("lat", &osmium::NodeRef::lat)
-        .add_property("ref", &osmium::NodeRef::ref)
-        .add_property("location", static_cast<osmium::Location (osmium::NodeRef::*)() const>(&osmium::NodeRef::location))
-    ;
-    class_<osmium::WayNodeList, boost::noncopyable>("WayNodeList", no_init)
-        .def("__len__", &osmium::WayNodeList::size)
-        .def("__getitem__", &osmium::WayNodeList::operator[], return_value_policy<reference_existing_object>())
-        .def("__iter__", iterator<osmium::WayNodeList,return_internal_reference<>>())
-    ;
-    class_<osmium::RelationMember, boost::noncopyable>("RelationMember", no_init)
-        .add_property("ref", static_cast<osmium::object_id_type (osmium::RelationMember::*)() const>(&osmium::RelationMember::ref))
-        .add_property("type", &member_item_type)
-        .add_property("role", &osmium::RelationMember::role)
-    ;
-    class_<osmium::RelationMemberList, boost::noncopyable>("RelationMemberList", no_init)
+    class_<osmium::NodeRef>("NodeRef",
+        "A reference to a OSM node that also caches the nodes location.")
+        .add_property("x", &osmium::NodeRef::x,
+                      "(read-only) X coordinate (longitude) as a fixed-point integer.")
+        .add_property("y", &osmium::NodeRef::y,
+                      "(read-only) Y coordinate (latitude) as a fixed-point integer.")
+        .add_property("lon", &osmium::NodeRef::lon,
+                      "(read-only) Longitude (x coordinate) as floating point number.")
+        .add_property("lat", &osmium::NodeRef::lat,
+                      "(read-only) Latitude (y coordinate) as floating point number.")
+        .add_property("ref", &osmium::NodeRef::ref,
+                      "(read-only) Id of the referenced node.")
+        .add_property("location", static_cast<osmium::Location (osmium::NodeRef::*)() const>(&osmium::NodeRef::location),
+                      "(read-only) Node coordinates as a :py:class:`osmium.osm.Location` object.")
+    ;
+    class_<osmium::RelationMember, boost::noncopyable>("RelationMember",
+        "Member of a relation.",
+        no_init)
+        .add_property("ref", static_cast<osmium::object_id_type (osmium::RelationMember::*)() const>(&osmium::RelationMember::ref),
+                      "OSM ID of the object. Only unique within the type.")
+        .add_property("type", &member_item_type,
+                      "Type of object referenced, a node, way or relation.")
+        .add_property("role", &osmium::RelationMember::role,
+                      "The role of the member within the relation, a free-text string. "
+                      "If no role is set then the string is empty.")
+    ;
+    class_<osmium::RelationMemberList, boost::noncopyable>("RelationMemberList",
+           "An immutable  sequence of relation members :py:class:`osmium.osm.RelationMember`.",
+           no_init)
         .def("__len__", &osmium::RelationMemberList::size)
         .def("__iter__", iterator<osmium::RelationMemberList,return_internal_reference<>>())
     ;
-    class_<osmium::Changeset, boost::noncopyable>("Changeset", no_init)
-    ;
-    class_<osmium::OSMObject, boost::noncopyable>("OSMObject", no_init)
-        .add_property("id", &osmium::OSMObject::id)
-        .add_property("deleted", &osmium::OSMObject::deleted)
-        .add_property("visible", &osmium::OSMObject::visible)
-        .add_property("version", &osmium::OSMObject::version)
-        .add_property("changeset", &osmium::OSMObject::changeset)
-        .add_property("uid", &osmium::OSMObject::uid)
-        .def("user_is_anonymous", &osmium::OSMObject::user_is_anonymous)
-        .add_property("timestamp", &osmium::OSMObject::timestamp)
-        .add_property("user", &osmium::OSMObject::user)
+    class_<osmium::NodeRefList, boost::noncopyable>("NodeRefList",
+        "A list of node references, implemented as "
+        "an immutable sequence of :py:class:`osmium.osm.NodeRef`. This class "
+        "is normally not used directly, use one of its subclasses instead.",
+        no_init)
+        .def("__len__", &osmium::NodeRefList::size)
+        .def("__getitem__", &osmium::NodeRefList::operator[], return_value_policy<reference_existing_object>())
+        .def("__iter__", iterator<osmium::NodeRefList,return_internal_reference<>>())
+        .def("is_closed", &osmium::NodeRefList::is_closed, args("self"),
+             "True if the start and end node are the same (synonym for "
+             "``ends_have_same_id``).")
+        .def("ends_have_same_id", &osmium::NodeRefList::ends_have_same_id, args("self"),
+             "True if the start and end node are exactly the same.")
+        .def("ends_have_same_location", &osmium::NodeRefList::ends_have_same_location,
+             args("self"),
+             "True if the start and end node of the way are at the same location. "
+             "Throws an exception if the location of one of the nodes is missing.")
+    ;
+    class_<osmium::WayNodeList, bases<osmium::NodeRefList>, boost::noncopyable>("WayNodeList",
+        "List of nodes in a way. For its members see :py:class:`osmium.osm.NodeRefList`.",
+        no_init)
+    ;
+    class_<osmium::OuterRing, bases<osmium::NodeRefList>, boost::noncopyable>("OuterRing",
+        "List of nodes in an outer ring. For its members see :py:class:`osmium.osm.NodeRefList`.",
+           no_init)
+    ;
+    class_<osmium::InnerRing, bases<osmium::NodeRefList>, boost::noncopyable>("InnerRing",
+        "List of nodes in an inner ring. For its members see :py:class:`osmium.osm.NodeRefList`.",
+           no_init)
+    ;
+    class_<osmium::OSMObject, boost::noncopyable>("OSMObject",
+            "This is the base class for all OSM entity classes below and contains "
+            "all common attributes.",
+            no_init)
+        .add_property("id", &osmium::OSMObject::id,
+                      "(read-only) OSM id of the object.")
+        .add_property("deleted", &osmium::OSMObject::deleted,
+                      "(read-only) True if the object is no longer visible.")
+        .add_property("visible", &osmium::OSMObject::visible,
+                      "(read-only) True if the object is visible.")
+        .add_property("version", &osmium::OSMObject::version,
+                      "(read-only) Version number of the object.")
+        .add_property("changeset", &osmium::OSMObject::changeset,
+                      "(read-only) Id of changeset where this version of the "
+                      "object was created.")
+        .add_property("uid", &osmium::OSMObject::uid,
+                      "(read-only) Id of the user that created this version "
+                      "of the object. Only this ID uniquely identifies users.")
+        .add_property("timestamp", &osmium::OSMObject::timestamp,
+                      "(read-only) Date when this version has been created, "
+                      "returned as a ``datetime.datetime``.")
+        .add_property("user", &osmium::OSMObject::user,
+                      "(read-only) Name of the user that created this version. "
+                      "Be aware that user names can change, so that the same "
+                      "user ID may appear with different names and vice versa. ")
         .add_property("tags", make_function(&osmium::OSMObject::tags,
-                       return_value_policy<reference_existing_object>()))
-        .def("positive_id", &osmium::OSMObject::positive_id)
+                       return_value_policy<reference_existing_object>()),
+                      "(read-only) List of tags describing the object. "
+                      "See :py:class:`osmium.osm.TagList`.")
+        .def("positive_id", &osmium::OSMObject::positive_id,
+             arg("self"),
+             "Get the absolute value of the id of this object.")
+        .def("user_is_anonymous", &osmium::OSMObject::user_is_anonymous,
+             arg("self"),
+             "Check if the user anonymous. If true, the uid does not uniquely "
+             "identify a single user but only the group of all anonymous users "
+             "in general.")
     ;
-    class_<osmium::Node, bases<osmium::OSMObject>, boost::noncopyable>("Node", no_init)
-        .add_property("location", static_cast<osmium::Location (osmium::Node::*)() const>(&osmium::Node::location))
+    class_<osmium::Node, bases<osmium::OSMObject>, boost::noncopyable>("Node",
+            "Represents a single OSM node. It inherits from OSMObjects and "
+            "adds a single attribute, the location.", no_init)
+        .add_property("location", static_cast<osmium::Location (osmium::Node::*)() const>(&osmium::Node::location),
+                      "The geographic coordinates of the node. "
+                      "See :py:class:`osmium.osm.Location`.")
     ;
-    class_<osmium::Way, bases<osmium::OSMObject>, boost::noncopyable>("Way", no_init)
-        .add_property("nodes", 
+    class_<osmium::Way, bases<osmium::OSMObject>, boost::noncopyable>("Way", 
+        "Represents a OSM way. It inherits the attributes from OSMObjects and "
+        "adds an ordered list of nodes that describes the way.",
+        no_init)
+        .add_property("nodes",
                       make_function(static_cast<const osmium::WayNodeList& (osmium::Way::*)() const>(&osmium::Way::nodes),
-                      return_value_policy<reference_existing_object>()))
-        .def("is_closed", &osmium::Way::is_closed)
-        .def("ends_have_same_id", &osmium::Way::ends_have_same_id)
-        .def("ends_have_same_location", &osmium::Way::ends_have_same_location)
+                      return_value_policy<reference_existing_object>()),
+                      "(read-only) Ordered list of nodes. See :py:class:`osmium.osm.WayNodeList`.")
+        .def("is_closed", &osmium::Way::is_closed, args("self"),
+             "True if the start and end node are the same (synonym for "
+             "``ends_have_same_id``).")
+        .def("ends_have_same_id", &osmium::Way::ends_have_same_id, args("self"),
+             "True if the start and end node are exactly the same.")
+        .def("ends_have_same_location", &osmium::Way::ends_have_same_location,
+             args("self"),
+             "True if the start and end node of the way are at the same location."
+             "Throws an exception if the location of one of the nodes is missing.")
     ;
-    class_<osmium::Relation, bases<osmium::OSMObject>, boost::noncopyable>("Relation", no_init)
+    class_<osmium::Relation, bases<osmium::OSMObject>, boost::noncopyable>("Relation",
+                 "Represents a OSM relation. It inherits the attributes from OSMObjects "
+                 "and adds an ordered list of members.",
+                 no_init)
         .add_property("members", 
                       make_function(static_cast<const osmium::RelationMemberList& (osmium::Relation::*)() const>(&osmium::Relation::members),
-                      return_value_policy<reference_existing_object>()))
+                      return_value_policy<reference_existing_object>()),
+                      "(read-only) Ordered list of relation members. "
+                      "See :py:class:`osmium.osm.RelationMemberList`")
+    ;
+    class_<osmium::Area, bases<osmium::OSMObject>, boost::noncopyable>("Area",
+            "Areas are a special kind of meta-object representing a polygon. "
+            "They can either be derived from closed ways or from relations "
+            "that represent multipolygons. They also inherit the attributes "
+            "of OSMObjects and in addition contain polygon geometries. Areas have "
+            "their own unique id space. This is computed as the OSM id times 2 "
+            "and for relations 1 is added,",
+            no_init)
+        .def("from_way", &osmium::Area::from_way, args("self"),
+             "Return true if the area was created from a way, false if it was "
+             "created from a relation of multipolygon type.")
+        .def("orig_id", &osmium::Area::orig_id, args("self"),
+             "Compute the original OSM id of this object. Note that this is not "
+             "necessarily unique because the object might be a way or relation "
+             "which have an overlapping id space.")
+        .def("is_multipolygon", &osmium::Area::is_multipolygon, args("self"),
+             "Return true if this area is a true multipolygon, i.e. it consists "
+             "of multiple outer rings.")
+        .def("num_rings", &osmium::Area::num_rings, args("self"),
+             "Return a tuple with the number of outer rings and inner rings.")
+        .def("outer_rings", 
+              range<return_internal_reference<> >(
+                &osmium::Area::cbegin<osmium::OuterRing>,
+                &osmium::Area::cend<osmium::OuterRing>),
+             "Return an iterator over all outer rings of the multipolygon.")
+        .def("inner_rings", 
+              range<return_internal_reference<> >(
+                &osmium::Area::cbegin<osmium::InnerRing>,
+                &osmium::Area::cend<osmium::InnerRing>),
+             "Return an iterator over all inner rings of the multipolygon.")
     ;
-    class_<osmium::Area, bases<osmium::OSMObject>, boost::noncopyable>("Area", no_init)
+    class_<osmium::Changeset, boost::noncopyable>("Changeset",
+           "A changeset description.",
+           no_init)
+        .add_property("id", &osmium::Changeset::id,
+                      "(read-only) Unique ID of the changeset.")
+        .add_property("uid", &osmium::Changeset::uid,
+                      "(read-only) User ID of the changeset creator.")
+        .add_property("created_at", &osmium::Changeset::created_at,
+                      "(read-only) Timestamp when the changeset was first opened.")
+        .add_property("closed_at", &osmium::Changeset::closed_at,
+                      "(read-only) Timestamp when the changeset was finalized. May be "
+                      "None when the changeset is still open/")
+        .add_property("open", &osmium::Changeset::open,
+                      "(read-only) True when the changeset is still open.")
+        .add_property("num_changes", &osmium::Changeset::num_changes,
+                      "(read-only) The total number of objects changed in this "
+                      "Changeset.")
+        .add_property("bounds",
+                      make_function(static_cast<const osmium::Box& (osmium::Changeset::*)() const>(&osmium::Changeset::bounds),
+                      return_value_policy<reference_existing_object>()),
+                      "(read-only) The bounding box of the area that was edited.")
+        .add_property("user", &osmium::Changeset::user,
+                      "(read-only) Name of the user that created the changeset. "
+                      "Be aware that user names can change, so that the same "
+                      "user ID may appear with different names and vice versa. ")
+        .add_property("tags", make_function(&osmium::Changeset::tags,
+                       return_value_policy<reference_existing_object>()),
+                      "(read-only) List of tags describing the changeset. "
+                      "See :py:class:`osmium.osm.TagList`.")
+        .def("user_is_anonymous", &osmium::Changeset::user_is_anonymous,
+               arg("self"),
+               "Check if the user anonymous. If true, the uid does not uniquely "
+               "identify a single user but only the group of all anonymous users "
+               "in general.")
     ;
 }
diff --git a/lib/osmium.cc b/lib/osmium.cc
index d160dbe..949f0e5 100644
--- a/lib/osmium.cc
+++ b/lib/osmium.cc
@@ -52,6 +52,7 @@ PyObject* createExceptionClass(const char* name, PyObject* baseTypeObj = PyExc_E
 BOOST_PYTHON_MODULE(_osmium)
 {
     using namespace boost::python;
+    docstring_options doc_options(true, true, false);
 
     invalidLocationExceptionType = createExceptionClass("InvalidLocationError", PyExc_RuntimeError);
     register_exception_translator<osmium::invalid_location>(&translator1);
@@ -64,14 +65,32 @@ BOOST_PYTHON_MODULE(_osmium)
         .def("ignore_errors", &osmium::handler::NodeLocationsForWays<LocationTable>::ignore_errors)
     ;
 
-    class_<SimpleHandlerWrap, boost::noncopyable>("SimpleHandler")
-        .def("node", &BaseHandler::node, &SimpleHandlerWrap::default_node)
-        .def("way", &BaseHandler::way, &SimpleHandlerWrap::default_way)
-        .def("relation", &BaseHandler::relation, &SimpleHandlerWrap::default_relation)
-        .def("changeset", &BaseHandler::changeset, &SimpleHandlerWrap::default_changeset)
-        .def("area", &BaseHandler::area, &SimpleHandlerWrap::default_area)
+    class_<SimpleHandlerWrap, boost::noncopyable>("SimpleHandler",
+        "A handler implements custom processing of OSM data. For each data type "
+        "a callback can be implemented where the object is processed. Note that "
+        "all objects that are handed into the handler are only readable and are "
+        "only valid until the end of the callback is reached. Any data that "
+        "should be retained must be copied into other data structures.")
+        .def("node", &BaseHandler::node, &SimpleHandlerWrap::default_node,
+             (arg("self"), arg("node")),
+             "Handler called for node objects.")
+        .def("way", &BaseHandler::way, &SimpleHandlerWrap::default_way,
+             (arg("self"), arg("way")),
+             "Handler called for way objects. If the geometry of the way is "
+             "needed then ``locations`` must be set to true when calling "
+             "apply_file.")
+        .def("relation", &BaseHandler::relation, &SimpleHandlerWrap::default_relation,
+             (arg("self"), arg("relation")),
+             "Handler called for relation objects.")
+        .def("changeset", &BaseHandler::changeset, &SimpleHandlerWrap::default_changeset,
+             (arg("self"), arg("changeset")),
+             "Handler called for changeset objects.")
+        .def("area", &BaseHandler::area, &SimpleHandlerWrap::default_area,
+             (arg("self"), arg("area")),
+             "Handler called for area objects.")
         .def("apply_file", &SimpleHandlerWrap::apply_file,
-              ("filename", arg("locations")=false, arg("idx")="sparse_mem_array"),
+              (arg("self"), arg("filename"),
+               arg("locations")=false, arg("idx")="sparse_mem_array"),
              "Apply the handler to the given file. If locations is true, then\n"
              "a location handler will be applied before, which saves the node\n"
              "positions. In that case, the type of this position index can be\n"
@@ -80,7 +99,8 @@ BOOST_PYTHON_MODULE(_osmium)
              "handler for assembling multipolygones and areas from ways will\n"
              "be executed.")
     ;
-    def("apply", &apply_reader_simple<BaseHandler>);
+    def("apply", &apply_reader_simple<BaseHandler>,
+        "Apply a chain of handlers.");
     def("apply", &apply_reader_simple<osmium::handler::NodeLocationsForWays<LocationTable>>);
     def("apply", &apply_reader_simple_with_location<LocationTable>);
 }
diff --git a/lib/std_pair.hpp b/lib/std_pair.hpp
new file mode 100644
index 0000000..74fadba
--- /dev/null
+++ b/lib/std_pair.hpp
@@ -0,0 +1,43 @@
+#ifndef PYOSMIUM_STD_PAIR_HPP
+#define PYOSMIUM_STD_PAIR_HPP
+
+// Borrowed from Boost Python examples.
+// Copyright Ralf W. Grosse-Kunstleve 2002-2004. Distributed under the Boost
+// Software License, Version 1.0.
+
+#include <boost/python/module.hpp>
+#include <boost/python/def.hpp>
+#include <boost/python/tuple.hpp>
+#include <boost/python/to_python_converter.hpp>
+
+namespace { // Avoid cluttering the global namespace.
+
+  // Converts a std::pair instance to a Python tuple.
+  template <typename T1, typename T2>
+  struct std_pair_to_tuple
+  {
+    static PyObject* convert(std::pair<T1, T2> const& p)
+    {
+      return boost::python::incref(
+        boost::python::make_tuple(p.first, p.second).ptr());
+    }
+    static PyTypeObject const *get_pytype () {return &PyTuple_Type; }
+  };
+
+  // Helper for convenience.
+  template <typename T1, typename T2>
+  struct std_pair_to_python_converter
+  {
+    std_pair_to_python_converter()
+    {
+      boost::python::to_python_converter<
+        std::pair<T1, T2>,
+        std_pair_to_tuple<T1, T2>,
+        true //std_pair_to_tuple has get_pytype
+        >();
+    }
+  };
+
+} // namespace anonymous
+
+#endif
diff --git a/osmium/__init__.py b/osmium/__init__.py
index f24c2d5..bac8392 100644
--- a/osmium/__init__.py
+++ b/osmium/__init__.py
@@ -1,5 +1,5 @@
 from ._osmium import *
-from . import _io as io
-from . import _osm as osm
-from . import _index as index
-from . import _geom as geom
+import osmium.io
+import osmium.osm
+import osmium.index
+import osmium.geom
diff --git a/osmium/geom/__init__.py b/osmium/geom/__init__.py
new file mode 100644
index 0000000..8cb8e1c
--- /dev/null
+++ b/osmium/geom/__init__.py
@@ -0,0 +1 @@
+from ._geom import *
diff --git a/osmium/index/__init__.py b/osmium/index/__init__.py
new file mode 100644
index 0000000..a9af58a
--- /dev/null
+++ b/osmium/index/__init__.py
@@ -0,0 +1 @@
+from ._index import *
diff --git a/osmium/io/__init__.py b/osmium/io/__init__.py
new file mode 100644
index 0000000..262a731
--- /dev/null
+++ b/osmium/io/__init__.py
@@ -0,0 +1 @@
+from ._io import *
diff --git a/osmium/osm/__init__.py b/osmium/osm/__init__.py
new file mode 100644
index 0000000..7af4485
--- /dev/null
+++ b/osmium/osm/__init__.py
@@ -0,0 +1 @@
+from ._osm import *
diff --git a/setup.py b/setup.py
index b968e4c..ff55d46 100644
--- a/setup.py
+++ b/setup.py
@@ -38,8 +38,18 @@ libs.extend(osmium_libs)
 extensions = []
 extra_compile_args = [ '-std=c++11', '-D_LARGEFILE_SOURCE', '-D_FILE_OFFSET_BITS=64' ]
 
-for ext in ('osmium', 'io', 'osm', 'index', 'geom'):
-    extensions.append(Extension('osmium._%s' % ext,
+extensions.append(Extension('osmium._osmium',
+       sources = ['lib/osmium.cc'],
+       include_dirs = includes,
+       libraries = libs,
+       library_dirs = libdirs,
+       language = 'c++',
+       extra_compile_args = extra_compile_args
+     ))
+packages = ['osmium']
+
+for ext in ('io', 'osm', 'index', 'geom'):
+    extensions.append(Extension('osmium.%s._%s' % (ext, ext),
            sources = ['lib/%s.cc' % ext],
            include_dirs = includes,
            libraries = libs,
@@ -47,11 +57,13 @@ for ext in ('osmium', 'io', 'osm', 'index', 'geom'):
            language = 'c++',
            extra_compile_args = extra_compile_args
          ))
+    packages.append('osmium.%s' % ext)
+
 
 setup (name = 'pyosmium',
        version = '0.1',
        description = 'Provides python bindings for libosmium.',
-       packages = [ 'osmium' ],
+       packages = packages,
        ext_modules = extensions)
 
 
diff --git a/test/test_helper.py b/test/test_helper.py
index 4c05172..fb00777 100644
--- a/test/test_helper.py
+++ b/test/test_helper.py
@@ -9,10 +9,19 @@ def _complete_object(o):
     """Takes a hash with an incomplete OSM object description and returns a
        complete one.
     """
-    ret = { 'version' : '1', 'timestamp': "2012-05-01T15:06:20Z",
-            'changeset' : "11470653", 'uid' : "122294", 'user' : "foo",
-            'tags' : {}
-          }
+    if o['type'] == 'C':
+        ret = { 'created_at' : "2005-04-09T19:54:13Z",
+                'num_changes' : 2, 'closed_at' : "2005-04-09T20:54:39Z",
+                'open' : "false", 'min_lon' : -0.1465242,
+                'min_lat' : 51.5288506, 'max_lon' : -0.1464925,
+                'max_lat' : 51.5288620, 'user' : "Steve", 'uid' : "1",
+                'tags' : None
+        }
+    else:
+        ret = { 'version' : '1', 'timestamp': "2012-05-01T15:06:20Z",
+                'changeset' : "11470653", 'uid' : "122294", 'user' : "foo",
+                'tags' : {}
+        }
     ret.update(o)
     if ret['type'] == 'N':
         if 'lat' not in ret:
@@ -45,6 +54,15 @@ def _write_osm_obj(fd, obj):
         for k,v in iter(obj['tags'].items()):
             fd.write(('  <tag k="%s" v="%s"/>\n' % (k, v)).encode('utf-8'))
         fd.write('</relation>\n'.encode('utf-8'))
+    elif obj['type'] == 'C':
+        fd.write(('<changeset id="%(id)d" created_at="%(created_at)s" num_changes="%(num_changes)d" closed_at="%(closed_at)s" open="%(open)s" min_lon="%(min_lon).8f" min_lat="%(min_lat).8f" max_lon="%(max_lon).8f" max_lat="%(max_lat).8f"  user="%(user)s" uid="%(uid)s"' % obj).encode('utf-8'))
+        if obj['tags'] is None:
+            fd.write('/>\n'.encode('utf-8'))
+        else:
+            fd.write('>\n'.encode('utf-8'))
+            for k,v in iter(obj['tags'].items()):
+                fd.write(('  <tag k="%s" v="%s"/>\n' % (k, v)).encode('utf-8'))
+            fd.write('</changeset>\n'.encode('utf-8'))
 
 
 
@@ -77,12 +95,13 @@ def osmobj(kind, **args):
 
 class HandlerTestBase:
 
+    apply_locations = False
+    apply_idx = 'sparse_mem_array'
+
     def test_func(self):
         fn = create_osm_file(self.data)
         try:
-            rd = osmium.io.Reader(fn)
-            osmium.apply(rd, self.Handler())
-            rd.close()
+            self.Handler().apply_file(fn, self.apply_locations, self.apply_idx)
         finally:
             os.remove(fn)
 
diff --git a/test/test_osm.py b/test/test_osm.py
index ec3b3dd..79fcf96 100644
--- a/test/test_osm.py
+++ b/test/test_osm.py
@@ -1,6 +1,7 @@
 from nose.tools import *
 import unittest
 import os
+from datetime import datetime
 
 from test_helper import create_osm_file, osmobj, HandlerTestBase
 
@@ -32,12 +33,27 @@ class TestNodeAttributes(HandlerTestBase, unittest.TestCase):
             assert_equals(n.changeset, 58674)
             assert_equals(n.uid, 42)
             assert_equals(n.user_is_anonymous(), False)
-            assert_equals(str(n.timestamp), '2014-01-31T06:23:35Z')
+            assert_equals(n.timestamp, datetime(2014, 1, 31, 6, 23, 35))
             assert_equals(n.user, 'anonymous')
-            assert_equals(n.positive_id(), True)
+            assert_equals(n.positive_id(), 1)
+
+
+class TestNodePositiveId(HandlerTestBase, unittest.TestCase):
+    data = [osmobj('N', id=-34, version=5, changeset=58674, uid=42,
+                   timestamp='2014-01-31T06:23:35Z', user='anonymous')]
+
+    class Handler(o.SimpleHandler):
+        def node(self, n):
+            assert_equals(n.positive_id(), 34)
+
 
 class TestWayAttributes(HandlerTestBase, unittest.TestCase):
-    data = [osmobj('W', id=1, version=5, changeset=58674, uid=42,
+
+    apply_locations = True
+
+    data = [osmobj('N', id=1, lat=0, lon=0),
+            osmobj('N', id=3, lat=1, lon=1),
+            osmobj('W', id=1, version=5, changeset=58674, uid=42,
                    timestamp='2014-01-31T06:23:35Z', user='anonymous',
                    nodes = [1,2,3])]
 
@@ -50,9 +66,12 @@ class TestWayAttributes(HandlerTestBase, unittest.TestCase):
             assert_equals(n.changeset, 58674)
             assert_equals(n.uid, 42)
             assert_equals(n.user_is_anonymous(), False)
-            assert_equals(str(n.timestamp), '2014-01-31T06:23:35Z')
+            assert_equals(n.timestamp, datetime(2014, 1, 31, 6, 23, 35))
             assert_equals(n.user, 'anonymous')
-            assert_equals(n.positive_id(), True)
+            assert_equals(n.positive_id(), 1)
+            assert_false(n.is_closed())
+            assert_false(n.ends_have_same_id())
+            assert_false(n.ends_have_same_location())
 
 class TestRelationAttributes(HandlerTestBase, unittest.TestCase):
     data = [osmobj('R', id=1, version=5, changeset=58674, uid=42,
@@ -68,8 +87,61 @@ class TestRelationAttributes(HandlerTestBase, unittest.TestCase):
             assert_equals(n.changeset, 58674)
             assert_equals(n.uid, 42)
             assert_equals(n.user_is_anonymous(), False)
-            assert_equals(str(n.timestamp), '2014-01-31T06:23:35Z')
+            assert_equals(n.timestamp, datetime(2014, 1, 31, 6, 23, 35))
+            assert_equals(n.user, 'anonymous')
+            assert_equals(n.positive_id(), 1)
+
+class TestAreaFromWayAttributes(HandlerTestBase, unittest.TestCase):
+    data = [osmobj('N', id=1, lat=0, lon=0),
+            osmobj('N', id=2, lat=0, lon=1),
+            osmobj('N', id=3, lat=1, lon=0),
+            osmobj('W', id=23, version=5, changeset=58674, uid=42,
+                   timestamp='2014-01-31T06:23:35Z', user='anonymous',
+                   nodes = [1,2,3,1], tags = { "area" : "yes" }),
+           ]
+
+    class Handler(o.SimpleHandler):
+        def area(self, n):
+            assert_equals(n.id, 46)
+            assert_equals(n.deleted, False)
+            assert_equals(n.visible, True)
+            assert_equals(n.version, 5)
+            assert_equals(n.changeset, 58674)
+            assert_equals(n.uid, 42)
+            assert_equals(n.user_is_anonymous(), False)
+            assert_equals(n.timestamp, datetime(2014, 1, 31, 6, 23, 35))
             assert_equals(n.user, 'anonymous')
-            assert_equals(n.positive_id(), True)
+            assert_equals(n.positive_id(), 46)
+            assert_equals(n.orig_id(), 23)
+            assert_equals(n.from_way(), True)
+            assert_equals(n.is_multipolygon(), False)
+            assert_equals(n.num_rings(), (1, 0))
+            assert_equals(len(list(n.outer_rings())), 1)
+            oring = list(n.outer_rings())[0]
+            assert_equals(len(list(oring)), 4)
+            assert_equals(set((1,2,3)), set([x.ref for x in oring]))
+            assert_true(oring.is_closed())
+            assert_true(oring.ends_have_same_id())
+            assert_true(oring.ends_have_same_location())
+            assert_equals(len(list(n.inner_rings())), 0)
 
+class TestChangesetAttributes(HandlerTestBase, unittest.TestCase):
+    data = [osmobj('C', id=34, created_at="2005-04-09T19:54:13Z",
+                num_changes=2, closed_at="2005-04-09T20:54:39Z",
+                open="false", min_lon=-0.1465242,
+                min_lat=51.5288506, max_lon=-0.1464925,
+                max_lat=51.5288620, user="Steve", uid="1")
+           ]
+
+    class Handler(o.SimpleHandler):
+        def changeset(self,c):
+            assert_equals(34, c.id)
+            assert_equals(1, c.uid)
+            assert_false(c.user_is_anonymous())
+            assert_equals("Steve", c.user)
+            assert_equals(datetime(2005, 4, 9, 19, 54, 13), c.created_at)
+            assert_equals(datetime(2005, 4, 9, 20, 54, 39), c.closed_at)
+            assert_false(c.open)
+            assert_equals(2, c.num_changes)
+            assert_equals(0, len(c.tags))
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/pyosmium.git



More information about the Pkg-grass-devel mailing list