Skip to main content

Posts

Showing posts from July, 2012

Creating contour lines with GDAL and Mapnik

Credits: Wikipedia So far we’ve used our Digital Elevation Model (DEM) to create hillshade  and color relief . Contours  is another common cartographic method used to show the shape of the terrain. If contour lines are placed close to each other, it means that the terrain is steep. Let’s add some contours for our terrain map of Jotunheimen. We can use a GDAL command, gdal_contour , to create vector contour lines from a DEM: gdal_contour -a height jotunheimen.tif jotunheimen_contour_25m.shp -i 25.0 The resulting shapefile has an attribute named “height” (-a) containing the elevation of each contour line. The contour interval, the difference in elevation between successive contour lines, is 25 meters (-i). Let's render the contour lines with Mapnik ( jotunheimen_contours.xml ): We can use Nik2Img to create an image from the Mapnik XML file: nik2img.py jotunheimen_contours.xml jotunheimen_contours.png -d 4096 4096 --projected-extent 460000 6810000 470000 ...

Using custom projections with TileCache, Mapnik and Leaflet

After five blog posts ( 1 , 2 , 3 , 4 , 5 ) we finally have a terrain map of Jotunheimen , a mountainous area in Norway with beautiful lakes and glaciers. It’s time to publish the map on the web. In this blog post I’ll show how you can use TileCache and Mapnik to render map tiles, and how to load these tiles into Leaflet using the UTM coordinate system . To make a slippy map - a zoomable and draggable map - we need to serve map tiles instead of the large map image we created in the last blog post . The original Digital Elevation Model (DEM) is 3134 x 3134 pixels, and with a bit of upscaling we can using this tiling scheme: Zoom Map size Tiles Resolution 0 256 x 256 px 1 x 1 = 1 234.375 1 512 x 512 px 2 x 2 = 4 117.1875 2 1024 x 1024 px 4 x 4 = 16 58.59375 3 2048 x 2048 px 8 x 8 = 64 29.296875 4 4096 x 4096 px 16 x 16 = 256 14.6484375 Each map tile is 256 x 256 pixels. We need one map tile to cover the first zoom level a...

Land cover mapping with Mapnik

In the previous blog post we created a terrain map of Jotunheimen using color relief, hill and slope shading. All data originates from a single Digital Elevation Model (DEM). I miss two important features that dominates this area - lakes and glaciers. Let’s map it! The Norwegian Mapping Authority has not yet released detailed land cover data in the public domain. Low resolution data can be found on this page (scale 1:1,500,000). Luckily, I found the Corine Land Cover dataset (scale 1:100,000) from the European Environment Agency (EEA). Reuse for commercial or non-commercial purposes is permitted free of charge, provided that EEA is acknowledged. I downloaded two shapefiles from this dataset, 335 - Glaciers and perpetual snow and 512 - Water bodies . The Corine dataset is covering the whole of europe and use a different projection ( EPSG:3035 ) than our map of Jotunheimen ( EPSG:32632 ). Mapnik is able to clip and reproject vector data on-the-fly, so we can simply add the shape...

Terrain mapping with Mapnik

In the previous posts we’ve created three different GeoTIFF images from a single Digital Elevation Model (DEM); hillshade, slopeshade and color relief. It’s time to combine the images into a single terrain map of Jotunheimen. Mapnik is a great open source toolkit for map rendering, and we’ll use the RasterSymbolizer to blend the GeoTIFFs. The styles and layers (images) can be defined in an XML file ( jotunheimen_terrain.xml ): The map projection ( UTM 32N )  is defined in the first line. Mapnik uses the PROJ.4 library, and you’ll find the srs code by clicking on the Proj4 link on spatialreference.org . Mapnik can’t alter the projection of raster images, so the images have to be in the desired projection before feeding them into Mapnik. Next, I’ve defined two styles for this map with the RasterSymbolizer . The hillshade is going to be blended with the color relief image, using the multiply blend mode . The color numbers for each pixel of the hillshade are multiplied...