From ce0661b0e8b793291de5f882dcafbb06a738e33e Mon Sep 17 00:00:00 2001 From: springmeyer Date: Mon, 9 Jan 2012 09:56:36 -0800 Subject: [PATCH] Updated Tutorial 2 -- 'Hello world' using an XML stylesheet (markdown) --- GettingStartedInXML.md | 181 +++-------------------------------------- 1 file changed, 11 insertions(+), 170 deletions(-) diff --git a/GettingStartedInXML.md b/GettingStartedInXML.md index 3e64cc5..58856e8 100644 --- a/GettingStartedInXML.md +++ b/GettingStartedInXML.md @@ -8,11 +8,7 @@ Make sure you have mapnik (and the python bindings) installed and you've success * 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 are covered in this tutorial: - -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 is showcased that uses a world borders dataset with population attributes to create a chloropleth map (aka thematic) by population size. +This tutorial covers using an XML stylesheet to rendering output that exactly matches the map output from the pure python example in [Getting Started Python Tutorial](GettingStartedInPython). ## Step 1 @@ -32,14 +28,19 @@ mapnik.render_to_file(m, image) print "rendered image to '%s'" % image ``` -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` +Now, we need some data to render, let's use a shapefile of world border polygons from http://naturalearthdata.com. Download the data from this wiki's local cache [here](data/110m-admin-0-countries.zip) 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 in the same directory as the `world_map.py`. Once unzipped, you should see four files like: + + ne_110m_admin_0_countries.shp + ne_110m_admin_0_countries.shx + ne_110m_admin_0_countries.dbf + ne_110m_admin_0_countries.prj 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. +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`, also in the same directory as `world_map.py` script. ```xml @@ -68,167 +69,7 @@ Now run the python script: * It should output a png graphic in the same folder that matches the Getting Started Tutorial. ----- +Hint: if you would like to run the script without first typing `python` you can do: -## Step 2 - -### World Population XML - -Attached below and included as code samples, here is a sample python script that accesses a _'population.xml_ map configuration. - -Note: you will need to download the [modified world borders shapefile](http://trac.mapnik.org/attachment/wiki/XMLGettingStarted/world_borders.zip). - - * Note: this file is originally from [Thematic Mapping Blog](http://thematicmapping.org/downloads/world_borders.php). The version attached here is the simpler shapefile provided there with some modification made to avoid problems that occur when displaying the map in projections such as 900913/3785 (this tutorial does not use this projection so you can use the original shapefiles as well). See [ticket 308](https://github.com/mapnik/mapnik/issues/308) for details. - -This script should result in a graphic like this: - -[[/images/world_population_minimized.png]] - -```python - #!/usr/bin/env python - - import mapnik - mapfile = "population.xml" - m = mapnik.Map(1400, 600) - mapnik.load_map(m, mapfile) - bbox = mapnik.Envelope(mapnik.Coord(-180.0, -75.0), mapnik.Coord(180.0, 90.0)) - m.zoom_to_box(bbox) - mapnik.render_to_file(m, 'world_population.png', 'png') -``` - -And here is the xml file: - -```xml - - - - - - - - - - - - - population - countries_label - - shape - - - /PATH/TO/THE/TM_WORLD_BORDERS_SIMPL-0.3 - - - - -``` \ No newline at end of file + chmod +x world_map.py # to make it executable + ./world_map.py