Skip to main content

Mapping New Zealand: Dealing with the antimeridian in TileMill

I want to play with my new seafloor map in TileMill, which is a great map design studio. It’s built on top of Mapnik, but instead of XML you can style your maps with CartoCSS, which is much more user friendly. The biggest limitation of TileMill is that it only supports the Web Mercator projection (even though the underlying rendering engine, Mapnik, handles multiple map projections very well). Hopefully, TileMill will add support for other map projections and custom tiling schemes in the future.

Web Mercator is clearly not the ideal map projection to use for countries far north, like Norway (use UTM 33N), or countries not so far south, like New Zealand (use NZTM2000). Another problem with Web Mercator, and other projections centered at the prime meridian, is that you often get troubles crossing the antimeridian on the opposite side. This is unfortunate for New Zealand, where the animeridian is just east of the North Island, leaving the Chatham Islands on the other side. When I tried to reproject my seafloor map into Web Mercator, I got a dataset that made a roundtrip around the Earth. This blog post tells you how to avoid this trip by dividing the source dataset into two parts.

Gisborne, in northeastern New Zealand, proudly claims to be the first city in the world to greet the sun each day.

You’ll see that this seafloor map is different from the one I created earlier, as I’ve masked out the islands with a white color. I did this with Mapnik XML using this LINZ dataset. I want to add land data as separate layers in TileMill.

The seafloor map of New Zealand is 12,000 x 15,200 pixels and it crosses the antimeridian (180° longitude). This is not a problem with the original map projection, as it’s centered at 100° east longitude, and not the prime meridian (0° longitude). What happens if we reproject the dataset into Web Mercator

gdalwarp -s_srs "+proj=merc +lon_0=100 +lat_ts=-41 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs" -t_srs EPSG:3785 -co compress=lzw -r bilinear nz-seafloor.tif nz-seafloor-webmerc.tif

(To use Mercator 41 with gdalwarp you need to specify the full Proj4-definition.)

The result is a very wide image spanning  the globe (and I’m not able to get the same resolution as the original image):


Instead of this wide image, I decided to split the image in two at the antimeridian with gdal_translate:

gdal_translate -srcwin 0 0 7723 15200 -co compress=lzw nz-seafloor.tif nz-seafloor-1.tif

gdal_translate -srcwin 7724 0 4276 15200 -co compress=lzw nz-seafloor.tif nz-seafloor-2.tif


This will create two new map images, one on each side of the antimeridian. There is one column of pixels, which was unfortunate enough to cross the antimerdian, that is now missing.

Next, I’m reprojecting both images into Web Mercator using gdalwarp:

gdalwarp -s_srs "+proj=merc +lon_0=100 +lat_ts=-41 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs" -t_srs EPSG:3785 -co compress=lzw -r bilinear nz-seafloor-1.tif nz-seafloor-1-webmerc.tif

gdalwarp -s_srs "+proj=merc +lon_0=100 +lat_ts=-41 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs" -t_srs EPSG:3785 -co compress=lzw -r bilinear nz-seafloor-2.tif nz-seafloor-2-webmerc.tif

Because of the missing pixel, the images don’t overlap entirely at the antimeridian. I’m therefore stretching the images a tiny bit (which is not recognizable at this scale) to make it seamless:

gdal_translate -a_ullr 17482842.051 -7842209.647 20037508.34 -2796127.081 -co compress=lzw nz-seafloor-1-webmerc.tif nz-seafloor-1-webmerc-fix.tif

gdal_translate -a_ullr -20037508.34 -7842313.166 -18622711.547 -2796127.081 -co compress=lzw nz-seafloor-2-webmerc.tif nz-seafloor-2-webmerc-fix.tif

We now have to map images that we can load into TileMill, which will stitch them together again.



Comments

Popular posts from this blog

Creating a WebGL Earth with three.js

This blog post will show you how to create a WebGL Earth with three.js , a great JavaScript library which helps you to go 3D in the browser. I was surprised how easy it seemed when reading a blog post  by Jerome Etienne . So I decided to give it a try using earth textures  from one of my favourite cartographers, Tom Patterson . WebGL is a JavaScript API for rendering interactive 3D graphics in modern web browsers without the use of plug-ins. Three.js is built on top of WebGL, and allows you to create complex 3D scenes with a few lines of JavaScript. If your browser supports WebGL you should see a rotating Earth below: [ Fullscreen ] To be able to display something with three.js, you need three things: a scene, a camera and a renderer. var width  = window.innerWidth,     height = window.innerHeight; var scene = new THREE.Scene(); var camera = new THREE.PerspectiveCamera(45, width / height, 0.01, 1000); camera.position.z = 1.5; var rende...

Thematic Mapping Engine

It's time to introduce the Thematic Mapping Engine (TME). In my previous blog posts, I've shown various techniques of how geobrowsers can be used for thematic mapping. The goal has been to explore the possibilites and to make these techniques available to a wider audience. The Tematic Mapping Engine provides an easy-to-use web interface where you can create visually appealing maps on-the-fly. So far only prism maps are supported, but other thematic mapping techniques will be added in the upcoming weeks. The engine returns a KMZ file that you can open in Google Earth or download to your computer. My primary data source is UNdata . The above visualisation is generated by TME ( download KMZ ) and shows child mortaility in the world ( UNdata ). The Thematic Mapping Engine is also an example of what you can achieve with open source tools and datasets in the public domain: A world border dataset is loaded into a MySQL database . The same database contains tables with statistics ...

Creating 3D terrains with Cesium

Previously, I’ve used three.js to create 3D terrain maps in the browser ( 1 , 2 , 3 , 4 , 5 , 6 ). It worked great for smaller areas, but three.js doesn’t have built-in support for tiling and advanced LOD algorithms needed to render large terrains. So I decided to take Cesium for a spin. Cesium is a JavaScript library for creating 3D globes and 2D maps in the browser without a plugin. Like three.js, it uses WebGL for hardware-accelerated graphics. Cesium allows you to add your own terrain data, and this blog post will show you how. Impressed by the terrain rendering in @CesiumJS - with a 10m elevation model for Norway! Farewell Google Earth. pic.twitter.com/RQKvfu2hBb — Bjørn Sandvik (@thematicmapping) October 4, 2014 Compared to  the dying Google Earth plugin , it's quite complicated to get started with Cesium. The source code is well documented and the live coding Sandcastle is great, but there is a lack of tutorials  and my development slows down when ...