Package: tilecloud
TileCloudA powerful utility for generating, managing, transforming, and visualizing map tiles in multiple formats.IntroductionTileCloud is a powerful utility for generating, managing, transforming, visualizing and map tiles in multiple
formats. It can create, read update, delete tiles in multiple back ends, called TileStores. Existing
TileStores include:HTTP/REST in any layoutWMTSAmazonS3andSQSMBTilesTileJSONMapnik(viamapnik2)MemcachedLocal file systemLog files in any formatTileCloud is not limited to image tiles, it can also handle other tile data such asUTFGrid, or elevation data in JSON format.TileCloud uses Python's generators and iterators to efficiently stream tens of millions of tiles, and can
handle multiple tiles in parallel using Python'smultiprocessinglibrary.Example tasks that TileCloud makes easy include:Visualize tiles stored in any TileStore withOpenLayers,Google
Maps,jQuery Geo,Leaflet,Polymaps,Modest
Maps, andOpenWebGlobe.Convert sixty million PNG tiles stored in S3 to JPEG format with different quality settings at different
zoom levels.Transform image formats and perform arbitrary image transformations on the fly, including PNG
optimization.Generate semi-transparent tiles with embedded tile coordinates for debugging.Pack multiple tile layers into a single tile on the server.Efficiently calculate bounding boxes and detect missing tiles in existing tile datasets.Simulate fast and slow tile servers.Efficiently delete millions of tiles in S3.Read JSON tiles from a tarball, compress them, and upload them.Getting startedTileCloud depends on some Python modules. It's easiest to install them withpipin avirtualenv:$ python3 -m venv .venv
$ . .venv/bin/activate
$ pip install -r requirements.txtFor a quick demo, run$ ./tc-viewer --root=3/4/2 'http://gsp2.apple.com/tile?api=1&style=slideshow&layers=default&lang=en_GB&z=%(z)d&x=%(x)d&y=%(y)d&v=9'and point your browser athttp://localhost:8080/. TypeCtrl-Cto terminatetc-viewer.Next, download an example MBTiles file fromMapBox, such asGeography
Class. We can quickly find out more about this tile set
with thetc-infocommand. For example, to count the number of tiles:$ ./tc-info -t count geography-class.mbtiles
87381To calculate the bounding pyramid:$ ./tc-info -t bounding-pyramid -r geography-class.mbtiles
0/0/0:+1/+1
1/0/0:+2/+2
2/0/0:+4/+4
3/0/0:+8/+8
4/0/0:+16/+16
5/0/0:+32/+32
6/0/0:+64/+64
7/0/0:+128/+128
8/0/0:+256/+256To check for missing tiles against a bounding pyramid:$ ./tc-info -b 0/0/0:8/*/* -t completion geography-class.mbtiles
0 1/1 (100%)
1 4/4 (100%)
2 16/16 (100%)
3 64/64 (100%)
4 256/256 (100%)
5 1024/1024 (100%)
6 4096/4096 (100%)
7 16384/16384 (100%)
8 65536/65536 (100%)This shows, for each zoom level, the number of tiles at that zoom level, the total number of tiles expected at
that zoom level for the specified bounding pyramid (0/0/0:8/*/*means all tiles from level 0 to level 8),
and a percentage completion. This can be useful for checking that a tile set is complete.Now, display this MBTiles tile set on top of theOpenStreetMaptiles and a
debug tile layer:$ ./tc-viewer tiles.openstreetmap_org geography-class.mbtiles tiles.debug.blackYou'll need to point your browser athttp://localhost:8080/and choose your favorite library.tc-infoandtc-viewerare utility programs. Normally you use TileCloud by writing short Python programs
that connect the TileCloud's modules to perform the action that you want.As a first example, run the following:$ PYTHONPATH=. examples/download.pyThis will download a few tiles fromOpenStreetMapand save them in a local
MBTiles file calledlocal.mbtiles. Look at the source code toexamples/download.pyto see how it works. If
there are problems with the download, just interrupt it withCtrl-Cand re-run it: the program will
automatically resume where it left off.Once you have downloaded a few tiles, you can view them directly withtc-viewer:$ ./tc-viewer --root=4/8/5 local.mbtiles tiles.debug.blackPoint your browser athttp://localhost:8080as usual. The--rootoption totc-viewerinstructs the
viewer to start at a defined tile, rather than at 0/0/0, so you don't have to zoom in to find the tiles that
you downloaded.Changelog1.9.0Add the following extra dependenciesazure,aws,wsgi,redis,all.Tile coordinates, tile layouts, tile grids and bounding pyramidsTileCloud always represents tile coordinates as strings likez/x/y. TileCloud primarily works in tile
coordinates, although geographic coordinates can be used in some places.Tile layouts convert tile coordinates to and from strings for use in paths, URLs, keys, etc.Tile grids are used to convert tile coordinates to and from geographic coordinates, and to relate tiles with
different z values.Bounding pyramids represent a range of tiles in the x, y and z directions. The format is basicallyminz/minx/miny:maxz/maxx/maxybutmaxzis optional andmaxz,maxxandmaxycan be prefixed with an+sign to indicate that they are relative to the correspondingminvalue. This is probably best
demonstrated by a few examples:4/10/20:15/25: This corresponds to a range of tiles with z=4, x=10..15 and y=20..254/10/20:+5/+5: This is the same range (z=4, x=10..15, y=20..25) but expressed using relative sizes.4/10/20:5/15/20: This is the same range of tiles above, but also includes all the tiles at level z=5 which overlap the
above range. TileCloud uses the tile grid to calculate which tiles from level z=5 to include.4/10/20:+1/+5/+5: This represents the range same as the previous example using a relativemaxz.Quick tile generationThetc-copycommand can be used to copy tiles between different TileStores. If a TileStore has the side
effect of generating tiles, then it functions as a quick tile generation utility. First, some quick examples.To convert from one tile format to another, just copy from source to destination. For example, to convert an
MBTiles file in to a ZIP file, just run:$ ./tc-copy geography-class.mbtiles geography-class.zipYou can check this worked withunzip:$ unzip -t geography-class.zipEqually,tc-copycan be used to download multiple tiles:$ ./tc-copy --bounding-pyramid 4/0/0:0/16/16 tiles.openstreetmap_org osm-up-to-z4.mbtilesHere we downloaded zoom levels 0 to 4 of the OpenStreetMap tiles into a local MBTiles file. The--bounding-pyramidoption is required because otherwise we would downloadallOpenStreetMap tiles -- which
might take some time (and also contravene OpenStreetMap's tile usage policy). Note that, by default,tc-copywon't overwrite tiles if they already exist in the destination. This means that you can interrupt the above
command and restart it, and it will resume where it was interrupted. If you want to overwrite tiles in the
destination then pass the--overwriteoption totc-copy.In the same way,tc-copycan also be used to upload tiles. For example, to upload an MBTiles file to S3,
just use:$ ./tc-copy osm-up-to-z4.mbtiles s3://bucket/prefix/%(z)d/%(x)d/%(y)d.jpgbucketis the name of your S3 bucket. You'll need to have set theAWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEYenvironment variables to have permission to upload to S3. The rest of the destination
(prefix/%(z)d/%(x)d/%(y)d.jpg) is a template describing the layout of the tiles in S3. It's a normal Python
format string:%(x)dmeans substitute the tile'sxcoordinate as a decimal integer.You can pass the sames3://URL totc-viewer. This allows you to visualize your tiles stored in S3 with
your favorite mapping library. For example:$ ./tc-viewer s3://bucket/prefix/%(z)d/%(x)d/%(y)d.jpgHere,tc-vieweris acting as a proxy, serving tiles stored in S3 over HTTP, bypassing any caches or access
controls (assuming you have the correct credentials, of course). This allows you to visualize the exact tiles
that you've stored.Rendering the WorldAtFOSS4G-NA,MapBoxpresented an excellent strategy forrendering the world. TileCloud supports the subdivision
strategy. To run the demo, execute:$ python examples/renderingtheworld.pyThis will generate tiles from a WMTS tile server and save them in a local MBTiles tiles. When the above
command is complete, you can see the bounding pyramid of the generated tiles:$ ./tc-info -t bounding-pyramid -r medford_buildings.mbtiles
0/0/0:+1/+1
1/0/0:+1/+1
2/0/1:+1/+1
3/1/2:+1/+1
4/2/5:+1/+1
5/5/11:+1/+1
6/10/23:+1/+1
7/20/47:+1/+1
8/40/94:+2/+2
9/80/189:+2/+1
10/162/378:+1/+2
11/324/757:+2/+2
12/649/1514:+3/+3
13/1299/3028:+4/+5
14/2598/6057:+7/+8
15/5196/12114:+13/+15You can look at these tiles (which show buildings in Medford, OR) with the command:./tc-viewer --root=7/20/47 tiles.openstreetmap_org medford_buildings.mbtilesA cheap-and-cheerful tile servertc-viewercan be used as a lightweight tile server, which can be useful for development, debugging and
off-line demos. The TileStores passed as arguments totc-viewerare available at the URL:http://localhost:8080/tiles/{index}/tiles/{z}/{x}/{y}where{index}is the index of the TileStore on the command line (starting from 0 for the first tile store),
and{z},{x}and{y}are the components of the tile coordinate. The secondtilesin the URL is present
to work around assumptions made by OpenWebGlobe. This layout is directly usable by most mapping libraries, see
the code inviews/*.tplfor examples. The host and port can be set with the--hostand--portcommand
line options, respectively.Note that there is no file extension.tc-viewerwill automatically set the correct content type and content
encoding headers if it can determine them, and, failing this, most browsers will figure it out for themselves.For convenience,tc-viewerserves everything in thestaticdirectory under the URL/static. This can be
used to serve your favorite mapping library and/or application code directly for testing purposes.By default,tc-viewerwill useTornadoas a web server, if it is available,
otherwise it will fall back toWSGIRef. Tornado has reasonably
good performance, and is adequate for local development and off-line demos, especially when used with a
MBTiles TileStore. WSGIRef has very poor performance (it handles only one request at a time) and as such can
be used as a "slow" tile server, ideal for debugging tile loading code or testing how your web application
performs over a slow network connection.tc-vieweris particularly slow when used to proxy tiles being
served by a remote server. You can set the server explicitly with the--serveroption.tc-viewersets theAccess-Control-Allow-Originheader to*for all the tiles it serves, this allows the
tiles to be used as textures for WebGL applications running on different hosts/ports. For more information,
seeCross-Domain Textures.tc-vieweris designed as a development tool, and the power that it offers comes at the expense of fragility.
It makes many assumptions - including the benevolence of the user - that make it entirely unsuitable as a
generic tile server. It should only be used in development or demonstration environments.Comparing mapping librariestc-viewersupports most popular web mapping libraries out-of-the box. This can be very useful for quick,
practical comparisons. If your favorite mapping library is missing, please submit anissue, or, even better, apull
request.ContributingPlease report bugs and feature requests using theGitHub issue
tracker.If you'd like to contribute to TileCloud, please install the development requirements:$ pip install -r dev-requirements.txtTileCloud comes with unit tests in thetilecloud/testsdirectory. You can run these with the command:$ make testThis is equivalent to:$ python setup.py nosetestsFor pull requests, it is very much appreciated if your code passesprospectorwithout warnings. You can run
prospector on the codebase with the command:$ make prospectorLicenseCopyright (c) 2012, Tom Paynetwpayne@gmail.comAll rights reserved.
Copyright (c) 2012, Camptocamp All rights reserved.Redistribution and use in source and binary forms, with or without modification, are permitted provided that
the following conditions are met:Redistributions of source code must retain the above copyright notice, this list of conditions and the
following disclaimer.Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other materials provided with the distribution.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.vim: set filetype=rst spell spelllang=en textwidth=0:ContributingInstall the pre-commit hooks:pipinstallpre-commit
pre-commitinstall--allow-missing-config