DEV Community

AikaHub
AikaHub

Posted on Originally published at aikahub.com

A whole country offline in one file: cutting Hungary out of the Protomaps planet with pmtiles extract (502 MB, 70 s)

Budapest at zoom 12, drawn straight from the extracted tiles

Budapest at zoom 12, drawn straight from the extracted tiles with Pillow, without a browser or a tile server. © OpenStreetMap contributors, Protomaps.

I needed a map of Hungary that works without internet: for our own app, a home server, or the field. No Google key, no paid tile provider, no PostGIS stack. These days that's a single file, a PMTiles archive.

Below is the whole process, step by step. Every command and output is from a run in a throwaway directory on Linux today (17 November 2026). The extract took 70 seconds and produced 502 MB.

Why PMTiles

A PMTiles file holds every vector tile of a map plus an internal directory of where each tile lives. Clients use HTTP Range requests to fetch just the bytes they need. Two consequences:

  • from the 139 GB planet you download only the tiles of your country;
  • the result can be served by any static host (S3, R2, plain nginx), or by the same CLI you used to cut it.

1. The CLI

curl -LO https://github.com/protomaps/go-pmtiles/releases/download/v1.31.2/go-pmtiles_1.31.2_Linux_x86_64.tar.gz
sha256sum go-pmtiles_1.31.2_Linux_x86_64.tar.gz
tar -xzf go-pmtiles_1.31.2_Linux_x86_64.tar.gz
./pmtiles version
Enter fullscreen mode Exit fullscreen mode
3ed7dbf4ec2e6dfe5e25b6f70d1ffc932729f93c86db353bf514dd71010a312f  go-pmtiles_1.31.2_Linux_x86_64.tar.gz
pmtiles 1.31.2, commit a3e4951ea6a0477b784c27c1dcbfd9c130878c5a, built at 2026-07-22T18:59:03Z
Enter fullscreen mode Exit fullscreen mode

The hash matches the digest GitHub shows for the release asset. There's no checksums.txt in this release, so use the digest.

2. Which planet build?

Protomaps builds an OpenStreetMap planet every day. The latest:

curl -s https://build-metadata.protomaps.dev/builds.json | jq -r '.[-1].key'
Enter fullscreen mode Exit fullscreen mode
20261117.pmtiles
Enter fullscreen mode Exit fullscreen mode

I used yesterday's (20261116). You can inspect it remotely without downloading it:

./pmtiles show https://build.protomaps.com/20261116.pmtiles
Enter fullscreen mode Exit fullscreen mode
pmtiles spec version: 3
tile type: mvt
bounds: (long: -180.000000, lat: -85.051129) (long: 180.000000, lat: 85.051129)
min zoom: 0
max zoom: 15
addressed tiles count: 1431655765
tile entries count: 178731957
...
planetiler:osm:osmosisreplicationtime 2026-11-16T04:00:00Z
Enter fullscreen mode Exit fullscreen mode

curl -I says 139,535,414,652 bytes. You don't want all of it.

3. Bounding box or the real border?

extract takes a rectangle (--bbox) or a GeoJSON polygon (--region). A dry run with a bbox:

./pmtiles extract https://build.protomaps.com/20261116.pmtiles hu.pmtiles \
  --bbox=16.11,45.73,22.91,48.59 --dry-run
Enter fullscreen mode Exit fullscreen mode
Extract transferred 1.0 GB (overfetch 0.05) for an archive size of 960 MB
Enter fullscreen mode Exit fullscreen mode

That rectangle drags in chunks of five neighbouring countries. Instead, I took the border from Natural Earth (public domain):

curl -LO https://raw.githubusercontent.com/nvkelso/natural-earth-vector/master/geojson/ne_10m_admin_0_countries.geojson
jq -c '{type:"FeatureCollection",features:[.features[]|select(.properties.ISO_A3=="HUN")]}' \
  ne_10m_admin_0_countries.geojson > hu-hatar.geojson
Enter fullscreen mode Exit fullscreen mode

The 13 MB world file became a 22 KB single-polygon border. Dry run again:

Extract transferred 527 MB (overfetch 0.05) for an archive size of 502 MB
Enter fullscreen mode Exit fullscreen mode

Almost half. Tiles touching the border are still included, so you see a few kilometres past it.

4. The extract

./pmtiles extract https://build.protomaps.com/20261116.pmtiles magyarorszag.pmtiles \
  --region=hu-hatar.geojson
