GithubHelp home page GithubHelp logo

ashtons / landez Goto Github PK

View Code? Open in Web Editor NEW

This project forked from makinacorpus/landez

0.0 2.0 0.0 192 KB

Landez operates with tiles, arranges them together into images or builds MBTiles files

License: GNU Lesser General Public License v3.0

Python 100.00%

landez's Introduction

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.

INSTALL

Landez is pure python and has no external dependency.

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()

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.reader 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(reader.tile(z, x, y))

# UTF-Grid tile
print reader.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
    ...

AUTHORS

LICENSE

  • Lesser GNU Public License

landez's People

Contributors

ashtons avatar leplatrem avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.