Skip to content

Commit

Permalink
Merge 0be9684 into da911cc
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvandenbossche committed Apr 7, 2020
2 parents da911cc + 0be9684 commit f13ee9c
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 35 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ build/
dist/
.coverage
.pytest_cache/

# Sphinx documentation
docs/_build/
docs/*.ipynb
8 changes: 4 additions & 4 deletions contextily/place.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ def plot(self, ax=None, zoom=ZOOM, interpolation=INTERPOLATION, attribution=None
Plot a `Place` object
...
Arguments
---------
Parameters
----------
ax : AxesSubplot
Matplotlib axis with `x_lim` and `y_lim` set in Web
Mercator (EPSG=3857). If not provided, a new
Expand Down Expand Up @@ -149,8 +149,8 @@ def plot(self, ax=None, zoom=ZOOM, interpolation=INTERPOLATION, attribution=None
Matplotlib axis with `x_lim` and `y_lim` set in Web
Mercator (EPSG=3857) containing the basemap
Example
-------
Examples
--------
>>> lvl = ctx.Place('Liverpool')
>>> lvl.plot()
Expand Down
15 changes: 7 additions & 8 deletions contextily/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@ def add_basemap(
resampling=Resampling.bilinear,
**extra_imshow_args):
"""
Add a (web/local) basemap to `ax`
...
Add a (web/local) basemap to `ax`.
Arguments
---------
Parameters
----------
ax : AxesSubplot
Matplotlib axis with `x_lim` and `y_lim` set in Web
Mercator (EPSG=3857)
Expand Down Expand Up @@ -75,8 +74,8 @@ def add_basemap(
**extra_imshow_args :
Other parameters to be passed to `imshow`.
Example
-------
Examples
--------
>>> db = gpd.read_file(ps.examples.get_path('virginia.shp'))\
.to_crs(epsg=3857)
Expand Down Expand Up @@ -160,8 +159,8 @@ def add_attribution(ax, text, font_size=ATTRIBUTION_SIZE, **kwargs):
"""
Utility to add attribution text.
Arguments
---------
Parameters
----------
ax : AxesSubplot
Matplotlib axis with `x_lim` and `y_lim` set in Web
Mercator (EPSG=3857)
Expand Down
38 changes: 15 additions & 23 deletions contextily/tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@ def bounds2raster(
Take bounding box and zoom, and write tiles into a raster file in
the Spherical Mercator CRS (EPSG:3857)
...
Arguments
---------
Parameters
----------
w : float
West edge
s : float
Expand Down Expand Up @@ -124,10 +122,8 @@ def bounds2img(w, s, e, n, zoom="auto", url=None, ll=False, wait=0, max_retries=
Take bounding box and zoom and return an image with all the tiles
that compose the map and its Spherical Mercator extent.
...
Arguments
---------
Parameters
----------
w : float
West edge
s : float
Expand Down Expand Up @@ -246,10 +242,9 @@ def warp_tiles(img, extent, t_crs="EPSG:4326", resampling=Resampling.bilinear):
NOTE: this method works well with contextily's `bounds2img` approach to
raster dimensions (h, w, b)
...
Arguments
---------
Parameters
----------
img : ndarray
Image as a 3D array (h, w, b) of RGB values (e.g. as
returned from `contextily.bounds2img`)
Expand All @@ -261,7 +256,7 @@ def warp_tiles(img, extent, t_crs="EPSG:4326", resampling=Resampling.bilinear):
format permitted by rasterio. Defaults to WGS84 (lon/lat)
resampling : <enum 'Resampling'>
[Optional. Default=Resampling.bilinear] Resampling method for
executing warping, expressed as a `rasterio.enums.Resampling
executing warping, expressed as a `rasterio.enums.Resampling`
method
Returns
Expand Down Expand Up @@ -296,11 +291,10 @@ def warp_img_transform(img, transform, s_crs, t_crs, resampling=Resampling.bilin
different `t_crs`
NOTE: this method works well with rasterio's `.read()` approach to
raster's dimensions (b, h, w)
...
raster's dimensions (b, h, w)
Arguments
---------
Parameters
----------
img : ndarray
Image as a 3D array (b, h, w) of RGB values (e.g. as
returned from rasterio's `.read()` method)
Expand All @@ -314,7 +308,7 @@ def warp_img_transform(img, transform, s_crs, t_crs, resampling=Resampling.bilin
Target CRS, expressed in any format permitted by rasterio.
resampling : <enum 'Resampling'>
[Optional. Default=Resampling.bilinear] Resampling method for
executing warping, expressed as a `rasterio.enums.Resampling
executing warping, expressed as a `rasterio.enums.Resampling`
method
Returns
Expand Down Expand Up @@ -395,10 +389,9 @@ def _retryer(tile_url, wait, max_retries):
def howmany(w, s, e, n, zoom, verbose=True, ll=False):
"""
Number of tiles required for a given bounding box and a zoom level
...
Arguments
---------
Parameters
----------
w : float
West edge
s : float
Expand Down Expand Up @@ -431,10 +424,9 @@ def howmany(w, s, e, n, zoom, verbose=True, ll=False):
def bb2wdw(bb, rtr):
"""
Convert XY bounding box into the window of the tile raster
...
Arguments
---------
Parameters
----------
bb : tuple
(left, bottom, right, top) in the CRS of `rtr`
rtr : RasterReader
Expand Down
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
80 changes: 80 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

import os
import pathlib
import shutil


# -- Path setup --------------------------------------------------------------

# 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.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))


# -- Project information -----------------------------------------------------

project = 'contextily'
copyright = '2020, Dani Arribas-Bel & Contexily Contributors'
author = 'Dani Arribas-Bel & Contexily Contributors'

# The full version, including alpha/beta/rc tags
release = '1.0.0'


# -- General configuration ---------------------------------------------------

# 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",
"numpydoc",
"nbsphinx"
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']


# -- 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 = 'alabaster'

# 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']


# ---------------------------------------------------------------------------

# Copy notebooks into the docs/ directory so sphinx sees them

HERE = pathlib.Path(os.path.abspath(os.path.dirname(__file__)))


notebooks = [
"contextily_guide.ipynb",
"warping_guide.ipynb",
]


for notebook in notebooks:
shutil.copy(HERE / ".." / notebook, HERE)
23 changes: 23 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.. contextily documentation master file, created by
sphinx-quickstart on Tue Apr 7 15:16:59 2020.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to contextily's documentation!
======================================

.. toctree::
:maxdepth: 2
:caption: Contents:

contextily_guide
warping_guide
reference


Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build

if "%1" == "" goto help

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
36 changes: 36 additions & 0 deletions docs/reference.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
.. _reference:

Reference Guide
===============

Plotting basemaps
-----------------

.. autofunction:: contextily.add_basemap

.. autofunction:: contextily.add_attribution


Working with tiles
------------------

.. autofunction:: contextily.bounds2raster

.. autofunction:: contextily.bounds2img

.. autofunction:: contextily.warp_tiles

.. autofunction:: contextily.warp_img_transform

.. autofunction:: contextily.howmany


Geocoding and plotting places
-----------------------------

.. autoclass:: contextily.Place

.. automethod:: contextily.Place.plot

.. autofunction:: contextily.plot_map

0 comments on commit f13ee9c

Please sign in to comment.