Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
post

MBTiles in QGIS

Introduction to MBTiles in QGIS

QGIS, a leading open-source GIS software, offers a wide range of tools for geospatial analysis, including the ability to work with MBTiles — a format designed for storing and packaging sets of raster or vector map tiles. This guide will walk you through the basics of MBTiles, their importance, and how to integrate them into your QGIS projects.

If you are using QGIS and working with MBTiles, check out our podcast!

1. Understanding MBTiles

What are MBTiles?

MBTiles is an open specification for storing map tiles in a single SQLite database file, making it straightforward to transport and use large sets of map tiles offline. The format supports both raster tiles (PNG or JPEG images) and vector tiles.

Why Use MBTiles in QGIS?

  • Offline Access: Ideal for fieldwork in areas without internet connectivity.
  • Efficiency: Reduces the need to fetch online map tiles repeatedly, saving data and time.
  • Customisation: Allows users to create tailored map layers for specific projects.

MBTiles vs. Traditional Tile Access

While traditional tile access fetches data online every time, MBTiles store this data locally, ensuring faster load times and reduced dependency on internet connectivity.

Setting Up Your QGIS Environment

Before diving into the creation and management of MBTiles, it is important to ensure that your QGIS environment is optimised for the task. A well-organised workspace not only enhances efficiency but also ensures that you have all the necessary tools at your fingertips. Here is how to get started:

a. Accessing the Right Panels and Toolbars

QGIS offers a wide range of panels and toolbars, each designed for specific tasks. For working with MBTiles, ensure you have the Browser Panel and Layers Panel readily accessible. These are instrumental in managing and viewing your MBTiles.

b. Using the Browser Panel

The Browser Panel in QGIS functions like a file manager tailored for geographical data. It provides a hierarchical view of all your data sources, including databases, web services, and file systems. When working with MBTiles, this panel is your primary tool for accessing and managing these files.

c. Restoring Missing Panels

If you cannot locate the Browser Panel or any other essential panel, simply right-click on the toolbar area and select the panel you need. Alternatively, navigate to View > Panels from the top menu to manage your panels.

d. Familiarising Yourself with XYZ Tiles

When working with MBTiles, you will frequently encounter the term XYZ Tiles. These are web-based tile services that deliver map layers as small image chunks, referenced by column (X), row (Y), and zoom level (Z). In QGIS, the Browser Panel lists available XYZ Tile connections under the XYZ Tiles section.

e. Customising Preferences

While QGIS’s default settings are robust, you may want to adjust some preferences for a smoother experience with MBTiles. Navigate to Settings > Options and explore the Network tab. Here you can adjust settings such as cache size and network timeouts, which influence how QGIS interacts with online tile services.

With your QGIS environment set up, you are ready to work with MBTiles. The following sections guide you through connecting to tile services, generating your own MBTiles, and making the most of this format in your GIS projects.

Connecting to XYZ Tiles in QGIS

The ability to connect to and use XYZ tiles is one of the standout features of QGIS, allowing users to tap into a wide array of online map services. These tiles — small map image chunks — are assembled to form comprehensive maps. Here is how to use XYZ tiles within QGIS:

a. Understanding XYZ Tiles

XYZ tiles are web-based tile services that deliver map data in small chunks, enabling efficient loading and smooth zooming. Each tile is addressed by three integers: X (tile column), Y (tile row), and Z (zoom level). This scheme, sometimes called the slippy map tile numbering convention, is used by OpenStreetMap, Google Maps, and most modern web mapping services.

b. Accessing Pre-loaded Tiles

QGIS includes OpenStreetMap as a pre-loaded XYZ tile connection. To access it, expand the XYZ Tiles section in the Browser Panel. You can drag the layer to the Layers Panel or double-click it to add it to your map.

c. Adding New Tile Connections

To add additional tile services, follow these steps:

  • Right-click on XYZ Tiles in the Browser Panel.
  • Choose New Connection.
  • Enter a name and the URL template for the tile service. URL templates can usually be found on the service provider’s website or GIS community forums.
  • Click OK to save. The new tile service will appear under XYZ Tiles.

d. Loading Your Tiles

Once a connection is set up, double-click the tile service in the Browser Panel or drag it to the Layers Panel. The tiles will load and you can navigate the map as you would with any other layer.

e. Exploring Different Tile Options

Different tile services offer different visual styles and data. A satellite imagery service will show different content from a topographic or street-map service. By adding multiple tile connections, you can switch between layers based on your project’s needs.

f. Managing Tile Connections

To edit or remove a tile connection, right-click it in the Browser Panel and select the appropriate option.

Connecting to XYZ tiles in QGIS opens up a wide range of mapping possibilities. The following sections cover how to generate your own MBTiles from these services and use them for offline mapping.

Generating Your Own MBTiles in QGIS

Generating your own MBTiles in QGIS gives you map data that is available offline and tailored to your project. Here is how to do it:

a. Why Generate MBTiles?

MBTiles provide a compact, efficient way to store map data. They are well suited for:

  • Offline work, especially in remote areas without internet access.
  • Custom projects where specific map details are required.
  • Reducing data usage by avoiding constant online tile fetching.

b. Preparing Your Map View

Before generating MBTiles, ensure your QGIS map canvas displays exactly what you want to capture. Zoom to the desired extent and make sure the correct layers are active.

c. Accessing the MBTiles Generation Tool

  • Open the Processing Toolbox in QGIS.
  • Expand the Raster tools section.
  • Double-click Generate XYZ tiles (MBTiles).

d. Setting Parameters for MBTiles Generation

  • Extent: Define the geographical area for your MBTiles. You can draw directly on the canvas, use the current map view, or enter coordinates manually.
  • Zoom Levels: Define the minimum and maximum zoom levels to capture. Higher zoom levels add more detail but also significantly increase file size.
  • DPI: Set the tile resolution. Higher DPI produces sharper images but increases file size.
  • Format: Choose between PNG and JPEG. PNG is lossless; JPEG produces smaller files with some quality reduction.
  • Output File: Choose a name and location for the output .mbtiles file.

e. Running the Tool

Once all parameters are set, click Run. QGIS will fetch the tiles and package them into an MBTiles file. Processing time varies depending on the extent and zoom levels chosen.

f. Loading and Using Your MBTiles

After generation, load your MBTiles into QGIS by dragging and dropping the .mbtiles file into the map canvas or the Layers Panel. Your offline map is then ready to use.

Advanced Tips and Best Practices for MBTiles in QGIS

There are several techniques that can improve your experience and the efficiency of your MBTiles workflow in QGIS.

a. Optimise for File Size

MBTiles can become large, especially when capturing broad areas at high zoom levels. To manage file size:

  • Limit zoom levels: the highest zoom levels add substantial size without adding much value for broad geographical overviews.
  • Choose JPEG over PNG where image quality allows, as JPEG compression can significantly reduce file size.

b. Layering with MBTiles

QGIS supports layering MBTiles with other datasets. When doing so:

  • Ensure your MBTiles layer is ordered correctly in the Layers Panel relative to other data layers.
  • Use transparency settings to make underlying layers visible where needed.

c. Back Up Your MBTiles

Given the time and data required to generate large MBTiles files, always keep backups stored in multiple locations to prevent data loss.

d. Update MBTiles Periodically

If you are using MBTiles for professional or research purposes, regenerate them periodically to ensure you are working with the most current and accurate map data.

e. Test on Target Devices

If you are creating MBTiles for use on specific devices such as tablets or smartphones, always test the files on those devices to confirm compatibility and acceptable performance.

f. Document Your Process

Given the range of parameters involved in generating MBTiles, document your settings. This makes it straightforward to replicate or update your MBTiles in the future.

This podcast provides an excellent overview of the tile creation process

Frequently Asked Questions about MBTiles in QGIS

How do I generate MBTiles in QGIS?

You can generate MBTiles using the Generate XYZ tiles (MBTiles) tool found in the Raster tools section of the Processing Toolbox.

Can I use MBTiles for offline mapping in QGIS?

Yes. MBTiles are specifically designed for offline use, making them ideal for fieldwork or areas without stable internet connectivity.

What is the difference between MBTiles and regular online map tiles?

Online map tiles are fetched from the internet each time they are accessed. MBTiles are stored locally in a single SQLite database file, allowing faster access and eliminating the need for an internet connection.

How can I optimise the size of my MBTiles file in QGIS?

Select appropriate zoom levels, choose JPEG format over PNG where quality permits, and limit the geographical extent to only the area you need.

Are there any licensing issues I should be aware of when creating MBTiles?

Yes. Always ensure you have the right to use and redistribute the map data you are converting into MBTiles. Many online map services restrict offline caching or redistribution of their tiles in their terms of service.

How do I update my MBTiles with new map data in QGIS?

You will need to regenerate the MBTiles file using the updated source data.

Can I layer multiple MBTiles in QGIS?

Yes. Multiple MBTiles files can be loaded and layered just like any other layer type in QGIS.

Is there a limit to the size or zoom levels for MBTiles in QGIS?

There is no strict limit, but larger extents and higher zoom levels produce larger files that are more resource-intensive to generate and use.

Can I export MBTiles from QGIS to use in other applications?

Yes. MBTiles generated in QGIS follow the open MBTiles specification and can be used in any application or device that supports the format, including mobile field data tools and tile servers.

About the Author
I'm Daniel O'Donohue, the voice and creator behind The MapScaping Podcast ( A podcast for the geospatial community ). With a professional background as a geospatial specialist, I've spent years harnessing the power of spatial to unravel the complexities of our world, one layer at a time.