Skip to content

Instantly share code, notes, and snippets.

@zhm
Created October 3, 2012 23:09
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save zhm/3830471 to your computer and use it in GitHub Desktop.
Save zhm/3830471 to your computer and use it in GitHub Desktop.
Delete zoom levels from an MBTiles file (set max zoom)
-- change 18 to whatever the max zoom level you want in your MBTiles
DELETE FROM images WHERE
tile_id IN (SELECT tile_id FROM map WHERE zoom_level > 18) AND
tile_id NOT IN (SELECT tile_id FROM map WHERE zoom_level <= 18);
DELETE FROM map WHERE zoom_level > 18;
UPDATE metadata SET value = '18' WHERE name = 'maxzoom';
-- now run the VACUUM command
@mabsplanner
Copy link

Hello,
I'm badly in need to change max. zoom level of my *.mbtiles file. Can you please help how to use these codes. I'm completely new in GistBox. I'm not sure where and how to use these codes. Please help me. Any help will make me grateful to you.

Regards,
Siddique

@mapmeld
Copy link

mapmeld commented Jun 13, 2015

I'm doing this on a raster MBtiles which doesn't have an "images" table. If you're in the same situation, replace the first two statements with this:

DELETE FROM tiles WHERE zoom_level > 18;

@moneytoo
Copy link

DELETE FROM tiles_data WHERE 
  tile_data_id IN (SELECT tile_data_id FROM tiles_shallow WHERE zoom_level > 9) AND
  tile_data_id NOT IN (SELECT tile_data_id FROM tiles_shallow WHERE zoom_level <= 9);

DELETE FROM tiles_shallow WHERE zoom_level > 9;

UPDATE metadata SET value = '9' WHERE name = 'maxzoom';

VACUUM;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment