Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I make it work to make mbtile file? #3

Open
bongobongo opened this issue Nov 4, 2020 · 9 comments
Open

How do I make it work to make mbtile file? #3

bongobongo opened this issue Nov 4, 2020 · 9 comments

Comments

@bongobongo
Copy link

bongobongo commented Nov 4, 2020

I have compiled meta2tile.c and got it working to make a lot of single tiles from the meta tiles directory.
But I would like to make an mbtile file. Could someone provide some examples on what syntax to use when running meta2tile to produce mbtile (hopefully without having to change the c code)?

I tried to do this:
./meta2tile --mbtiles /var/lib/mod_tile/default /media/test/tissd/mbtiles/wz12.db
that gives this error:
cannot create directory /media/tore/tissd/mbtiles/wz12.db/12: No such file or directory

So even if I use --mbtiles as parameter meta2tile still want to create single meta tiles inside a directory that does not exist - because the last part in the last parameter (wz12.db) is the target filename for the mbtile file to be created (and not an existing directory).

After some trail and error - I found some text inside the meta2tile.c file that said one must define WITH_MBTILES
So then I created a copy of meta2tile.c - named meta2mbtile.c and added:
#define WITH_MBTILES
compiled and run it without luck.
then I changed
static int mbtiles = 0
to
static int mbtiles = 1
and now it created an mbtile file without any other input from command line than meta-tile-dir and target file name:
like this:
./meta2mbtile /var/lib/mod_tile/default /media/test/tissd/mbtiles/wz12.db

and then the file reported creating same number of tiles as when creating single tiles. So far so good....
But by some reason the numbering in tile_row column in the wz12.db file is wrong.
zoom_level is set correct to 12
tile_column is set correct from 0 to 4095
tile_row is from 1248 to 3943 - but should have been from 158 to 2847

Is there something else I have to change i the c file to make it work to get the tile_row value (and corresponding tile_data) correct, or even better - if there was some examples on how to use the original file with some parameters when running it from command line - to produce mbtile.

@woodpeck
Copy link
Contributor

woodpeck commented Nov 4, 2020

A typical mbtiles creation call would look like this (all on one line):

meta2tile  --mbtiles 
   --meta name='Paris' 
   --meta type=raster 
   --meta format=png 
   --meta version=1.0 
   --meta bounds='2.0,48.5,2.8,49.1' 
   --meta description='OpenStreetMap tiles for Paris, France' 
   /var/lib/mod_tile/default
   /media/test/tissd/mbtiles/wz12.mbtiles

The --meta thingies do not influence meta2tile's behaviour, but some mbtiles consumers will insist on this information being present. Changing anything in the source code should not be necessary (you'd usually do a -DWITH_MBTILES on the compiler comamnd line).

@woodpeck
Copy link
Contributor

woodpeck commented Nov 4, 2020

Apparently some applications use a flipped Y axis with mbtiles files. Mapbox's mb-util package will by default create the same style of mbtiles file as meta2tile, but supports a --scheme command line option that lets you request a "tms" scheme which has a flipped axis (see https://github.com/mapbox/mbutil). A pull request to add such a command line option to meta2tile would be viewed favourably. If you're looking for quick hack, modify

sqlite3_bind_int(t->sqlite_tile_insert, 2, ty);
and add a logic like https://github.com/mapbox/mbutil/blob/2fc4161f9be890a65d07f5e7b2ed0c8a0a123ed6/mbutil/util.py#L16-L17.

@bongobongo
Copy link
Author

bongobongo commented Nov 4, 2020

When I use meta2tile to make lots of stand alone tiles from the meta tiles, like this:
./meta2tile /var/lib/mod_tile/default /media/test/tissd/mbtiles/

all those subdirs and tiles are corrext (z,x,y).
.../mbtiles/12 (zoom)
.../mbtiles/12 / 0 to .../mbtiles/12/4095
and each file below those dirs consist of tiles numbered from 158 to 2847
which correspond with the coordinates given to render_list when creating the meta tiles.

