Reputation: 11
I installed mapnik using command line
sudo apt-get install -y python-software-properties
echo 'yes' | sudo add-apt-repository ppa:mapnik/v2.1.0
sudo apt-get update
# install core mapnik
sudo apt-get install -y libmapnik mapnik-utils python-mapnik
# install the python binding
sudo apt-get install -y python-mapnik
# confirm mapnik-config returns 2.1.0
mapnik-config -v
When i run python code doing import mapnik
it worked fine. When i tried to generate a image using shape file it output the result. But when i tried the same using osm file and used the style sheet osm.xml given in this link http://wiki.openstreetmap.org/wiki/Mapnik_Example it then gives me error
Traceback (most recent call last):
File "render.py", line 6, in <module>
mapnik.load_map(m, stylesheet)
RuntimeError: Failed to parse expression: "NAME" in style 'CountryLabels' in TextSymbolizer at line 33 of 'mapnik_style2.xml'
Here i am using TextSymbolizer to display the country name.
Am i doing something wrong here. Any help will be grateful. Thanks in Advance.
Upvotes: 0
Views: 1412
Reputation: 61
The example that you refer to is not up to date.
It was used for mapnik 0.7
(NOTE: The code used in this example is not current and was used for mapnik 0.7. Attempts to reproduce this image using mapnik 2.0+ using the following workflow will not work.]
The version 2.1 got a lot of change even for the style fomat. The parsing error about "NAME" of the xml style file comes from this. Starting with Mapnik 2.0 the new syntax for TextSymbolizer is used:
<TextSymbolizer name="[label]" />
becomes
<TextSymbolizer>[label]</TextSymbolizer>
This change was made to be forward compatible with changes to text formatting being introduced in later versions.
And your xml style file is probably even older (This is in the page that you indiquate):
<TextSymbolizer name="name" face_name="DejaVu Sans Bold" size="10" fill="#734a08" dy="18" halo_radius="1" wrap_width="0"/>
Attention: The attribute 'name' of node TextSymbolizer has NO square brackets. So if you want to change your XML style file, you need to add [] to name -> name="[name]". If you need more information about the TextSymbolizer, you can reference to: https://github.com/mapnik/mapnik/wiki/TextSymbolizer
If you need another example style file to test, perhaps this osm.xml could help: https://trac.openstreetmap.org/browser/subversion/applications/rendering/mapnik/osm.xml?order=name
Upvotes: 3