Is there a way to generate a .mbtiles file from .osm.pbf file
Asked Answered
O

6

5

I have an .osm.pbf file which I want to use to generate vector tiles with (.mbtiles).

Im currently on a windows machine utilising docker, I have tried to use the tool tilemaker (https://github.com/systemed/tilemaker) though I cannot get it to work on my files and get issues like so

" terminate called after throwing an instance of 'std::runtime_error' what(): Exception during zlib decompression: (-5) "

I was just wondering if anyone else was able to generate these tiles from said file type, if so could you provide a low level detailed guide on how you did so, as I am new to vector tiles and am getting confused within some circumstances.

For anyone interested I use this code to run the docker:

docker run tilemaker tilemaker --input=sud-latest.osm.pbf --output=sud.mbtiles

I have to put tilemaker twice as otherwise it says it cannot open the .osm.pbf otherwise

Overkill answered 22/1, 2021 at 16:51 Comment(0)
S
2

You can use ogr2ogr (see other answer here) to translate osm.pbf into geojson, and then Mapbox's tippecanoe tool to convert the geojson to mbtiles.

Softfinned answered 22/1, 2021 at 17:35 Comment(4)
have you got an installation guide for both of these for windows or docker? as both of the installation materials on the sites are quick confusing or lacking in a low level guideOverkill
I assume that if you have docker, you can easily run linux in a container? I blieve both have instructions for it.Softfinned
Ive managed to produce the files I want using both of these, eventually after I figured out how to install both off them, thank youOverkill
Though Ive just noticed that is has produced some odd metadata, its also not compatible with tileserver php, any ideas why this may be? heres a link to an issue on tippecanoe ive made, this way you can see the metadata too github.com/mapbox/tippecanoe/issues/898Overkill
K
11

Extract .pbf to .mbtiles

Install

brew install osmium-tool
brew install tippecanoe

Extract

extract .pbf to .geojson

osmium export xxx.pbf -o xxx.geojson

extract .geojson to .mbtiles

tippecanoe -zg -o xxx.mbtiles --drop-densest-as-needed xxx.geojson

2023-08-17 Edit

Using tilemaker is a better option

Install

git clone https://github.com/systemed/tilemaker.git
cd tilemaker
docker build -t tilemaker .

Extract

docker run --rm -it -v $(pwd):/srv tilemaker --input=/srv/xxx.osm.pbf --output=/srv/xxx.mbtiles
Kindliness answered 6/7, 2023 at 7:9 Comment(0)
C
3

I made a tutorial on how to generate tiles using maptiler: https://blog.kleunen.nl/blog/tilemaker-generate-map

It is focused on linux, but you can run it on windows as well. You can find a pre-built version of maptiler on the CI: https://github.com/systemed/tilemaker/pull/208/checks?check_run_id=2143761163

Probably soon they will also become available on the github page. Once you have the prebuilt executable and the resources (config and process lua), you can simply do:

tilemaker.exe --input=sud-latest.osm.pbf --output=sud.mbtiles --process resources/process-openmaptiles.lua --config resources/config-openmaptiles.json

The output works best from zoom level 8 - 14, borders are still missing, so lower zoom levels look pretty empty.

Container answered 18/3, 2021 at 20:59 Comment(0)
S
2

You can use ogr2ogr (see other answer here) to translate osm.pbf into geojson, and then Mapbox's tippecanoe tool to convert the geojson to mbtiles.

Softfinned answered 22/1, 2021 at 17:35 Comment(4)
have you got an installation guide for both of these for windows or docker? as both of the installation materials on the sites are quick confusing or lacking in a low level guideOverkill
I assume that if you have docker, you can easily run linux in a container? I blieve both have instructions for it.Softfinned
Ive managed to produce the files I want using both of these, eventually after I figured out how to install both off them, thank youOverkill
Though Ive just noticed that is has produced some odd metadata, its also not compatible with tileserver php, any ideas why this may be? heres a link to an issue on tippecanoe ive made, this way you can see the metadata too github.com/mapbox/tippecanoe/issues/898Overkill
V
0

possible solutions :

1.Might be RAM issue try to run small size osm.pbf file with tilemaker

2.Run tilemaker.exe from executable file (by making build from github tilemaker clone) ---> it may solve most of issues

Vltava answered 17/11, 2021 at 17:0 Comment(0)
M
0

I didn't face with the "terminate called ..." error, but i faced with the same error you've described regarding "cannot open the file", so here is my

Low-level tutorial: how to convert osm.pbf into .mbtiles via tilemaker

First of all, use another image: stadtnavi/tilemaker. Image tilemaker seems to be broken inside, it shows either

    Couldn't open .pbf file /srv/germany.osm.pbf

or

    Invalid JSON file.

But the source file is ok and successfully converted by stadtnavi/tilemaker.

Create the following docker-compose.yaml

services:
  tilemaker:
    image: stadtnavi/tilemaker:latest
    volumes:
      - ./srv:/srv
    entrypoint: [ "bash", "-c", "/tilemaker /srv/germany.osm.pbf --output=/srv/germany.mbtiles"]

Put it near the file to be converted. In my example it is a parent directory of /srv, all the osm.pbf are in the /srv.

Execute docker-compose up

And that's it. The output .mbtiles file will be created near the input osm.pbf in some time.

Mesopotamia answered 11/4 at 11:43 Comment(0)
C
0

Further to Michael's post, I found that a leading slash didn't work on Windows for the volume creation, which led to not finding the PBF file. I also found the default config absolutely did not load automatically, but if I specified then it ran fine. I saved the PBF at C:\osm\united-kingdom.pbf and My CLI command (after building the image) was:

docker run -v C:\\osm:/srv -i -t --rm tilemaker --input /srv/united-kingdom.pbf --output /srv/uk.mbtiles --config resources/config-openmaptiles.json --process resources/process-openmaptiles.lua --store /srv
Cindiecindra answered 17/4 at 10:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.