Giter Club home page Giter Club logo

tilekiln-old's Introduction

Tilekiln

Background

Tilekiln is a set of command-line utilities to generate and serve Mapbox Vector Tiles (MVTs).

Generation relies on the standard method of a PostgreSQL + PostGIS server as a data source, and ST_AsMVT to serialize the MVTs.

The target use-case is vector tiles for OpenStreetMap Carto on openstreetmap.org, a worldwide complex basemap under high load.

Minutely updates are supported with an appropriately updating database.

Requirements

Tilekiln requires a PostGIS database with data loaded to generate vector tiles.

OpenStreetMap Carto's directions are a good starting place for loading OpenStreetMap data into a PostGIS database, but any PostGIS data source in EPSG 3857 will work.

  • PostgreSQL 9.5+
  • PostGIS 2.4+, 3.0 is strongly recommended

History

The tilekiln configuration syntax is based on studies and experience with other vector tile and map generation configurations. In particular, it is heavily inspired by Tilezen's use of Jinja2 templates and TileJSON for necessary metadata.

Tilekiln v0.0.x was written in Python and established the configuration format met all the requirements, but the implementation failed to scale on sufficiently powerful machines and the storage mechanisms had issues.

License

Code

Copyright © 2022 Paul Norman [email protected]

The code is licensed terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Documentation

The text of the documentation and configuration format specification is licensed under a Creative Commons Attribution 4.0 International License. However, the use of the specification in products and code is entirely free: there are no royalties, restrictions, or requirements.

Sample configuration

The sample configuration files are released under the CC0 Public Domain Dedication, version 1.0, as published by Creative Commons. To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to the Software to the public domain worldwide. The Software is distributed WITHOUT ANY WARRANTY.

If you did not receive a copy of the CC0 Public Domain Dedication along with the Software, see http://creativecommons.org/publicdomain/zero/1.0/

tilekiln-old's People

Contributors

pnorman avatar ttomasz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

tilekiln-old's Issues

Rewrite: Tile storage

I want to rewrite how tilekiln stores tiles. Although loose tiles on-disk can work for planet-sized datasets, it's a pain, particularly when it comes to deleting them. Because local tile creation needs to remain a first-class option, this can't be solved by pushing tiles to an object store.

A few options to consolidate multiple tiles are

  1. PMTiles

PMtiles would be my preferred format to store and distribute tiles in, but it's not clear to me that it supports the operations needed for just updating one tile, like what happens in an incremental update. My reading of the format is that it would also be more difficult to parallelize the work then write back to a single PMtiles file, as stuff like deduplication would require tracking across all workers.

  1. MBTiles

MBTiles is sqlite-based, so in theory supports updates. In practice, sqlite, and thus mbtiles, does not work well when handling high-concurrency writing of updates, or handling reading and writing of updates at the same time. MBTiles support is the best of all options, with lots of people having written tools for them.

  1. Tapalcatl

Tapalcatl 2 would still use multiple files, but reduce the number of files by a couple of orders of magnitude. Within an individual ZIP archive the tile writing work couldn't be done in parallel, but in practice this isn't an issue because there are enough ZIP archives to split work across them.

ZIP archives have some functionality for updating in place, which would require one worker updating files on disk to handle all the tiles in that archive, which is practical. Or, the entire archive could be regenerated, because if an individual tile in an archive has changed, odds are good others at the same zoom have changed, and it's guaranteed some at lower zooms will have changed.

The biggest issue is that it isn't open source yet.

Generate an entire tile at once

Tilekiln generates each layer independently and concatenates them in Python. This works well for development because SQL errors are clearer, and it's easier to profile to get per-layer performance information.

Doing all the layers in one complex SQL statement should be faster, with fewer round-trips to the server.

The general form of the current SQL is

WITH mvtgeom AS (SELECT contents...)
SELECT ST_AsMVT(mvtgeom.*)
FROM mvtgeom

This will need some adjustment to be more like

SELECT ST_AsMVT(mvtgeom.*)
FROM (SELECT contents...) AS mvtgeom

This will then allow

SELECT string_agg(t)
FROM (
SELECT ST_AsMVT(mvtgeom.*) t
FROM (SELECT contents1...) AS mvtgeom
UNION ALL
SELECT ST_AsMVT(mvtgeom.*) t
FROM (SELECT contents2...) AS mvtgeom
) AS tiles

Define error handling

How should tilekiln respond to a failure in one of the jobs? It could

  1. exit as soon as possible,
  2. skip the rest of the tiles in that chunk, or
  3. render everything else and exit with a return value of 1.

Are there any command-line flags that should be added to change its behavior?

@rory, what's your expectation from tirex/renderd?

Tilejson center

The config file calls for a two-number array for center, but the tilejson spec calls for three, including the zoom.

Don't apply jinja2 substitutions to wrapping SQL

Currently the SQL is generated by wrapping the user-supplied SQL and processing the wrapped jinja2 string as a j2 template.

https://github.com/pnorman/tilekiln/blob/6c32f13a544dc828fd84f32dcf91bf9195fe653d/tilekiln/definition.py#L45-L54

This lets the wrapped SQL refer to variables like {{extent}} but comes with the downside that the wrapping SQL has to be jinja safe. This does not work in a few cases

  • a layer name could be a j2 variable
  • testing the SQL generation functions is difficult

This needs to be rewritten to have the inner SQL processed as a j2 template then wrapped in SQL with python's format function.

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.