MapTiler to create online maps

For a project a few years ago we created a vegetation map for central and southwest Kenya (see here for more information). The map together with documentation was initially made available on CD-ROM. I also created an online map. Apart from the version mentioned in this post, I also created a version with MapTiler.

MapTiler requires a georeferences image file as input. To export the vegetation map from my GRASS GIS database to a georeferenced image, I used the r.out.tiff function.

r.out.tiff -t input=veg_ethiopia_pnv@vegetation output=vegethiopia.tif

The resulting file can be used in MapTiler to create map mashups for Google Earth, Google Maps or OpenLayer. MapTiler offers a wizard like interface which leads you step by step through the process.

I am encountering only one problem. For the map to blend well with the background maps the NODATA pixels should be transparent. There is an option in MapTiler to set a transparency for a color (NODATA), but for some reason this doesn’t work for me. UPDATE: This now works for me, so the steps below should not be needed. See this post.

As an alternative I am using ImageMagick to convert the image to png and make the pixels containing NODATA transparent. I am doing this after the PNG tiles have been created at the same time I am optimizing the map tile images to speed up the download and save space on the server.

As described in this blog the PNGNQ tool is excellent for post-processing of PNG tiles generated from MapTiler/GDAL2Tiles. You probably want to automate this because depending on the zoom level selected in MapTiles, there are potentially thousands of png files.

I wrote a small script in R to convert the background color to transparent and to process all PNG tiles generated by MapTiler using the PNGNQ utility. Of course you can use your own favorite scripting or programming language to do the same.

# Get list of tile file names
tfwp <- list.files(path = "/home/paulo/vegethiopia", pattern = "png", all.files = FALSE, full.names = TRUE, recursive = TRUE)
lt <- length(tfwp)

# Loop to set transparency and optimize the png images
tfb <- strsplit(tfwp,split=".", fixed=TRUE)
for(i in 1:lt){
fn <- paste(tfb[[i]][1], "-nq8.png", sep="")

# convert background color to transparent
system(paste("convert -transparent white ",tfwp[i], " ", tfwp[i], sep=""))

# Optimize png images
system(paste("pngnq -n 256 ",tfwp[i], sep=""))
file.rename(fn, tfwp[i])

The Potential Natural Vegetation map for Central and Southwest Kenya is an example of mash-up map created with MapTiler, with some adaptations of the page layout and the addition of a legend. See also the Potential natural vegetation map for eastern Africa for an example of a Google Earth layer created with MapTiler.


2 thoughts on “MapTiler to create online maps

  1. Pingback: Atlas of potential vegetation of Ethiopia « Ecostudies

  2. Pingback: MapTiler to create online maps II « Ecostudies

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s