manby 0.2.2__py3-none-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- manby/__init__.py +341 -0
- manby/__main__.py +5 -0
- manby/__pycache__/__init__.cpython-314.pyc +0 -0
- manby-0.2.2.data/scripts/manby.exe +0 -0
- manby-0.2.2.dist-info/METADATA +215 -0
- manby-0.2.2.dist-info/RECORD +10 -0
- manby-0.2.2.dist-info/WHEEL +4 -0
- manby-0.2.2.dist-info/licenses/LICENSE.md +26 -0
- manby-0.2.2.dist-info/licenses/src/crs/NOTICE.md +13 -0
- manby-0.2.2.dist-info/sboms/manby.cyclonedx.json +10583 -0
manby/__init__.py
ADDED
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
"""manby builds vector tilesets from geographic features, like tippecanoe,
|
|
2
|
+
several times faster.
|
|
3
|
+
|
|
4
|
+
``tile`` makes a tileset from files, or from tables in memory: a DuckDB
|
|
5
|
+
query, a GeoDataFrame, or a Polars or PyArrow table. A table streams to the
|
|
6
|
+
manby program in Arrow batches, so a query result need not fit in memory.
|
|
7
|
+
|
|
8
|
+
import duckdb, manby
|
|
9
|
+
|
|
10
|
+
manby.tile("roads.geojson", "roads.pmtiles", "-zg", "--drop-densest-as-needed")
|
|
11
|
+
manby.tile(
|
|
12
|
+
duckdb.sql("SELECT name, geometry FROM 'places.parquet' WHERE country = 'DE'"),
|
|
13
|
+
"places.pmtiles",
|
|
14
|
+
maximum_zoom=14,
|
|
15
|
+
drop_densest_as_needed=True,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
The options are tippecanoe's: ``maximum_zoom=14`` is ``--maximum-zoom=14``,
|
|
19
|
+
``drop_densest_as_needed=True`` is ``--drop-densest-as-needed``, and a list
|
|
20
|
+
repeats an option. Arguments after the output are passed as they are.
|
|
21
|
+
|
|
22
|
+
``serve`` serves tilesets with a map of them, in the browser or in a notebook,
|
|
23
|
+
and ``stats`` reports the sizes of their tiles.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
from __future__ import annotations
|
|
27
|
+
|
|
28
|
+
import atexit
|
|
29
|
+
import errno
|
|
30
|
+
import json
|
|
31
|
+
import os
|
|
32
|
+
import shutil
|
|
33
|
+
import subprocess
|
|
34
|
+
import sys
|
|
35
|
+
import sysconfig
|
|
36
|
+
import tempfile
|
|
37
|
+
import threading
|
|
38
|
+
import time
|
|
39
|
+
import webbrowser
|
|
40
|
+
from typing import Any, Mapping, Sequence
|
|
41
|
+
|
|
42
|
+
__all__ = ["tile", "serve", "stats", "run", "binary", "Server", "ManbyError"]
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class ManbyError(RuntimeError):
|
|
46
|
+
"""manby exited with an error. ``returncode`` is its exit status, as
|
|
47
|
+
tippecanoe's: 100 when the tileset is complete only to a lower zoom."""
|
|
48
|
+
|
|
49
|
+
def __init__(self, returncode: int, args: Sequence[str]):
|
|
50
|
+
self.returncode = returncode
|
|
51
|
+
super().__init__(
|
|
52
|
+
"manby exited with status %d: %s" % (returncode, " ".join(args))
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def binary() -> str:
|
|
57
|
+
"""The path of the manby program that this package installed."""
|
|
58
|
+
name = "manby.exe" if os.name == "nt" else "manby"
|
|
59
|
+
dirs = []
|
|
60
|
+
for scheme in (None, "%s_user" % os.name):
|
|
61
|
+
try:
|
|
62
|
+
dirs.append(
|
|
63
|
+
sysconfig.get_path("scripts", scheme)
|
|
64
|
+
if scheme
|
|
65
|
+
else sysconfig.get_path("scripts")
|
|
66
|
+
)
|
|
67
|
+
except KeyError:
|
|
68
|
+
pass
|
|
69
|
+
# pip install --target puts the program beside the package
|
|
70
|
+
here = os.path.dirname(os.path.abspath(__file__))
|
|
71
|
+
dirs.append(os.path.join(os.path.dirname(here), "bin"))
|
|
72
|
+
for d in dirs:
|
|
73
|
+
if d:
|
|
74
|
+
path = os.path.join(d, name)
|
|
75
|
+
if os.path.isfile(path) and os.access(path, os.X_OK):
|
|
76
|
+
return path
|
|
77
|
+
path = shutil.which(name)
|
|
78
|
+
if path:
|
|
79
|
+
return path
|
|
80
|
+
raise FileNotFoundError("the manby program was not found next to its package")
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def run(*args: str) -> None:
|
|
84
|
+
"""Runs manby with ``args``, as on the command line. For example,
|
|
85
|
+
``run("join", "-o", "all.pmtiles", "a.pmtiles", "b.pmtiles")``."""
|
|
86
|
+
argv = [binary(), *map(str, args)]
|
|
87
|
+
code = subprocess.call(argv)
|
|
88
|
+
if code != 0:
|
|
89
|
+
raise ManbyError(code, argv[1:])
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _flags(options: Mapping[str, Any]) -> list:
|
|
93
|
+
out = []
|
|
94
|
+
for key, value in options.items():
|
|
95
|
+
flag = "--" + key.replace("_", "-")
|
|
96
|
+
if value is None or value is False:
|
|
97
|
+
continue
|
|
98
|
+
if value is True:
|
|
99
|
+
out.append(flag)
|
|
100
|
+
elif isinstance(value, (list, tuple)):
|
|
101
|
+
out.extend("%s=%s" % (flag, v) for v in value)
|
|
102
|
+
else:
|
|
103
|
+
out.append("%s=%s" % (flag, value))
|
|
104
|
+
return out
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _is_geodataframe(data: Any) -> bool:
|
|
108
|
+
return any(
|
|
109
|
+
c.__name__ == "GeoDataFrame" and c.__module__.startswith("geopandas")
|
|
110
|
+
for c in type(data).__mro__
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def _arrow(data: Any) -> Any:
|
|
115
|
+
"""``data`` as an object with an Arrow stream, or None if it is a path."""
|
|
116
|
+
if isinstance(data, (str, bytes, os.PathLike)):
|
|
117
|
+
return None
|
|
118
|
+
if _is_geodataframe(data):
|
|
119
|
+
crs = data.crs
|
|
120
|
+
if crs is not None and crs.to_epsg() not in (4326, 3857):
|
|
121
|
+
data = data.to_crs(4326)
|
|
122
|
+
return data.to_arrow(geometry_encoding="WKB")
|
|
123
|
+
if hasattr(data, "__arrow_c_stream__"):
|
|
124
|
+
return data
|
|
125
|
+
raise TypeError(
|
|
126
|
+
"manby.tile takes a file name, a GeoDataFrame, or a table with an Arrow "
|
|
127
|
+
"stream, such as a DuckDB relation or a Polars or PyArrow table, not %s"
|
|
128
|
+
% type(data).__name__
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def _write_ipc(data: Any, f: Any) -> None:
|
|
133
|
+
"""Writes ``data`` to ``f`` as an Arrow IPC stream."""
|
|
134
|
+
try:
|
|
135
|
+
import pyarrow as pa
|
|
136
|
+
except ImportError:
|
|
137
|
+
pa = None
|
|
138
|
+
if pa is not None:
|
|
139
|
+
reader = pa.RecordBatchReader.from_stream(data)
|
|
140
|
+
with pa.ipc.new_stream(f, reader.schema) as w:
|
|
141
|
+
for batch in reader:
|
|
142
|
+
w.write_batch(batch)
|
|
143
|
+
return
|
|
144
|
+
if hasattr(data, "write_ipc_stream"): # Polars
|
|
145
|
+
data.write_ipc_stream(f)
|
|
146
|
+
return
|
|
147
|
+
raise ImportError("manby needs pyarrow to send this table: pip install pyarrow")
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
class _Feed(threading.Thread):
|
|
151
|
+
"""Writes a table to a named pipe that manby reads, on Unix."""
|
|
152
|
+
|
|
153
|
+
def __init__(self, path: str, data: Any, proc: subprocess.Popen):
|
|
154
|
+
super().__init__(daemon=True)
|
|
155
|
+
self.path, self.data, self.proc = path, data, proc
|
|
156
|
+
self.error = None # type: BaseException | None
|
|
157
|
+
|
|
158
|
+
def run(self) -> None:
|
|
159
|
+
try:
|
|
160
|
+
# manby opens the pipes one at a time, in order, and may stop
|
|
161
|
+
# before it opens this one
|
|
162
|
+
while True:
|
|
163
|
+
try:
|
|
164
|
+
fd = os.open(self.path, os.O_WRONLY | os.O_NONBLOCK)
|
|
165
|
+
break
|
|
166
|
+
except OSError as e:
|
|
167
|
+
if e.errno != errno.ENXIO:
|
|
168
|
+
raise
|
|
169
|
+
if self.proc.poll() is not None:
|
|
170
|
+
return
|
|
171
|
+
time.sleep(0.005)
|
|
172
|
+
os.set_blocking(fd, True)
|
|
173
|
+
with open(fd, "wb") as f:
|
|
174
|
+
_write_ipc(self.data, f)
|
|
175
|
+
except BrokenPipeError:
|
|
176
|
+
pass # manby stopped; its status says why
|
|
177
|
+
except BaseException as e:
|
|
178
|
+
self.error = e
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def tile(
|
|
182
|
+
data: Any,
|
|
183
|
+
output: str | os.PathLike,
|
|
184
|
+
*args: str,
|
|
185
|
+
layer: str | None = None,
|
|
186
|
+
force: bool = True,
|
|
187
|
+
**options: Any,
|
|
188
|
+
) -> str:
|
|
189
|
+
"""Makes the tileset ``output`` from ``data``, and gives its path.
|
|
190
|
+
|
|
191
|
+
``data`` is a file name, a GeoDataFrame, a table with an Arrow stream (a
|
|
192
|
+
DuckDB relation, a Polars or PyArrow table), or a dict of layer names to
|
|
193
|
+
any of these. A table's geometry is the column that its GeoArrow or
|
|
194
|
+
GeoParquet metadata names, or a column named ``geometry`` in well-known
|
|
195
|
+
binary. ``layer`` names the layer of a single input. ``force`` overwrites
|
|
196
|
+
an existing tileset. The other options are tippecanoe's long options.
|
|
197
|
+
"""
|
|
198
|
+
layers = data if isinstance(data, Mapping) else {layer: data}
|
|
199
|
+
argv = ["-o", os.fspath(output)]
|
|
200
|
+
if force:
|
|
201
|
+
argv.append("--force")
|
|
202
|
+
argv += _flags(options)
|
|
203
|
+
argv += [str(a) for a in args]
|
|
204
|
+
|
|
205
|
+
feeds = []
|
|
206
|
+
tmp = None
|
|
207
|
+
try:
|
|
208
|
+
for i, (name, d) in enumerate(layers.items()):
|
|
209
|
+
stream = _arrow(d)
|
|
210
|
+
if stream is None:
|
|
211
|
+
if name is None:
|
|
212
|
+
argv.append(os.fspath(d))
|
|
213
|
+
else:
|
|
214
|
+
argv.append(
|
|
215
|
+
"-L" + json.dumps({"file": os.fspath(d), "layer": name})
|
|
216
|
+
)
|
|
217
|
+
continue
|
|
218
|
+
if tmp is None:
|
|
219
|
+
tmp = tempfile.mkdtemp(prefix="manby-")
|
|
220
|
+
# named as the tileset, which an unnamed layer is named after
|
|
221
|
+
stem = os.path.basename(os.fspath(output)).rsplit(".", 1)[0] or "layer"
|
|
222
|
+
path = os.path.join(tmp, str(i), stem + ".arrows")
|
|
223
|
+
os.mkdir(os.path.dirname(path))
|
|
224
|
+
if hasattr(os, "mkfifo"):
|
|
225
|
+
os.mkfifo(path)
|
|
226
|
+
feeds.append((path, stream))
|
|
227
|
+
else:
|
|
228
|
+
# Windows has no named pipes among its files, so the table is
|
|
229
|
+
# written out first, as the R package writes its tables
|
|
230
|
+
with open(path, "wb") as f:
|
|
231
|
+
_write_ipc(stream, f)
|
|
232
|
+
source = {"file": path, "format": "arrow"}
|
|
233
|
+
if name is not None:
|
|
234
|
+
source["layer"] = name
|
|
235
|
+
argv.append("-L" + json.dumps(source))
|
|
236
|
+
|
|
237
|
+
proc = subprocess.Popen([binary(), *argv])
|
|
238
|
+
threads = [_Feed(path, stream, proc) for path, stream in feeds]
|
|
239
|
+
for t in threads:
|
|
240
|
+
t.start()
|
|
241
|
+
try:
|
|
242
|
+
code = proc.wait()
|
|
243
|
+
except BaseException:
|
|
244
|
+
proc.kill()
|
|
245
|
+
raise
|
|
246
|
+
for t in threads:
|
|
247
|
+
t.join()
|
|
248
|
+
for t in threads:
|
|
249
|
+
if t.error is not None:
|
|
250
|
+
raise t.error
|
|
251
|
+
if code != 0:
|
|
252
|
+
raise ManbyError(code, argv)
|
|
253
|
+
finally:
|
|
254
|
+
if tmp is not None:
|
|
255
|
+
shutil.rmtree(tmp, ignore_errors=True)
|
|
256
|
+
return os.fspath(output)
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
class Server:
|
|
260
|
+
"""A running ``manby serve``. ``url`` is the map, ``tilejson`` the
|
|
261
|
+
TileJSON of each tileset by name, and ``stop()`` ends it. In a notebook,
|
|
262
|
+
the server shows as its map."""
|
|
263
|
+
|
|
264
|
+
def __init__(self, proc: subprocess.Popen, url: str, tilejson: Mapping[str, str]):
|
|
265
|
+
self.process = proc
|
|
266
|
+
self.url = url
|
|
267
|
+
self.tilejson = dict(tilejson)
|
|
268
|
+
|
|
269
|
+
def stop(self) -> None:
|
|
270
|
+
"""Stops serving."""
|
|
271
|
+
if self.process.poll() is None:
|
|
272
|
+
self.process.terminate()
|
|
273
|
+
try:
|
|
274
|
+
self.process.wait(5)
|
|
275
|
+
except subprocess.TimeoutExpired:
|
|
276
|
+
self.process.kill()
|
|
277
|
+
|
|
278
|
+
def __enter__(self) -> "Server":
|
|
279
|
+
return self
|
|
280
|
+
|
|
281
|
+
def __exit__(self, *exc: Any) -> None:
|
|
282
|
+
self.stop()
|
|
283
|
+
|
|
284
|
+
def __repr__(self) -> str:
|
|
285
|
+
state = "serving" if self.process.poll() is None else "stopped"
|
|
286
|
+
return "<manby.Server %s %s>" % (state, self.url)
|
|
287
|
+
|
|
288
|
+
def _repr_html_(self) -> str:
|
|
289
|
+
return '<iframe src="%s" style="width:100%%;height:480px;border:0"></iframe>' % self.url
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
def serve(
|
|
293
|
+
*tilesets: str | os.PathLike,
|
|
294
|
+
port: int = 8080,
|
|
295
|
+
host: str = "127.0.0.1",
|
|
296
|
+
open: bool | None = None,
|
|
297
|
+
) -> Server:
|
|
298
|
+
"""Serves PMTiles archives, MBTiles databases or directories of tiles
|
|
299
|
+
until ``stop()``, with a map of them at ``url``. ``open`` opens the map in
|
|
300
|
+
a browser, as it does by default outside a notebook, where the server
|
|
301
|
+
shows as its map instead. ``port=0`` takes any free port. A tileset made
|
|
302
|
+
again while it is served shows when the map is reloaded."""
|
|
303
|
+
argv = [binary(), "serve", "--port", str(port), "--host", host]
|
|
304
|
+
argv += [os.fspath(t) for t in tilesets]
|
|
305
|
+
proc = subprocess.Popen(argv, stdout=subprocess.PIPE, text=True)
|
|
306
|
+
url = proc.stdout.readline().strip()
|
|
307
|
+
if not url:
|
|
308
|
+
raise ManbyError(proc.wait(), argv[1:])
|
|
309
|
+
tilejson = {}
|
|
310
|
+
for _ in tilesets:
|
|
311
|
+
name, _, address = proc.stdout.readline().strip().partition(": ")
|
|
312
|
+
tilejson[name] = address
|
|
313
|
+
server = Server(proc, url, tilejson)
|
|
314
|
+
atexit.register(server.stop)
|
|
315
|
+
if open is None:
|
|
316
|
+
open = "ipykernel" not in sys.modules
|
|
317
|
+
if open:
|
|
318
|
+
webbrowser.open(url)
|
|
319
|
+
return server
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
def stats(tileset: str | os.PathLike, layers: bool = False, largest: int = 10) -> dict:
|
|
323
|
+
"""The sizes of a tileset's tiles at each zoom, as stored, and the
|
|
324
|
+
``largest`` tiles. ``layers`` also counts the features of each layer at
|
|
325
|
+
each zoom, from every tile. The result is ``manby stats --json``'s."""
|
|
326
|
+
argv = [binary(), "stats", "--json", "--largest=%d" % largest]
|
|
327
|
+
if layers:
|
|
328
|
+
argv.append("--layers")
|
|
329
|
+
argv.append(os.fspath(tileset))
|
|
330
|
+
done = subprocess.run(argv, stdout=subprocess.PIPE, text=True)
|
|
331
|
+
if done.returncode != 0:
|
|
332
|
+
raise ManbyError(done.returncode, argv[1:])
|
|
333
|
+
return json.loads(done.stdout)
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
def main() -> None:
|
|
337
|
+
"""Runs the manby program with this process's arguments."""
|
|
338
|
+
argv = [binary(), *sys.argv[1:]]
|
|
339
|
+
if os.name == "posix":
|
|
340
|
+
os.execv(argv[0], argv)
|
|
341
|
+
sys.exit(subprocess.call(argv))
|
manby/__main__.py
ADDED
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: manby
|
|
3
|
+
Version: 0.2.2
|
|
4
|
+
Classifier: Environment :: Console
|
|
5
|
+
Classifier: Operating System :: MacOS
|
|
6
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
7
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Rust
|
|
10
|
+
Classifier: Topic :: Scientific/Engineering :: GIS
|
|
11
|
+
License-File: LICENSE.md
|
|
12
|
+
License-File: src/crs/NOTICE.md
|
|
13
|
+
Summary: Builds vector tilesets from geographic features, like tippecanoe, several times faster
|
|
14
|
+
Keywords: tippecanoe,vector-tiles,pmtiles,mbtiles,geojson
|
|
15
|
+
Home-Page: https://birkskyum.github.io/manby/
|
|
16
|
+
License-Expression: BSD-2-Clause
|
|
17
|
+
Requires-Python: >=3.8
|
|
18
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
19
|
+
Project-URL: Homepage, https://birkskyum.github.io/manby/
|
|
20
|
+
Project-URL: Repository, https://github.com/birkskyum/manby
|
|
21
|
+
|
|
22
|
+
# manby
|
|
23
|
+
|
|
24
|
+
[](https://crates.io/crates/manby)
|
|
25
|
+
[](https://pypi.org/project/manby/)
|
|
26
|
+
[](https://birkskyum.r-universe.dev/manby)
|
|
27
|
+
[](https://github.com/birkskyum/homebrew-tap)
|
|
28
|
+
[](https://github.com/birkskyum/manby/releases)
|
|
29
|
+
|
|
30
|
+
manby builds vector tilesets from GeoJSON, FlatGeobuf, CSV, Geobuf, GeoParquet or Arrow features, GeoParquet in object storage, and from DuckDB queries and data frames in Python and R. It makes the same tiles as [tippecanoe](https://github.com/felt/tippecanoe), in less memory, ten to eighteen times faster on a Mac and eight to fifteen times faster on Linux, more where tippecanoe's disk slows it down. `manby join` is tippecanoe's tile-join, two to thirty-five times faster.
|
|
31
|
+
|
|
32
|
+
The `manby` command takes tippecanoe's options:
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
manby -zg --drop-densest-as-needed -o places.pmtiles places.geojson
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
`--largest-maximum-zoom-guess=14` chooses the maximum zoom as `-zg` does, but no higher than 14.
|
|
39
|
+
|
|
40
|
+
The [site](https://birkskyum.github.io/manby/) has the guides.
|
|
41
|
+
|
|
42
|
+
## Install
|
|
43
|
+
|
|
44
|
+
manby runs on macOS, Linux and Windows.
|
|
45
|
+
|
|
46
|
+
| | |
|
|
47
|
+
| --- | --- |
|
|
48
|
+
| Homebrew | `brew install birkskyum/tap/manby` |
|
|
49
|
+
| pip, with the Python module | `pip install manby` |
|
|
50
|
+
| uv, without installing | `uvx manby` |
|
|
51
|
+
| mise | `mise use -g github:birkskyum/manby` |
|
|
52
|
+
| cargo, with Rust 1.94 or later | `cargo install manby` |
|
|
53
|
+
| R, from [R-universe](https://birkskyum.r-universe.dev/manby) | `install.packages("manby", repos = c("https://birkskyum.r-universe.dev", "https://cloud.r-project.org"))` |
|
|
54
|
+
| The program alone | the [releases](https://github.com/birkskyum/manby/releases), for macOS, Linux and Windows on arm64 and x86-64 |
|
|
55
|
+
|
|
56
|
+
cargo builds it without MapLibre Tiles and URLs, which `--features mlt,remote` adds, with Rust 1.98.
|
|
57
|
+
|
|
58
|
+
## From Python and R
|
|
59
|
+
|
|
60
|
+
From Python, a DuckDB query streams to manby in Arrow batches.
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
import duckdb, manby
|
|
64
|
+
|
|
65
|
+
places = duckdb.sql("SELECT name, geometry FROM 'places.parquet' WHERE country = 'DE'")
|
|
66
|
+
manby.tile(places, "places.pmtiles", maximum_zoom="g", drop_densest_as_needed=True)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The R package tiles sf data frames and DuckDB tables the same way. `manby serve` serves tilesets with a map of them, and `manby stats` reports their tiles' sizes, from the command line, R or Python.
|
|
70
|
+
|
|
71
|
+
```r
|
|
72
|
+
manby::tile(sf::st_read("places.gpkg"), "places.pmtiles", maximum_zoom = "g", drop_densest_as_needed = TRUE)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Speed
|
|
76
|
+
|
|
77
|
+
Against tippecanoe 2.82.0 itself, the C++ built with its own Makefile, writing PMTiles. Each figure is the median of three runs, and memory is peak resident memory. tippecanoe's runs and manby's come from separate sessions on the same machine, since tippecanoe's do not change with manby's version.
|
|
78
|
+
|
|
79
|
+
On macOS, on an Apple M5 Max with 18 cores and 128 GB:
|
|
80
|
+
|
|
81
|
+
| Benchmark | tippecanoe | manby | |
|
|
82
|
+
| --- | --- | --- | --- |
|
|
83
|
+
| 4 million points, `-zg --drop-densest-as-needed` | 61.4 s, 2,276 MB | 3.44 s, 919 MB | 17.8x |
|
|
84
|
+
| The same points, `-zg -r1 --cluster-distance=10 --cluster-densest-as-needed --accumulate-attribute=value:sum` | 54.4 s, 1,318 MB | 3.88 s, 891 MB | 14.0x |
|
|
85
|
+
| The same points, `-zg --cluster-densest-as-needed` | 59.8 s, 2,330 MB | 4.07 s, 916 MB | 14.7x |
|
|
86
|
+
| The same points, `-zg -r1 --cluster-densest-as-needed --accumulate-attribute=value:sum` | 87.7 s, 3,443 MB | 7.82 s, 1,115 MB | 11.2x |
|
|
87
|
+
| 17,522 roads at `-z14`, 122,725 tiles | 11.8 s, 327 MB | 0.81 s, 177 MB | 14.5x |
|
|
88
|
+
| 85,186 census tracts at `-z12`, 312,073 tiles | 46.6 s, 566 MB | 3.78 s, 338 MB | 12.3x |
|
|
89
|
+
| 85,186 census tracts, `-zg --coalesce-densest-as-needed` | 24.8 s, 554 MB | 2.27 s, 366 MB | 10.9x |
|
|
90
|
+
|
|
91
|
+
On Linux, on a Lenovo Yoga Slim 7x with a Snapdragon X Elite (12 cores, 32 GB), running Arch Linux ARM:
|
|
92
|
+
|
|
93
|
+
| Benchmark | tippecanoe | manby | |
|
|
94
|
+
| --- | --- | --- | --- |
|
|
95
|
+
| 4 million points, `-zg --drop-densest-as-needed` | 88.5 s, 1,088 MB | 5.86 s, 994 MB | 15.1x |
|
|
96
|
+
| The same points, clustered within 10 pixels, summing `value` | 82.5 s, 1,028 MB | 6.02 s, 974 MB | 13.7x |
|
|
97
|
+
| The same points, `-zg --cluster-densest-as-needed` | 89.6 s, 1,165 MB | 6.37 s, 1,000 MB | 14.1x |
|
|
98
|
+
| The same points, `-zg -r1 --cluster-densest-as-needed`, summing `value` | 133.6 s, 1,498 MB | 13.9 s, 1,152 MB | 9.6x |
|
|
99
|
+
| 17,522 roads at `-z14`, 122,725 tiles | 59.0 s, 240 MB | 1.51 s, 236 MB | 39.1x |
|
|
100
|
+
| 85,186 census tracts at `-z12`, 312,073 tiles | 196.8 s, 456 MB | 7.77 s, 360 MB | 25.3x |
|
|
101
|
+
| 85,186 census tracts, `-zg --coalesce-densest-as-needed` | 36.1 s, 451 MB | 4.46 s, 379 MB | 8.1x |
|
|
102
|
+
|
|
103
|
+
On this machine tippecanoe uses 8 of the 12 cores, since it rounds its thread count down to a power of 2, which keeps its memory low, while manby uses all 12. tippecanoe is slow on the runs with many tiles here because it writes PMTiles by way of a SQLite database next to the output, on a btrfs filesystem that compresses with zstd. With the output in memory instead, roads take it 27 s rather than 59. The kernel also backs memory with 2 MB pages wherever it can (transparent huge pages set to `always`, as Arch sets them), which adds about a tenth to manby's figures, and leaves its roads only just below tippecanoe's. `bench/` has the data, the scripts and how the Linux numbers were made.
|
|
104
|
+
|
|
105
|
+
For every run the tiles decode to exactly what tippecanoe makes, with one exception. tippecanoe's arm64 builds, from Apple's clang on macOS and from GCC on Linux, fuse multiplications and additions where its x86-64 build does not, and that changes a few tiles near the size limit. On these benchmarks it changes only the census tracts at `-zg`, here and 20 times over below. In the tracts, the zoom 0 tile comes out 6 bytes smaller compressed, so that tippecanoe's retry keeps other features. manby makes the same tiles on macOS and Linux alike, the tiles of tippecanoe's x86-64 build. Built for x86-64, or on arm64 with `-ffp-contract=off`, tippecanoe makes manby's tiles on the tracts too.
|
|
106
|
+
|
|
107
|
+
[tippecanoe-rs](crates/tippecanoe-rs), the faithful Rust port that manby takes tippecanoe's algorithms from, runs at about the speed of the C++. So porting tippecanoe to Rust is not what makes manby fast. Doing the work differently is.
|
|
108
|
+
|
|
109
|
+
The archives are not tippecanoe's byte for byte, and a little smaller. zlib's exact output decides which features a tile keeps only when the tile could be near the size limit. Every other tile is compressed with libdeflate, which is faster and compresses tiles better. `--compression=zlib` compresses every tile with zlib, as tippecanoe does, for the same archive bytes.
|
|
110
|
+
|
|
111
|
+
## How
|
|
112
|
+
|
|
113
|
+
tippecanoe spends most of its time waiting on itself rather than computing. It works through the low zoom levels one tile per thread, rebuilds oversized tiles by reading their features back from compressed temporary files, finishes each zoom level before starting the next, and writes PMTiles by way of a SQLite database. manby keeps the features in memory, sorted once, walks the tile pyramid in parallel on every core, splits big tiles across threads, retries oversized tiles on data already in memory, and writes PMTiles directly. The geometry algorithms are tippecanoe's own, by way of tippecanoe-rs, which is why the tiles come out the same. [DESIGN.md](DESIGN.md) has the measurements and the architecture.
|
|
114
|
+
|
|
115
|
+
## Memory
|
|
116
|
+
|
|
117
|
+
manby's peak memory is below tippecanoe's on the benchmarks. For inputs larger than memory, `--memory-budget` bounds it (default: half the physical memory, as tippecanoe sizes its sorting). Past the budget, the features and the tile data live in an unlinked temporary file in the `-t` directory, mapped into memory, laid out in the order the tiling reads them, and manby keeps its resident memory near the budget. `bench/large.sh` tiles inputs several times larger than a 1 GB budget, once each:
|
|
118
|
+
|
|
119
|
+
| Input | System | tippecanoe | manby, `--memory-budget=1G` |
|
|
120
|
+
| --- | --- | --- | --- |
|
|
121
|
+
| 40 million points (5.6 GB), `-zg --drop-densest-as-needed` | macOS | 652 s, 10,206 MB | 79 s, 1,139 MB |
|
|
122
|
+
| | Linux | 1,025 s, 6,379 MB | 121 s, 1,188 MB |
|
|
123
|
+
| The census tracts 20 times over (3 GB), `-zg --coalesce-densest-as-needed` | macOS | 564 s, 4,810 MB | 137 s, 1,022 MB |
|
|
124
|
+
| | Linux | 854 s, 3,730 MB | 269 s, 1,206 MB |
|
|
125
|
+
|
|
126
|
+
## Joining tilesets
|
|
127
|
+
|
|
128
|
+
`manby join` takes tile-join's options, prints its messages, exits as it does, and makes the same tiles, with their features in the same order. It merges tilesets, joins attributes from a CSV file, filters and renames layers, filters features, overzooms, and converts between MBTiles, PMTiles and directories:
|
|
129
|
+
|
|
130
|
+
```sh
|
|
131
|
+
manby join -o merged.pmtiles roads.pmtiles places.mbtiles
|
|
132
|
+
manby join -c tracts.csv -o joined.pmtiles tracts.pmtiles
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
`manby tile-join` works too. Under the name `tile-join`, a link to it for example, manby is tile-join, so it can take its place.
|
|
136
|
+
|
|
137
|
+
On the same machines, median of three runs, against tile-join 2.82.0, the C++. For every run the tiles decode to exactly what tile-join makes.
|
|
138
|
+
|
|
139
|
+
| Benchmark | System | tile-join | manby join | |
|
|
140
|
+
| --- | --- | --- | --- | --- |
|
|
141
|
+
| The tracts at `-z12` (312,073 tiles) copied to PMTiles | macOS | 21.9 s, 589 MB | 0.63 s, 161 MB | 34.8x |
|
|
142
|
+
| | Linux | 24.2 s, 461 MB | 1.05 s, 185 MB | 23.1x |
|
|
143
|
+
| The same, to MBTiles | macOS | 16.6 s, 560 MB | 1.19 s, 380 MB | 13.9x |
|
|
144
|
+
| | Linux | 20.4 s, 463 MB | 1.28 s, 371 MB | 16.0x |
|
|
145
|
+
| The same tracts joined to a CSV keyed on `GEOID` | macOS | 22.6 s, 652 MB | 1.09 s, 296 MB | 20.7x |
|
|
146
|
+
| | Linux | 25.9 s, 556 MB | 1.92 s, 325 MB | 13.5x |
|
|
147
|
+
| The points and the tracts, both `-zg`, merged to PMTiles | macOS | 1.20 s, 701 MB | 0.38 s, 269 MB | 3.2x |
|
|
148
|
+
| | Linux | 1.62 s, 573 MB | 0.68 s, 249 MB | 2.4x |
|
|
149
|
+
| The same, to MBTiles | macOS | 1.15 s, 707 MB | 0.40 s, 273 MB | 2.9x |
|
|
150
|
+
| | Linux | 1.51 s, 567 MB | 0.69 s, 258 MB | 2.2x |
|
|
151
|
+
| Counties at `-z5` and tracts at `-z9`, with `--overzoom` | macOS | 3.87 s, 592 MB | 0.39 s, 182 MB | 9.9x |
|
|
152
|
+
| | Linux | 5.99 s, 440 MB | 0.72 s, 196 MB | 8.3x |
|
|
153
|
+
|
|
154
|
+
The merges spend most of their time on a hundred tiles near the 500 KB limit, which manby join, like tile-join, has to compress with zlib to check their size. `bench/join.sh` has the benchmarks.
|
|
155
|
+
|
|
156
|
+
tile-join decodes each tile into layers that each allocate a megabyte of hash tables, does its overzooming one tile at a time, compresses every tile with zlib, and writes PMTiles by way of a SQLite database. manby join keeps tile-join's order of input tiles and its metadata, does the work on the tiles on every core without those tables, keeps the compression of tiles it does not change, and writes PMTiles directly. [DESIGN.md](DESIGN.md) has the details.
|
|
157
|
+
|
|
158
|
+
Where several inputs have a tile at the same z/x/y, tile-join appends their features in the order of the tiles' stored bytes. manby compresses most tiles with libdeflate, whose bytes sort differently from zlib's, so for tilesets that manby made, manby join compares tiles by the bytes zlib makes of them, which are tippecanoe's. So manby and then manby join make the tiles that tippecanoe and then tile-join make, with the tiles of tippecanoe's x86-64 build as above. tile-join itself, run on manby's tilesets, can order the features of those shared tiles differently. Tilesets that manby made with `--compression=zlib` are joined the same way by both.
|
|
159
|
+
|
|
160
|
+
## tippecanoe's other programs
|
|
161
|
+
|
|
162
|
+
manby also runs tippecanoe's smaller programs, as tippecanoe-rs has them, so one program does all of tippecanoe's work:
|
|
163
|
+
|
|
164
|
+
| tippecanoe | manby |
|
|
165
|
+
| --- | --- |
|
|
166
|
+
| `tippecanoe` | `manby` |
|
|
167
|
+
| `tile-join` | `manby join` |
|
|
168
|
+
| `tippecanoe-decode` | `manby decode` |
|
|
169
|
+
| `tippecanoe-enumerate` | `manby enumerate` |
|
|
170
|
+
| `tippecanoe-overzoom` | `manby overzoom` |
|
|
171
|
+
| `tippecanoe-json-tool` | `manby json-tool` |
|
|
172
|
+
|
|
173
|
+
Each program's own name works as the subcommand too (`manby tippecanoe-decode`), and under that name, through a link, manby is that program, so links named after all six make manby a drop-in replacement for tippecanoe. The tiling and joining are manby's own, since that is where the time goes, and so is overzooming, for its feature filters (below). Decoding, enumerating and json-tool are tippecanoe-rs's code and run at its speed.
|
|
174
|
+
|
|
175
|
+
Feature filters (`-j`, `-J`) take tippecanoe's expressions and three more. `["like", key, pattern]` is SQL's LIKE, with `%` for any run of characters and `_` for any one, and `["ilike", key, pattern]` ignores case; `!like` and `!ilike` are their negations, and a number or boolean is matched as its text. In `manby overzoom`, `["intersects", geometry]` keeps features that share a point with a GeoJSON Polygon or MultiPolygon in longitude and latitude, as clipped to the new tile.
|
|
176
|
+
|
|
177
|
+
To tile an input file named like a subcommand, such as `decode`, write it as `./decode`.
|
|
178
|
+
|
|
179
|
+
## Building and testing
|
|
180
|
+
|
|
181
|
+
manby uses tippecanoe-rs, in `crates/tippecanoe-rs`, as a library. The port has tippecanoe's six programs, built with `cargo build --release -p tippecanoe-rs`, and runs tippecanoe's test suite against them with `make -C crates/tippecanoe-rs test`.
|
|
182
|
+
|
|
183
|
+
```sh
|
|
184
|
+
cargo build --release
|
|
185
|
+
make test
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
`make test` runs the unit tests and tippecanoe's own test suite with manby in place of tippecanoe, from GeoJSON input and again from Geobuf input. All 188 of tippecanoe's expected outputs match, and the tests of tippecanoe's other programs pass with manby as each of them.
|
|
189
|
+
|
|
190
|
+
manby is a library first. `manby::run(&Options)` reads, tiles and writes a tileset and returns an error instead of exiting, `manby::join(&JoinOptions)` joins tilesets, and the commands are thin layers over them. The options are tippecanoe's, from a command line or as fields, and [docs.rs](https://docs.rs/manby) has the API.
|
|
191
|
+
|
|
192
|
+
## MapLibre Tiles
|
|
193
|
+
|
|
194
|
+
`--tile-format=mlt` writes [MapLibre Tiles](https://maplibre.org/maplibre-tile-spec/) instead of Mapbox Vector Tiles, with the same features, into PMTiles, MBTiles or a directory. The tiles are 2 to 45% smaller than MVT on the benchmarks, and MapLibre GL JS 5.12 and later reads them from a vector source with `encoding: "mlt"`.
|
|
195
|
+
|
|
196
|
+
```sh
|
|
197
|
+
manby -zg --drop-densest-as-needed --tile-format=mlt -o places.pmtiles places.geojson
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
The wheels and the release binaries write MLT. The encoder, mlt-core, needs Rust 1.98, so from source MLT output is a cargo feature, `cargo +1.98.1 build --release --features mlt`.
|
|
201
|
+
|
|
202
|
+
DESIGN.md describes the choices behind the tiles, and `make test-golden-mlt` checks them against the MVT tiles of the same runs.
|
|
203
|
+
|
|
204
|
+
## Fitting each tile on its own
|
|
205
|
+
|
|
206
|
+
When a tile is too big, tippecanoe raises its threshold for dropping, coalescing or clustering until it fits, then makes the whole zoom level again with the highest threshold any tile needed. `--as-needed-per-tile` keeps each tile's own threshold instead. Only the tiles that are too big are thinned, so the others keep more, but neighboring tiles can be thinned differently, which can show at tile edges. On the census tracts, the tiles of z5 keep 67,163 tract polygons rather than 17,094, and the run is 1.2 times faster. The tiles are not tippecanoe's.
|
|
207
|
+
|
|
208
|
+
## Thanks
|
|
209
|
+
|
|
210
|
+
manby is built on tippecanoe. [Erica Fischer](https://github.com/e-n-f) started it in 2014 and, over twelve years at Mapbox and then at Felt, wrote nearly all of it. The way it thins features evenly across a zoom level until every tile fits, and the test suite that pins all of that down, are what manby keeps, and they are her work. Thank you, Erica.
|
|
211
|
+
|
|
212
|
+
## License
|
|
213
|
+
|
|
214
|
+
BSD 2-Clause, see [LICENSE.md](LICENSE.md).
|
|
215
|
+
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
manby/__init__.py,sha256=Fd45M-Clc8HUB-Z3jQnFhCbnJlpLrUitXh_JOVTfR-0,12199
|
|
2
|
+
manby/__main__.py,sha256=M6VlyIaDLs5l166V21x6dM40ay7Jm9owcEvjqpBmdK0,85
|
|
3
|
+
manby/__pycache__/__init__.cpython-314.pyc,sha256=1PiL-HucmV7vayuOoEAr1jdrFHQ5eMI4dZ0LQleTthA,22772
|
|
4
|
+
manby-0.2.2.data/scripts/manby.exe,sha256=K5Vcn2mXXr5vONkSJeJrNrUDEgdbRkJJj3Zh713X-DE,23198208
|
|
5
|
+
manby-0.2.2.dist-info/METADATA,sha256=REfvX2acAeUD6BOPSgDMpkoilDOp0CczGXrAt7t6O-U,16565
|
|
6
|
+
manby-0.2.2.dist-info/WHEEL,sha256=Uvw7WSmy7Kj2FBk8Va4L_dq4MDW8X5Ynby-pOX3ZNS0,94
|
|
7
|
+
manby-0.2.2.dist-info/licenses/LICENSE.md,sha256=Upi1joh5kqUMCcE_BCGWLWs5oNN58iD7FolPAKhgNEk,1386
|
|
8
|
+
manby-0.2.2.dist-info/licenses/src/crs/NOTICE.md,sha256=5BE2__JERWN4OzbhgCD8zElQDTUxGYm6QXNtKwWfZjY,1607
|
|
9
|
+
manby-0.2.2.dist-info/sboms/manby.cyclonedx.json,sha256=P8YSKjoz9D-gwrbZeXQ8rrNSxoQj8TYc625lZAnzh3g,341899
|
|
10
|
+
manby-0.2.2.dist-info/RECORD,,
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Copyright (c) 2026, Birk Skyum
|
|
2
|
+
Copyright (c) 2022, Protomaps LLC
|
|
3
|
+
Copyright (c) 2014, Mapbox Inc.
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted provided that the following conditions
|
|
8
|
+
are met:
|
|
9
|
+
|
|
10
|
+
- Redistributions of source code must retain the above copyright notice,
|
|
11
|
+
this list of conditions and the following disclaimer.
|
|
12
|
+
- Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
|
14
|
+
and/or other materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
17
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
18
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
19
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
20
|
+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
21
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
|
22
|
+
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
23
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
24
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
25
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
26
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Notices
|
|
2
|
+
|
|
3
|
+
`definitions.txt.gz` holds the definitions of crs-defs (<https://github.com/birkskyum/crs-defs>), with these terms.
|
|
4
|
+
|
|
5
|
+
## EPSG data
|
|
6
|
+
|
|
7
|
+
The EPSG definitions are derived from the EPSG Geodetic Parameter Dataset, which is owned by the International Association of Oil and Gas Producers (IOGP). The EPSG Dataset is used under the EPSG Dataset Terms of Use, <https://epsg.org/terms-of-use.html>, and anyone who receives these definitions is bound by those terms. A definition that crs-defs marks as approximate is not the EPSG Dataset's own and must not be attributed to it.
|
|
8
|
+
|
|
9
|
+
> The EPSG Facilities are published by IOGP at no charge. Distribution for profit is forbidden. [...] The data may be used, copied and distributed subject to the following conditions: [...] neither the IOGP nor any of its members past present or future warrants their accuracy or will, regardless of its or their negligence, assume liability for any foreseeable or unforeseeable use made thereof, which liability is hereby excluded. Consequently, such use is at your own risk. You are obliged to inform anyone to whom you provide the EPSG Facilities of these Terms of Use. [...] Ownership of the EPSG Dataset by IOGP must be acknowledged in any publication or transmission (by whatever means) thereof (including permitted modifications).
|
|
10
|
+
|
|
11
|
+
## ESRI data
|
|
12
|
+
|
|
13
|
+
The ESRI definitions are derived from Esri's projection engine database. Copyright © 2010-2026 Esri. Licensed under the Apache License, Version 2.0, <https://www.apache.org/licenses/LICENSE-2.0>. The source is <https://github.com/Esri/projection-engine-db-doc>.
|