If it is a flipped Y axis problem when creating mbtile files, why is not same problem happening when creating lots of single tiles from the meta tiles - using meta2tile (works flawlessly)?
The meta tiles have been created using render_list after a "standard" import from planet pbf - where the recipy was found here:
https://www.linuxbabe.com/ubuntu/openstreetmap-tile-server-ubuntu-20-04-osm

I will look closer into the tiles in the generated mbtiles file - to see if the tiles have been flipped, and report back.

@woodpeck
Copy link
Contributor

woodpeck commented Nov 4, 2020

I cannot explain what you describe. The code determines the Y coordinate in

int ty = y + (meta % METATILE);
and then uses that coordinate when writing a file
sprintf(path, "%s/%d/%d/%d.%s", t->pathname, z, tx, ty, (file_is_jpeg || tojpeg) ? "jpg" : "png");
as well as when writing a mbtiles database
sqlite3_bind_int(t->sqlite_tile_insert, 2, ty);
- I do not see any code to flip the Y axis. Are you sure that the code you have compiled is the current version from this repository? If all else fails, generate individual tiles and use the mbutil program to make an mbtiles file from them.

@bongobongo
Copy link
Author

bongobongo commented Nov 4, 2020

Hi again. Looked more closely into the generated mbtile file that was generated by the meta2tile file where I changed two lines.
Looks like you are correct about the y axis flipping.
tile_column = 2164
tile_row = 2886, but should have been 1209
control (all this is zoom level 12):
4095 - 1209 = 2886.

When I downloaded the files that I used from this repository, I just went here:
https://github.com/geofabrik/meta2tile

then I clicked on the file meta2tile.c,
then clicked on the RAW button, and then right-clicked and saved the file.
Then repeated the same with the header files.
Probably not a normal way to do it, but should that not be okay to do?
I did the downloads yesterday.

UPDATE: Just checked both the original meta2tile.c and the one I changed - both have the code intact regarding the ty variable.
I'll try the mbutil program, like you suggested.

Thanks a lot for the quick replies.

@bongobongo
Copy link
Author

bongobongo commented Nov 4, 2020

Okay, thouth I should give it a try by using
git clone https://github.com/geofabrik/meta2tile.git

then when I run make I got fatal error: zip.h: No such file or directory
So I removed -DWITH_ZIP and -lzip (not needed by me anyway).

then make again and it gets compiled.
Then I do this:
./meta2tile --mbtiles /var/lib/mod_tile/default /media/test/tissd/mbtiles/planet-z12.db

and the mbtile is generated.
BUT - I get the exact same problem as earlier - with the flipped y axis in the mbutil file.
So now I will try using mbutil to make a mbtile file from the many single.

@bongobongo
Copy link
Author

Using mbutil (with --scheme=tms ) on the stand alone tiles generated by meta2tile fixed the flipped y issue. Thanks a lot for that quick fix suggestion. Next now will be to create a pull request so hopefully we can get the tms option in meta2tile. I will enter that request tomorrow.

@bongobongo
Copy link
Author

bongobongo commented Nov 9, 2020

Apparently some applications use a flipped Y axis with mbtiles files. Mapbox's mb-util package will by default create the same style of mbtiles file as meta2tile, but supports a --scheme command line option that lets you request a "tms" scheme which has a flipped axis (see https://github.com/mapbox/mbutil). A pull request to add such a command line option to meta2tile would be viewed favourably. If you're looking for quick hack, modify

sqlite3_bind_int(t->sqlite_tile_insert, 2, ty);

and add a logic like https://github.com/mapbox/mbutil/blob/2fc4161f9be890a65d07f5e7b2ed0c8a0a123ed6/mbutil/util.py#L16-L17.

When I go to "Pull requests" I see this message:
"If you know how to fix an issue, consider opening a pull request for it."
Well, I do not know how to fix the issue in question (in meta2tile), and when I click the button "New pull request" I do not get to a place where I can enter a pull request. So I cannot create the pull request you mentioned.
So, perhaps you could create the pull request and add a command line option to meta2tile: --scheme, and if set to tms will make flipped y axis.

@woodpeck
Copy link
Contributor

woodpeck commented Nov 9, 2020

The "pull request" is for if you have solved the issue. If you cannot solve the issue and just want someone else to solve it, then things are ok as they are, we'll just leave this issue open until someone has the time to fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants