Slippy map tile generator for QGIS
This program is a slippy map tile generator for use with QGIS.
All rendering is done by QGIS so what you see on your screen is
what you'll get in your output tiles. Functionally it is quite
similar to the QTiles plugin. Here's a comparison of the two:
Advantages of this program
All styling is done using QGIS.
Renders the map a section at time.
This allows even very large datasets to be rendered.
Renders each zoom level separately.
This means that scale-dependant feature visibility is honored.
Does not exhibit the rendering issues that QTiles has at tile edges:
- Does not truncate point icons
- Labels don't shift
- Patterned lines display correctly
20 minutes to render a complex 60km × 70km topographic map with roads, water, POIs, etc. from levels 5 through 15 on a 3.5GHz i7.
Resistant to the QGIS bug that causes raster layers to sometimes
not be displayed.
Copious progress status display
Simple Python script that can be easily modified to suit your needs.
Disadvantages of this program
No graphical interface.
Cannot be made to stop early without killing QGIS.
Rendering complex maps causes the QGIS GUI to temporarily freeze during
some parts of the rendering process.
Lacks some of the additional options that QTiles offers.
Some tiles will be output that are not within the area of interest.
This happens because large regions are rendered and sliced into tiles.
All of a region's tiles are written to disk without checking whether they
are within the area of interest.
Might not work under QGIS 3.x.
This program has been tested under QGIS 2.x.
Reports indicate that it does not function on the 3.x series.
Comments are welcome, see the email link at the bottom of the page.
v0.2.1 Documentation updates, added scale presets file (no code changes)
Create your map in QGIS
Set the map's appearance (layer and feature visibility, symbology, etc.) to how you want the tiles to appear.
If you are using scale-dependant feature visibility see the section
Zoom levels below
Running the script
- Download the latest version of this script (see above)
- Extract the files
globalmercator.py into the same directory
(As packaged, this has already been done)
- In QGIS, open the Python console (Plugins→Python Console)
- Click on the "Show editor" icon in the Python Console (middle icon)
- Load the
tile_writer.py script using the "Open file" icon (top icon on the right)
Define the map's area of interest:
- Create a new polygon vector layer
- Make it editable
- Add a polygon covering the area you want rendered
Save it to disk; the filename you chose should be put into the
variable in the script.
- Hide the layer
- Adjust the settings to suit your needs (see below).
Note that all non-absolute paths and filenames are relative to QGIS's current working directory.
- If you run QGIS from the commandline then the directory you started it from is the working directory.
- If you run QGIS from a graphical interface under Unix/Linux then the working directory is probably your home directory.
- If you run QGIS under Windows drop me an email and let me know what QGIS's working directory is ☺
- Run the script using the "Run script" icon (the bottom icon)
- The script's progress will appear in the console
- An "All done" message will be printed when the script has finished
Note that QGIS may appear to have locked up while generating the regional
tiles. If this happens simply be patient; complex maps may take several
minutes to draw.
The script will avoid regenerating images whenever possible. This means that if
you want to regenerate a map you should either specify a different
or first delete all of the tile directories (numbered) as well as the region
tiles (e.g. "
These are found near the top of
and should be changed as
appropriate before running the script.
Minimum zoom level
Default value: 10
Maximum zoom level
Default value: 15
How many map tiles to place in each regional tile
(the actual number of map tiles per regional tile is step × step)
Higher number speed up rendering (assuming enough RAM is available).
Lower numbers decrease memory usage but increase rendering time.
Default value: 16
Number of extra map tiles to render along each edge of a regional tile
By rendering extra, unused border tiles we can avoid shifting labels,
truncated images, and line-drawing inconsistancies at tile boundaries.
If this value is set to 0 you will encounter rendering issues at tile boundaries.
Default value: 2
Directory to write the regional images and level subdirectories to
Default value: '.'
Path of shapefile defining the area of interest
The extent of the shapefile is used to limit rendering to a particular area.
Note that no clipping is done so at lower zoom levels tiles from outside the
area of interest will be generated.
Default value: 'border.shp'
Filename convention to follow
Can be set to either 'tms' or 'google'
Default value: 'tms'
If you are using scale-dependant feature visibility you should use the scales listed below when
Settings → Options → Map Tools → Predefined Scales → Import from file (folder icon)
||1 : 295,829,355.45
||1 : 147,914,677.73
||1 : 73,957,338.86
||1 : 36,978,669.43
||1 : 18,489,334.72
||1 : 9,244,667.36
||1 : 4,622,333.68
||1 : 2,311,166.84
||1 : 1,155,583.42
||1 : 577,791.71
||1 : 288,895.85
||1 : 144,447.93
||1 : 72,223.96
||1 : 36,111.98
||1 : 18,055.99
||1 : 9,028.00
||1 : 4,514.00
||1 : 2,257.00
||1 : 1,128.50
||1 : 564.25
||1 : 282.12
||1 : 141.06
||1 : 70.53
Other GIS pages on this site
Useful GIS commands
A set of commands for common GIS tasks using GDAL, OGR, and QGIS.
Google/OSM to TMS tile renamer
Simple BASH script to rename map tiles from Google Maps/OpenStreetMap
format to Tile Map Service format.
Geo::Index (offsite link)
Perl module for creating and searching in-memory geographic point indices.
I make no warranty or representation, either express or implied, with respect the behavior of this script, its quality, performance, accuracy, merchantability, or fitness for a particular purpose. This script is provided 'as is', and you, by making use thereof, are assuming the entire risk. That said, I hope you this script useful. Have fun!
Last modified 2019-03-31
© 2009-2019 Alexander Hajnal