API

Map Rendering

geotiler.Map([extent, center, zoom, size, ...])

Map created from tiles and to be drawn as an image.

geotiler.render_map(map[, tiles, downloader])

Download map tiles and render map image.

geotiler.render_map_async(map[, tiles, ...])

Asyncio coroutine to download map tiles asynchronously and render map image.

geotiler.fetch_tiles(map[, downloader])

Create and fetch map tiles.

geotiler.providers()

Get sorted list of all map providers identificators.

geotiler.find_provider(id)

Load map provider data from JSON file and create map provider.

class geotiler.Map(extent=None, center=None, zoom=None, size=None, provider: str | MapProvider = 'osm')[source]

Map created from tiles and to be drawn as an image.

The extent, zoom, center and image size can be changed at any time with appropriate properties.

Variables:
  • provider – Map tiles provider identificator (default osm) or object.

  • _zoom – Map zoom attribute accessed via zoom property.

  • _size – Map image size accessed via size property.

  • origin – Tile coordinates at map zoom level of base tile.

  • offset – Position of base tile relative to map center.

__init__(extent=None, center=None, zoom=None, size=None, provider: str | MapProvider = 'osm') None[source]

Create map.

One of the following parameters combination is required

  • center, zoom and size

  • extent and size

  • extent and zoom

If none of above parameters combination is provided, then ValueError exception is raised.

Parameters:
  • extent – Map geographical extent.

  • center – Map geographical center.

  • zoom – Map zoom.

  • size – Map image size.

  • provider – Map tiles provider.

__str__()[source]

Return str(self).

__weakref__

list of weak references to the object (if defined)

property center

Calculate map geographical center.

It is a tuple of two values - longitude and latitude.

Setting map geographical center affects map geographical extent.

property extent

Calculate map geographical extent.

It is a tuple of 2 coordinates (longitude and latitude)

  • lower-bottom corner of the map

  • right-top corner of the map

Setting map extent changes map image size.

geocode(point)[source]

Geocode map image point.

The method calculates geographical location (longitude, latitude) of image point.

Parameters:

point – Image map point (x, y).

rev_geocode(location)[source]

Reverse geocode geographical location.

The method calculates location position (x, y) on map image.

Parameters:

location – Geographical location (longitude, latitude).

property size

Size of the image containing map.

It is a sequence of two integer values - width and height of the image.

Setting size of the image affects map geographical extent.

property zoom

Map zoom value.

Setting map value does not affect any other map properties like extent, center or image size.

geotiler.render_map(map, tiles=None, downloader=None, **kw)[source]

Download map tiles and render map image.

If tiles are specified, then the provided tiles are used to render map. Otherwise, map tiles are downloaded from map provider.

If downloader is null, then default map tiles downloader is used (geotiler.tile.io.fetch_tiles()).

The function returns an image (instance of PIL.Image class).

Parameters:
  • map – Map instance.

  • tiles – Optional map tiles.

  • downloader – Map tiles downloader.

  • kw – Parameters passed to the downloader.

async geotiler.render_map_async(map, tiles=None, downloader=None, **kw)[source]

Asyncio coroutine to download map tiles asynchronously and render map image.

If tiles are specified, then the provided tiles are used to render map. Otherwise, map tiles are downloaded from map provider.

If downloader is null, then default map tiles downloader is used (geotiler.tile.io.fetch_tiles()).

The function returns an image (instance of PIL.Image class).

Parameters:
  • map – Map instance.

  • tiles – Optional map tiles.

  • downloader – Map tiles downloader.

  • kw – Parameters passed to the downloader.

geotiler.fetch_tiles(map, downloader=None, **kw)[source]

Create and fetch map tiles.

Asynchronous generator of map tiles is returned.

Parameters:
  • map – Map instance.

  • downloader – Map tiles downloader.

  • kw – Parameters passed to the downloader.

geotiler.providers()[source]

Get sorted list of all map providers identificators.

geotiler.find_provider(id)[source]

Load map provider data from JSON file and create map provider.

Parameters:

id – Map provider identificator.

Tile Downloading and Caching

geotiler.cache.caching_downloader(get, set, ...)

Download tiles from cache and missing tiles with the downloader.

geotiler.cache.redis_downloader(client[, ...])

Create downloader using Redis as cache for map tiles.

geotiler.tile.io.fetch_tiles(tiles, num_workers)

Download map tiles.

async geotiler.cache.caching_downloader(get, set, downloader, tiles, num_workers, **kw)[source]

Download tiles from cache and missing tiles with the downloader.

Asynchronous generator of map tiles is returned.

The code flow is

  • caching downloader gets tile data from cache using URLs

  • the original downloader is used to download missing tile data

  • cache is updated with all existing tile data

The cache getter function (get parameter) should return None if tile data is not in cache for given URL.

A collection of tiles is returned.

Parameters:
  • get – Function to get a tile data from cache.

  • set – Function to put a tile data in cache.

  • downloader – Original tiles downloader (asyncio coroutine).

  • tiles – Collection tiles to fetch.

  • num_workers – Number of workers used to connect to a map provider service.

  • kw – Parameters passed to downloader coroutine.

geotiler.cache.redis_downloader(client, downloader=None, timeout=604800)[source]

Create downloader using Redis as cache for map tiles.

Parameters:
  • client – Redis client object.

  • downloader – Map tiles downloader, use None for default downloader.

  • timeout – Map tile data expiry timeout, default 1 week.

async geotiler.tile.io.fetch_tiles(tiles, num_workers)[source]

Download map tiles.

Asynchronous generator of map tiles is returned.

A collection of tiles is returned. Each successfully downloaded tile has Tile.img attribute set. If there was an error while downloading a tile, then Tile.img is set to null and Tile.error to a value error.

Parameters:
  • tiles – Collection of tiles.

  • num_workers – Number of workers used to connect to a map provider service.