Skip to content
Katatunga edited this page Jun 26, 2020 · 4 revisions

Customizing inc/datasource-settings.xml.inc

For mapnik-stylesheets and preselected-rendering to use your database, you need to edit this file to match your configuration. Generate_view_tiles.py does not parse this file, so it ignores comments. Therefore, the correct database configuration needs to be the first occurence of parameters.

Customizing constants in 'generate_view_tiles.py'

To configure the script to match your directory setting, edit 'generate_view_tiles.py' (section PSR constants):

  • DIR_NAME: should remain '__file__', used as base for relative paths
  • DATABASE_SOURCE: relative path to your datasource-settings.xml.inc
  • PREFIX_SOURCE: relative path to your settings.xml.inc
  • TILE_DIR: absolute path to the output of rendered tiles (DATE / ZOOM / X / Y.png is added in rendering)

Usage of generate_view_tiles.py

As stated before, this file is a heavily modified version of 'generate_tiles.py' from the mapnik-stylesheets repository. The original file did not take any arguments and rendered according to hard-coded values. Neither did it handle errors nor validate values. So if you discover problems concerning usage of this script create an issue in this repository (preselected-rendering).

From Command Line

Type $ python generate_view_tiles.py --help for a usage explanation for both of the following ways.

$ python generate_view_tiles.py [PARAMETERS]

Parameters can either be

  1. --date [dd.mm.yyyy] --zoom [int] --left [float] --bottom [float] --right [float] --top [float]

or

  1. --port [int]

If you try to use both types of parameters at once, the script will fail with an error message.\

A single '-' and the respective first letter of a parameter work as well (e.g. -z [int]).

1) One-time-rendering

The parameters can be in any order, but the following restrictions apply:

Parameter Restrictions
date needs to be strictly the format above
zoom can range from 0 to 18
left / right can range from -180.0 to 180.0
bottom / top can range from -90.0 to 90.0

left / bottom / right / top are describing the bounding box to render. For that reason, left cannot be greater than right and bottom cannot be greater than top.

If any restriction is violated, the script will fail with an error message.

If used correctly, the tiles will be rendererd and saved to [TILE_DIR / DATE / ZOOM / X / Y.png].

2) Listen on a port

If you use only --port [PORT] as parameter, the script will listen on the given port for an incoming TCP-connection. The process ends either by received command, KeyBoardInterrupt or by losing the connection.

PORT - This number needs to be at least 5000 and the port needs to be available.

While listening, the script accepts the following protocol:

[CMD]&[PARAM1]=[VALUE1]&[PARAM2]=[VALUE2]&...

E.g. "render&date=02.03.1020&zoom=1&left=4.4232&bottom=4&right=42.2324&top=12.1451"

CMD = "render"

Reads the immediately following parameters, validates them, then renders tiles and saves them to [TILE_DIR / DATE / ZOOM / X / Y.png].

PARAM, VALUE

The Parameters can be in any order. There can be an indefinite number of parameters, but only the last occurence of a certain parameter is used. The possible parameters are the same as in '1) One-time-rendering' with the exact same restrictions. If validation fails, the process ignores the command, sends an error message and continues to listen for further commands.

CMD = "stop" or CMD = ""

Ends the process, given parameters will be ignored.

Possible error messages

Problem Message
Unknown CMD "errorCMD&Message not according to protocol (unknown command) - ignored"
Unknown PARAM "errorPARAM&Message not according to protocol (unknown parameter) - ignored"
Wrong VALUE "errorVALUE&[PARAM] [...] seems to be incorrect ([VALUE_RESTRICTIONS])"
Missing PARAM same as Wrong VALUE for the first PARAM the process cannot find
left > right "errorVALUE&First longitude (left) needs to be smaller than the second longitude (right)"
bottom > top "errorVALUE&First latitude (bottom) needs to be smaller than the second latitude (top)"

Example for Wrong VALUE error message:
Received String = "render&date=02.03.1020&zoom=13131&left=4.4232&bottom=4&right=42.2324&top=12.1451"
Error Message = "errorVALUE&Zoom level 13131 seems to be incorrect (0 - 18)"

There will be error messages as in '1) One-time-rendering' printed to the CLI as well.

Success protocol message

The process sends "done&Rendered successfully." as an answer, if the rendering process ended without errors.

Clone this wiki locally