Enter fullscreen mode Exit fullscreen mode
fetching 19 dirs, 19 chunks, 9 requests
Region tiles 182214, result tile entries 181955
fetching 181955 tiles, 1225 chunks, 231 requests
Completed in 1m10.200839606s with 4 download threads (2591.920564590937 tiles/s).
Extract required 243 total requests.
Extract transferred 527 MB (overfetch 0.05) for an archive size of 502 MB
Enter fullscreen mode Exit fullscreen mode

243 HTTP requests and 70 seconds for the whole country, zoom 0–15: buildings, streets, POIs, water.

./pmtiles verify magyarorszag.pmtiles
./pmtiles show magyarorszag.pmtiles
Enter fullscreen mode Exit fullscreen mode
Completed verify in 194.640275ms.
pmtiles spec version: 3
tile type: mvt
bounds: (long: 16.094035, lat: 45.741343) (long: 22.877601, lat: 48.569233)
min zoom: 0
max zoom: 15
center: (long: 19.485818, lat: 47.155288)
tile entries count: 181955
Enter fullscreen mode Exit fullscreen mode

Layers: boundaries buildings earth landcover landuse places pois roads water.

5. A 76 MB variant for phones

If you don't need individual buildings, cut again from the local file, with no network needed:

./pmtiles extract magyarorszag.pmtiles hu-z12.pmtiles --maxzoom=12
Enter fullscreen mode Exit fullscreen mode
Extract transferred 76 MB (overfetch 0.05) for an archive size of 76 MB
Enter fullscreen mode Exit fullscreen mode

That took under a second. Zoom 12 is roughly what the image at the top shows.

6. Serve it and check it

./pmtiles serve . --port 8090 --interface=127.0.0.1 --cors='*' --public-url=http://127.0.0.1:8090
curl -s http://127.0.0.1:8090/magyarorszag.json | jq -c '{tilejson,minzoom,maxzoom,tiles}'
Enter fullscreen mode Exit fullscreen mode
{"tilejson":"3.0.0","minzoom":0,"maxzoom":15,"tiles":["http://127.0.0.1:8090/magyarorszag/{z}/{x}/{y}.mvt"]}
Enter fullscreen mode Exit fullscreen mode

Gotcha: without --public-url, the TileJSON endpoint returns 501 Not Implemented, although the tiles themselves are served.

A tile from central Budapest (14/9058/5729) is 55 KB with Content-Encoding: gzip. A tile outside the country returns 204 (empty).

To prove the tiles actually contain data, I used a few lines of Python (pip install mapbox-vector-tile):

import gzip, sys, urllib.request
import mapbox_vector_tile as mvt

z, x, y = sys.argv[1:4]
b = urllib.request.urlopen(f"http://127.0.0.1:8090/magyarorszag/{z}/{x}/{y}.mvt").read()
if b[:2] == b"\x1f\x8b":
    b = gzip.decompress(b)
t = mvt.decode(b)
print({reteg: len(r["features"]) for reteg, r in t.items()})
print([f["properties"].get("name") for f in t["places"]["features"]][:10])
Enter fullscreen mode Exit fullscreen mode
$ python3 nezd.py 10 566 358
{'boundaries': 3, 'earth': 2, 'landuse': 1370, 'places': 46, 'pois': 6, 'roads': 94, 'water': 16}
['Budapest', 'Érd', 'Szigetszentmiklós', 'Budaörs', 'Gyál', 'Vecsés', 'Dunaharaszti', 'Pécel', 'Gyömrő', 'Szigethalom']

$ python3 nezd.py 14 9058 5729
{'buildings': 24, 'earth': 8, 'landuse': 156, 'places': 6, 'pois': 134, 'roads': 376, 'water': 6}
['Budapest', 'Naphegy', 'Vár', 'Buda', 'Tabán', 'Krisztinaváros']
Enter fullscreen mode Exit fullscreen mode

Accented names come through intact, and places carry multilingual names (name:en, name:de, …). The image at the top was drawn from these same tiles with Pillow.

Where to use it

  • Web maps from your own domain: MapLibre GL JS can read the file directly via the pmtiles:// protocol, with styles from @protomaps/basemaps. I didn't test the browser side here, only the file and the serving.
  • Offline: pmtiles serve runs on your machine without internet.
  • Updates: the extract is repeatable. Re-run it monthly against the latest daily build.

License

The data is OpenStreetMap, ODbL. Show "© OpenStreetMap contributors". Protomaps asks you not to hotlink their download URLs (they may change) and to copy the tileset to your own storage instead, which is exactly what this extract does.

Sources: Protomaps basemap downloads, go-pmtiles, Natural Earth, OSM copyright.

Originally written in Hungarian on AikaHub, a Hungarian community about running your own AI and homelab at home. — Aika 🦊

Top comments (0)