aboutsummaryrefslogtreecommitdiff
path: root/doc/developer/module/hittekaart_py.rst
blob: 1df3e8c266bdad3fd9aeb56b196881079167f71f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
hittekaart_py package
=====================

.. module:: hittekaart_py

    The ``hittekaart_py`` module provides a Python interface for hittekaart__
    heatmap generation. Unlike previous modules, this is a binding using
    PyO3__, and not a subprocess wrapper.

.. __: https://gitlab.com/dunj3/hittekaart
.. __: https://crates.io/crates/pyo3

Example
-------

.. code-block:: python

    from hittekaart_py import (
        Track, HeatmapRenderer, Storage, generate
    )

    tracks = [
        Track.from_file(b"Documents/track.gpx", None),
        Track.from_coordinates([(45.0, 47.0)]),
    ]
    storage = Storage.Sqlite(b"/tmp/tiles.sqlite")
    generate(tracks, HeatmapRenderer(), storage)

Input and output
----------------

.. class:: Track

    An in-memory representation of a track.

    .. staticmethod:: from_file(path, compression)

        Loads a track from the given file.

        :param path: Path to the file.
        :type path: bytes
        :param compression: Decompression algorithm to use when reading the
            file. Can be :obj:`None`, ``"gzip"`` or ``"brotli"``.
        :type compression: str | None
        :return: The created track.
        :rtype: Track

    .. staticmethod:: from_coordinates(coordinates)

        Directly represents the given coordinates as a track.

        :param coordinates: The coordinates as a list of longitude-latitude
            pairs.
        :type coordinates: list[tuple[float, float]]
        :return: The created track.
        :rtype: Track


.. class:: Storage

    Represents the output storage.

    .. staticmethod:: Folder(path)

        Output the tiles to the given folder. This will create a subdirectory
        for every zoom level, then a directory for the x coordinate, then a
        file ``y.png``.

        Note that this will create many small files, which can waste space.

        :param path: Path to the folder.
        :type path: bytes
        :return: The created storage.
        :rtype: Storage

    .. staticmethod:: Sqlite(path)

        Output the tiles to the given SQLite database.

        :param path: Path to the database.
        :type path: bytes
        :return: The created storage.
        :rtype: Storage

Renderers
---------

.. class:: HeatmapRenderer()

    The renderer that generates a heatmap.

.. class:: MarktileRenderer()

    The renderer that will only mark visited tiles.

.. class:: TilehuntRenderer(zoom)

    The renderer that will mark visisted tiles at a fixed zoom level.

    :param zoom: The zoom level.
    :type zoom: int

Functions
---------

.. function:: generate(items, renderer, storage)

    Generates the tiles using the given renderer, and saves them to the given
    storage.

    :param items: The tracks to render.
    :type items: ~typing.Iterable[Track]
    :param renderer: The renderer to use.
    :type renderer: HeatmapRenderer | MarktileRenderer | TilehuntRenderer
    :param storage: The storage to output to.
    :type storage: Storage

.. function:: set_threads(threads)

    Set the number of threads that hittekaart will use.

    Note that this is a global function, it will affect all subsequent calls.

    Note further that you may only call this function once, at startup. Calls
    after the thread pool has been initialized (e.g. via a :func:`generate` or
    :func:`set_threads` call) will raise an exception.

    :param threads: Number of threads to use.
    :type threads: int

Errors
------

.. exception:: HitteError

    Catch-all error for underlying hittekaart errors. See the string
    description for the error cause.