From 0614951efbfa9fe80179c63c4546e660f85d45bd Mon Sep 17 00:00:00 2001 From: springmeyer Date: Mon, 9 Jan 2012 09:48:35 -0800 Subject: [PATCH] fixup styles and data step --- GettingStartedInXML.md | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/GettingStartedInXML.md b/GettingStartedInXML.md index 58b8b09..3e64cc5 100644 --- a/GettingStartedInXML.md +++ b/GettingStartedInXML.md @@ -1,25 +1,24 @@ -# Tutorial 2 -- 'Hello,world!' using an XML stylesheet +# Tutorial 2 -- 'Hello world' using an XML stylesheet ## Overview -Make sure you have mapnik installed and you've successfully run through [Getting Started Python Tutorial](GettingStartedInPython). +Make sure you have mapnik (and the python bindings) installed and you've successfully run through [Getting Started Python Tutorial](GettingStartedInPython). * This page will guide you through using the Mapnik python bindings along with a separate XML file for your map styles. - * This is a useful approach to manage your map styles/rules separately from your python code, and can be advantageous for very complex formatting. + * This tutorial expects that you are running Mapnik 2.x or greater. The command `mapnik-config -v` will show you which version you are running. -Two examples will be shown: +Two examples are covered in this tutorial: -1) An XML stylesheet that exactly matches the map output from the pure python example in [Getting Started Python Tutorial](GettingStartedInPython). +1) An XML stylesheet is rendering that exactly matches the map output from the pure python example in [Getting Started Python Tutorial](GettingStartedInPython). -2) An XML stylesheet that uses a world borders dataset with population attributes to create a chloropleth map (aka thematic) by population size. +2) An XML stylesheet is showcased that uses a world borders dataset with population attributes to create a chloropleth map (aka thematic) by population size. ## Step 1 ### Hello World XML -First you will need a python script that sets the basic map parameters and points to the XML stylesheet - +First you will need a python script that sets the basic map parameters and points to the XML stylesheet. Copy the code below and save to a file called `world_map.py`. ```python #!/usr/bin/env python @@ -30,24 +29,25 @@ m = mapnik.Map(600, 300) mapnik.load_map(m, stylesheet) m.zoom_all() mapnik.render_to_file(m, image) +print "rendered image to '%s'" % image ``` - * Copy the above code and save to a file called `world_map.py` +Now, we need some data to render, let's use a shapefile of world border polygons from http://www.naturalearthdata.com. You can download the data from this wiki's local copy [here](data/) or directly from the [Natural Earth Data site](http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/cultural/110m-admin-0-countries.zip). Unzip the archive and it should produce four files like `ne_110m_admin_0_countries.shp, ne_110m_admin_0_countries.shx, ne_110m_admin_0_countries.dbf, and ne_110m_admin_0_countries.prj` -Next you will need to create the `world_style.xml` file referenced in the `world_map.py` script. +To download and unzip on the command line with the do: + + wget https://github.com/mapnik/mapnik/wiki/data/110m-admin-0-countries.zip + unzip 110m-admin-0-countries.zip # creates ne_110m_admin_0_countries.shp + +Next, create the `world_style.xml` file referenced in the `world_map.py` script. Copy this XML and save to a file called `world_style.xml` in the same directory as `world_map.py` script. ```xml - + @@ -55,16 +55,14 @@ Next you will need to create the `world_style.xml` file referenced in the `world My Style shape - world_borders.shp + ne_110m_admin_0_countries.shp ``` - * Copy this XML and save to a file called `world_style.xml` beside the `world_map.py` script. - -Now run that script: +Now run the python script: python world_map.py