*Landez* manipulates tiles, builds MBTiles, does tiles compositing and arrange tiles together into single images.
Tiles can either be obtained from a remote tile service URL, from a local Mapnik stylesheet,
a WMS server or from MBTiles files.
For building MBTiles, Landez embeds *mbutil* from Mapbox https://github.com/mapbox/mbutil at the final stage.
The land covered is specified using a list of bounding boxes and zoom levels.
.. image:: https://pypip.in/v/landez/badge.png
:target: https://pypi.python.org/pypi/landez
.. image:: https://pypip.in/d/landez/badge.png
:target: https://pypi.python.org/pypi/landez
.. image:: https://travis-ci.org/makinacorpus/landez.png
:target: https://travis-ci.org/makinacorpus/landez
.. image:: https://coveralls.io/repos/makinacorpus/landez/badge.png
:target: https://coveralls.io/r/makinacorpus/landez
=======
INSTALL
=======
*Landez* is pure python and has no external dependency. ::
sudo easy_install landez
However, it requires `mapnik` if the tiles are rendered locally. ::
sudo aptitude install python-mapnik
And `PIL` to blend tiles together or export arranged tiles into images. ::
sudo aptitude install python-imaging
=====
USAGE
=====
Building MBTiles files
======================
Remote tiles
------------
Using a remote tile service (OpenStreetMap.org by default):
::
import logging
from landez import MBTilesBuilder
logging.basicConfig(level=logging.DEBUG)
mb = MBTilesBuilder(cache=False)
mb.add_coverage(bbox=(-180.0, -90.0, 180.0, 90.0),
zoomlevels=[0, 1])
mb.run()
Please respect `Tile usage policies <http://wiki.openstreetmap.org/wiki/Tile_usage_policy>`
Local rendering
---------------
Using mapnik to render tiles:
::
import logging
from landez import MBTilesBuilder
logging.basicConfig(level=logging.DEBUG)
mb = MBTilesBuilder(stylefile="yourstyle.xml", filepath="dest.mbtiles")
mb.add_coverage(bbox=(-180.0, -90.0, 180.0, 90.0),
zoomlevels=[0, 1])
mb.run()
And with UTFGrids:
::
import logging
from landez import MBTilesBuilder
logging.basicConfig(level=logging.DEBUG)
mb = MBTilesBuilder(stylefile="yourstyle.xml",
grid_fields=["field1", "field2", "field3", ...] ,
filepath="dest.mbtiles")
mb.add_coverage(bbox=(-180, -90, 180, 90),
zoomlevels=[0, 1, 2, 3])
mb.run()
From an other MBTiles file
--------------------------
::
import logging
from landez import MBTilesBuilder
logging.basicConfig(level=logging.DEBUG)
mb = MBTilesBuilder(mbtiles_file="yourfile.mbtiles", filepath="dest.mbtiles")
mb.add_coverage(bbox=(-180.0, -90.0, 180.0, 90.0),
zoomlevels=[0, 1])
mb.run()
From a WMS server
-----------------
::
mb = MBTilesBuilder(wms_server="http://yourserver.com/geoserver/wms",
wms_layers=["ign:departements"],
wms_options=dict(format="image/png",
transparent=True),
filepath="dest.mbtiles")
mb.add_coverage(bbox=([-0.9853,43.6435.1126,44.0639]))
mb.run()
Blend tiles together
====================
Merge multiple sources of tiles (URL, WMS, MBTiles, Mapnik stylesheet) together. *(requires python PIL)*
For example, build a new MBTiles by blending tiles of a MBTiles on top of OpenStreetMap tiles :
::
mb = MBTilesBuilder(filepath="merged.mbtiles")
overlay = TilesManager(mbtiles_file="carto.mbtiles")
mb.add_layer(overlay)
mb.run()
Or composite a WMS layer with OpenStreetMap using transparency (40%):
::
mb = MBTilesBuilder(wms_server="http://yourserver.com/geoserver/wms",
wms_layers=["img:orthophoto"])
overlay = TilesManager(remote=True)
mb.add_layer(overlay, 0.4)
mb.run()
Export Images
=============
Assemble and arrange tiles together into a single image. *(requires python PIL)*
Specify tiles sources in the exact same way as for building MBTiles files.
::
import logging
from landez import ImageExporter
logging.basicConfig(level=logging.DEBUG)
ie = ImageExporter(mbtiles_file="yourfile.mbtiles")
ie.export_image(bbox=(-180.0, -90.0, 180.0, 90.0), zoomlevel=3, imagepath="image.png")
Add post-processing filters
===========================
Convert map tiles to gray scale, more suitable for information overlay :
::
from landez.filters import GrayScale
ie = ImageExporter()
ie.add_filter(GrayScale())
Replace a specific color by transparent pixels (i.e. color to alpha, *a-la-Gimp*) :
::
from landez.filters import ColorToAlpha
overlay = TileManager()
overlay.add_filter(ColorToAlpha('#ffffff')) # white will be transparent
ie = ImageExporter()
ie.add_layer(overlay)
...
Extract MBTiles content
=======================
::
from landez.sources import MBTilesReader
mbreader = MBTilesReader("yourfile.mbtiles")
# Metadata
print mbreader.metadata()
# Zoom levels
print mbreader.zoomlevels()
# Image tile
with open('tile.png', 'wb') as out:
out.write(mbreader.tile(z, x, y))
# UTF-Grid tile
print mbreader.grid(z, x, y, 'callback')
Manipulate tiles
================
::
from landez import MBTilesBuilder
# From a TMS tile server
# tm = TilesManager(tiles_url="http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png")
# From a MBTiles file
tm = TilesManager(mbtiles_file="yourfile.mbtiles")
tiles = tm.tileslist(bbox=(-180.0, -90.0, 180.0, 90.0),
zoomlevels=[0, 1])
for tile in tiles:
tilecontent = tm.tile(tile) # download, extract or take from cache
...
Cache tiles are stored using TMS scheme by default (with ``y`` value flipped). It can be changed to WMTS (a.k.a ``xyz``) :
::
tm = TilesManager(your_sources_options, cache=True, cache_scheme="wmts")
Run tests
=========
Run tests with nosetests (if you are working in a virtualenv, don't forget to install nose in it!):
::
cd landez
nosetests
The Mapnik stylesheet for the test about grid content comes from <https://github.com/springmeyer/gridsforkids>
=======
AUTHORS
=======
* Mathieu Leplatre <mathieu.leplatre@makina-corpus.com>
* Sergej Tatarincev
* Éric Bréhault
* Waldemar Osuch
* Isabelle Vallet
* Thanks to mbutil authors <https://github.com/mapbox/mbutil>
.. image:: http://depot.makina-corpus.org/public/logo.gif
:target: http://www.makina-corpus.com
=======
LICENSE
=======
* Lesser GNU Public License
=========
CHANGELOG
=========
2.5.0 (2019-04-16)
==================
* Add support of Python 3.
2.4.1 (2019-03-13)
==================
* Do not try to get tiles again when tiles doesn't exist.
2.4.0 (2017-03-02)
==================
* Do not crash when overlay tile data is not a valid image
* Correctly generate metadata for zoom levels
* Add support for tms mbtiles
* Correct tile box calculation for case when floating point value is an integer
* Correctly generate metadata for zoom levels
* Use the full path to construct the cache directory, as otherwise different
tiles sets on the same server are considered to be the same one
* Added a name metadata to prevent Maptiler crash
2.3.0 (2014-11-18)
==================
* Add headers to WMS sources if specified (thanks @sempixel!)
2.2.0 (2014-09-22)
==================
* Add delay between tiles downloads retries (by @kiorky)
* Add option to ignore errors during MBTiles creation (e.g. download errors)
2.1.1 (2013-08-27)
==================
* Do not hard-code ``grid();`` JSONP callback.
2.1.0 (2013-08-27)
==================
* Add TMS support (ebrehault)
* Add default subdomains argument for TileSource
* Add ability to set HTTP headers for tiles
* Fix file corruption on Windows (by @osuchw)
2.0.3 (2013-05-03)
==================
* Fix Mapnik signature on render()
2.0.2 (2012-06-21)
==================
* Prevent the whole image to be converted to grayscale
* Explicitly check http status code at tiles download
2.0.1 (2012-05-29)
==================
* Fix infinite loop on blending layers
2.0.0 (2012-05-25)
==================
* Rework cache mechanism
* Jpeg tiles support (#14)
* Remove use of temporary files
* Image post-processing (#11)
2.0.0-alpha (2012-05-23)
========================
* Refactoring of whole stack
1.8.2 (2012-03-27)
==================
* Fix Mapnik rendering
1.8.1 (2012-02-24)
==================
* Fix MBTiles cache cleaning
1.8 (2012-02-24)
================
* WMS support
* Tiles compositing
1.7 (2012-02-17)
================
* Catch Sqlite exceptions
1.6 (2012-02-08)
================
* UTF-Grid support for MBTiles files
1.5 (2011-12-07)
================
* Subdomain support for tiles servers
* Low level tiles manipulation
* Use i18n
1.4 (2011-10-17)
================
* Remove extra logging message of mbutil
1.3 (2011-09-23)
================
* Export set of tiles into single image
1.2 (2011-06-21)
================
* Raise exception if no tiles in coverages
1.1 (2012-04-18)
================
* Move internals to landez module
* Split projection into separate module
1.0 (2011-04-18)
================
* Initial working version
Raw data
{
"_id": null,
"home_page": "https://github.com/makinacorpus/landez/",
"name": "landez",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "MBTiles,Mapnik",
"author": "Mathieu Leplatre",
"author_email": "mathieu.leplatre@makina-corpus.com",
"download_url": "https://files.pythonhosted.org/packages/39/6b/911371692e259223e371a4f5137a4c4a445943da0ae7bed105cd25d5c575/landez-2.5.0.tar.gz",
"platform": "",
"description": "*Landez* manipulates tiles, builds MBTiles, does tiles compositing and arrange tiles together into single images.\n\nTiles can either be obtained from a remote tile service URL, from a local Mapnik stylesheet,\na WMS server or from MBTiles files.\n\nFor building MBTiles, Landez embeds *mbutil* from Mapbox https://github.com/mapbox/mbutil at the final stage.\nThe land covered is specified using a list of bounding boxes and zoom levels.\n\n\n.. image:: https://pypip.in/v/landez/badge.png\n :target: https://pypi.python.org/pypi/landez\n\n.. image:: https://pypip.in/d/landez/badge.png\n :target: https://pypi.python.org/pypi/landez\n\n.. image:: https://travis-ci.org/makinacorpus/landez.png\n :target: https://travis-ci.org/makinacorpus/landez\n\n.. image:: https://coveralls.io/repos/makinacorpus/landez/badge.png\n :target: https://coveralls.io/r/makinacorpus/landez\n\n\n=======\nINSTALL\n=======\n\n*Landez* is pure python and has no external dependency. ::\n\n sudo easy_install landez\n\nHowever, it requires `mapnik` if the tiles are rendered locally. ::\n\n sudo aptitude install python-mapnik\n\nAnd `PIL` to blend tiles together or export arranged tiles into images. ::\n\n sudo aptitude install python-imaging\n\n=====\nUSAGE\n=====\n\nBuilding MBTiles files\n======================\n\nRemote tiles\n------------\n\nUsing a remote tile service (OpenStreetMap.org by default):\n::\n\n import logging\n from landez import MBTilesBuilder\n\n logging.basicConfig(level=logging.DEBUG)\n \n mb = MBTilesBuilder(cache=False)\n mb.add_coverage(bbox=(-180.0, -90.0, 180.0, 90.0), \n zoomlevels=[0, 1])\n mb.run()\n\nPlease respect `Tile usage policies <http://wiki.openstreetmap.org/wiki/Tile_usage_policy>`\n\nLocal rendering\n---------------\n\nUsing mapnik to render tiles:\n\n::\n\n import logging\n from landez import MBTilesBuilder\n \n logging.basicConfig(level=logging.DEBUG)\n \n mb = MBTilesBuilder(stylefile=\"yourstyle.xml\", filepath=\"dest.mbtiles\")\n mb.add_coverage(bbox=(-180.0, -90.0, 180.0, 90.0),\n zoomlevels=[0, 1])\n mb.run()\n\n\nAnd with UTFGrids:\n\n::\n\n import logging\n from landez import MBTilesBuilder\n \n logging.basicConfig(level=logging.DEBUG)\n \n mb = MBTilesBuilder(stylefile=\"yourstyle.xml\",\n grid_fields=[\"field1\", \"field2\", \"field3\", ...] ,\n filepath=\"dest.mbtiles\")\n mb.add_coverage(bbox=(-180, -90, 180, 90),\n zoomlevels=[0, 1, 2, 3])\n mb.run()\n\n\nFrom an other MBTiles file\n--------------------------\n::\n\n import logging\n from landez import MBTilesBuilder\n \n logging.basicConfig(level=logging.DEBUG)\n \n mb = MBTilesBuilder(mbtiles_file=\"yourfile.mbtiles\", filepath=\"dest.mbtiles\")\n mb.add_coverage(bbox=(-180.0, -90.0, 180.0, 90.0), \n zoomlevels=[0, 1])\n mb.run()\n\n\nFrom a WMS server\n-----------------\n::\n\n mb = MBTilesBuilder(wms_server=\"http://yourserver.com/geoserver/wms\", \n wms_layers=[\"ign:departements\"], \n wms_options=dict(format=\"image/png\", \n transparent=True),\n filepath=\"dest.mbtiles\")\n mb.add_coverage(bbox=([-0.9853,43.6435.1126,44.0639]))\n mb.run()\n\n\n\nBlend tiles together\n====================\n\nMerge multiple sources of tiles (URL, WMS, MBTiles, Mapnik stylesheet) together. *(requires python PIL)*\n\nFor example, build a new MBTiles by blending tiles of a MBTiles on top of OpenStreetMap tiles :\n\n::\n\n mb = MBTilesBuilder(filepath=\"merged.mbtiles\")\n overlay = TilesManager(mbtiles_file=\"carto.mbtiles\")\n mb.add_layer(overlay)\n mb.run()\n\nOr composite a WMS layer with OpenStreetMap using transparency (40%):\n\n:: \n\n mb = MBTilesBuilder(wms_server=\"http://yourserver.com/geoserver/wms\", \n wms_layers=[\"img:orthophoto\"])\n overlay = TilesManager(remote=True)\n mb.add_layer(overlay, 0.4)\n mb.run()\n\n\nExport Images\n=============\n\nAssemble and arrange tiles together into a single image. *(requires python PIL)*\n\nSpecify tiles sources in the exact same way as for building MBTiles files.\n\n::\n\n import logging\n from landez import ImageExporter\n \n logging.basicConfig(level=logging.DEBUG)\n \n ie = ImageExporter(mbtiles_file=\"yourfile.mbtiles\")\n ie.export_image(bbox=(-180.0, -90.0, 180.0, 90.0), zoomlevel=3, imagepath=\"image.png\")\n\n\nAdd post-processing filters\n===========================\n\nConvert map tiles to gray scale, more suitable for information overlay :\n\n::\n\n from landez.filters import GrayScale\n \n ie = ImageExporter()\n ie.add_filter(GrayScale())\n\nReplace a specific color by transparent pixels (i.e. color to alpha, *a-la-Gimp*) :\n\n::\n\n from landez.filters import ColorToAlpha\n \n overlay = TileManager()\n overlay.add_filter(ColorToAlpha('#ffffff')) # white will be transparent\n \n ie = ImageExporter()\n ie.add_layer(overlay)\n ...\n\n\nExtract MBTiles content\n=======================\n\n:: \n\n from landez.sources import MBTilesReader\n \n mbreader = MBTilesReader(\"yourfile.mbtiles\")\n \n # Metadata\n print mbreader.metadata()\n \n # Zoom levels\n print mbreader.zoomlevels()\n \n # Image tile\n with open('tile.png', 'wb') as out:\n out.write(mbreader.tile(z, x, y))\n \n # UTF-Grid tile\n print mbreader.grid(z, x, y, 'callback')\n\n\n\nManipulate tiles\n================\n\n::\n\n from landez import MBTilesBuilder\n \n # From a TMS tile server\n # tm = TilesManager(tiles_url=\"http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png\")\n \n # From a MBTiles file\n tm = TilesManager(mbtiles_file=\"yourfile.mbtiles\")\n \n tiles = tm.tileslist(bbox=(-180.0, -90.0, 180.0, 90.0), \n zoomlevels=[0, 1])\n for tile in tiles:\n tilecontent = tm.tile(tile) # download, extract or take from cache\n ...\n\nCache tiles are stored using TMS scheme by default (with ``y`` value flipped). It can be changed to WMTS (a.k.a ``xyz``) :\n\n::\n\n tm = TilesManager(your_sources_options, cache=True, cache_scheme=\"wmts\")\n\n\nRun tests\n=========\n\nRun tests with nosetests (if you are working in a virtualenv, don't forget to install nose in it!):\n\n::\n \n cd landez\n nosetests\n\nThe Mapnik stylesheet for the test about grid content comes from <https://github.com/springmeyer/gridsforkids>\n\n\n=======\nAUTHORS\n=======\n\n * Mathieu Leplatre <mathieu.leplatre@makina-corpus.com>\n * Sergej Tatarincev\n * \u00c9ric Br\u00e9hault\n * Waldemar Osuch\n * Isabelle Vallet\n * Thanks to mbutil authors <https://github.com/mapbox/mbutil>\n\n\n.. image:: http://depot.makina-corpus.org/public/logo.gif\n :target: http://www.makina-corpus.com\n\n=======\nLICENSE\n=======\n\n * Lesser GNU Public License\n\n\n=========\nCHANGELOG\n=========\n\n2.5.0 (2019-04-16)\n==================\n\n* Add support of Python 3.\n\n\n2.4.1 (2019-03-13)\n==================\n\n* Do not try to get tiles again when tiles doesn't exist.\n\n\n2.4.0 (2017-03-02)\n==================\n\n* Do not crash when overlay tile data is not a valid image\n* Correctly generate metadata for zoom levels\n* Add support for tms mbtiles\n* Correct tile box calculation for case when floating point value is an integer\n* Correctly generate metadata for zoom levels\n* Use the full path to construct the cache directory, as otherwise different\n tiles sets on the same server are considered to be the same one\n* Added a name metadata to prevent Maptiler crash\n\n\n2.3.0 (2014-11-18)\n==================\n\n* Add headers to WMS sources if specified (thanks @sempixel!)\n\n\n2.2.0 (2014-09-22)\n==================\n\n* Add delay between tiles downloads retries (by @kiorky)\n* Add option to ignore errors during MBTiles creation (e.g. download errors)\n\n\n2.1.1 (2013-08-27)\n==================\n\n* Do not hard-code ``grid();`` JSONP callback.\n\n2.1.0 (2013-08-27)\n==================\n\n* Add TMS support (ebrehault)\n* Add default subdomains argument for TileSource\n* Add ability to set HTTP headers for tiles\n* Fix file corruption on Windows (by @osuchw)\n\n2.0.3 (2013-05-03)\n==================\n\n* Fix Mapnik signature on render()\n\n2.0.2 (2012-06-21)\n==================\n\n* Prevent the whole image to be converted to grayscale\n* Explicitly check http status code at tiles download\n\n2.0.1 (2012-05-29)\n==================\n\n* Fix infinite loop on blending layers\n\n2.0.0 (2012-05-25)\n==================\n\n* Rework cache mechanism\n* Jpeg tiles support (#14)\n* Remove use of temporary files\n* Image post-processing (#11)\n\n2.0.0-alpha (2012-05-23)\n========================\n\n* Refactoring of whole stack\n\n1.8.2 (2012-03-27)\n==================\n\n* Fix Mapnik rendering\n\n1.8.1 (2012-02-24)\n==================\n\n* Fix MBTiles cache cleaning\n\n1.8 (2012-02-24)\n================\n\n* WMS support\n* Tiles compositing\n\n1.7 (2012-02-17)\n================\n\n* Catch Sqlite exceptions\n\n1.6 (2012-02-08)\n================\n\n* UTF-Grid support for MBTiles files\n\n1.5 (2011-12-07)\n================\n\n* Subdomain support for tiles servers\n* Low level tiles manipulation\n* Use i18n\n\n1.4 (2011-10-17)\n================\n\n* Remove extra logging message of mbutil\n\n1.3 (2011-09-23)\n================\n\n* Export set of tiles into single image\n\n1.2 (2011-06-21)\n================\n\n* Raise exception if no tiles in coverages\n\n1.1 (2012-04-18)\n================\n\n* Move internals to landez module\n* Split projection into separate module\n\n1.0 (2011-04-18)\n================\n\n* Initial working version",
"bugtrack_url": null,
"license": "LPGL, see LICENSE file.",
"summary": "Landez is a python toolbox to manipulate map tiles.",
"version": "2.5.0",
"split_keywords": [
"mbtiles",
"mapnik"
],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "a1b71ed03d498508890c026259bd9be9",
"sha256": "a936b43d50322761cb04e3dc45d80764b0eea0df742d18f632ed163dc8e2b0c1"
},
"downloads": -1,
"filename": "landez-2.5.0.tar.gz",
"has_sig": false,
"md5_digest": "a1b71ed03d498508890c026259bd9be9",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 22105,
"upload_time": "2019-04-16T15:27:07",
"upload_time_iso_8601": "2019-04-16T15:27:07.030691Z",
"url": "https://files.pythonhosted.org/packages/39/6b/911371692e259223e371a4f5137a4c4a445943da0ae7bed105cd25d5c575/landez-2.5.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2019-04-16 15:27:07",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "makinacorpus",
"github_project": "landez",
"travis_ci": true,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "mbutil",
"specs": []
},
{
"name": "Pillow",
"specs": [
[
"==",
"5.1.0"
]
]
},
{
"name": "requests",
"specs": [
[
"==",
"2.21.0"
]
]
},
{
"name": "mock",
"specs": [
[
"==",
"0.7.2"
]
]
}
],
"lcname": "landez"
}