Talk:Mapnik/Rendering OSM XML data directly

From OpenStreetMap Wiki
Jump to: navigation, search

Thanks Tux008 for writing this tutorial! I spent days figuring out how to create a working PostgreSQL server, which I don't need at all - I just wanted to create Mapnik style sheets. With your approach it worked in 10 minutes. --Willem1 14:05, 19 January 2011 (UTC)

This guide is outdated as of 2016-06-03

According to people at the mapnik irc channel, this guide is outdated: mapnik no longer supports using osm data in this way. It might be useful if there were some sort of box on the actual page warning of this fact, or if the page was upadted or scrapped altogehter. I'd update it myself, but don't know how to do these things yet. The article at https://switch2osm.org/serving-tiles/manually-building-a-tile-server-14-04/ is a better starting point if you want to manually render a map. JokuNimi (talk) 13:04, 3 June 2016 (UTC)

No Plugin Found

When I run the command 'load_map(m, mapfile)' I get the following error

"RuntimeError: Cound not create datasource. No plugin found for type 'osm' (encountered during parsing of layer 'highways')"

On other forums I have seem people have gotten around the problem by reinstalling mapnik, but is it likely that this is my problem if I have previously been able to produce maps without any errors? Is it possible it is not a mapnik issue but something else on my end?

Thanks

The example does not work on FreeBSD-8.2 :(

Hello, everybody!


I tried to make this example on FreeBSD.


-#python2.6

- Python 2.6.6 (r266:84292, Apr 18 2011, 19:55:43)

- [GCC 4.2.1 20070719 [FreeBSD]] on freebsd8

- Type "help", "copyright", "credits" or "license" for more information.

- >>> from mapnik import *

- >>> mapfile = 'mapnik_style.xml'

- >>> map_output = 'mymap.png'

- >>> m = Map(4*1024,4*1024)

- >>> load_map(m, mapfile)

- Traceback (most recent call last):

- File "<stdin>", line 1, in <module>

- RuntimeError: XML document not well formed:

- StartTag: invalid element name (encountered in file 'mapnik_style.xml' at line 20)

- >>> bbox=(Envelope( 10.0,47.5,11.1,48.1 ))

- >>> m.zoom_to_box(bbox)

- >>> print "Scale = " , m.scale()

- Scale = 0.0002685546875

- >>> render_to_file(m, map_output)

- >>>

-#


Check of a file mapnik_style.xml gives it:


-#xmllint --valid --noout /var/mapnik/my/mapnik_style.xml

-/var/mapnik/my/mapnik_style.xml:3: validity error : Validation failed: no DTD found !

-s=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs +over"


-/var/mapnik/my/mapnik_style.xml:11: parser error : StartTag: invalid element name

-<Filter>[highway] <> </Filter>

-/var/mapnik/my/mapnik_style.xml:20: parser error : StartTag: invalid element name

-<Filter>[highway] <> </Filter>

-#

Sorry for my edition of this page. Thank you.

Do you copy the code for mapnik_style.xml from source of wiki page? --Ergo 16:55, 27 June 2011 (BST)
I receive this log, when I use the text of wiki-page.
At use of a source of wiki page (how there is written), I have it:
-# python2.6
-Python 2.6.6 (r266:84292, Apr 18 2011, 19:55:43)
-[GCC 4.2.1 20070719 [FreeBSD]] on freebsd8
-Type "help", "copyright", "credits" or "license" for more information.
->>> from mapnik import *
->>> mapfile = 'mapnik_style.xml'
->>> map_output = 'mymap.png'
->>> m = Map(4*1024,4*1024)
->>> load_map(m, mapfile)
-Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
-RuntimeError: XML document not well formed:
-Start tag expected, '<' not found (encountered in file 'mapnik_style.xml' at line 2)
->>> bbox=(Envelope( 10.0,47.5,11.1,48.1 ))
->>> m.zoom_to_box(bbox)
->>> print "Scale = " , m.scale()
-Scale = 0.0002685546875
->>> render_to_file(m, map_output)
->>>
-#
Thank you, Sergey
Now try to join 2 and 3 lines in one:
<Map bgcolor="#f2efe9" 
 srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs +over">
to
<Map bgcolor="#f2efe9" srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs +over">

--Ergo 18:29, 27 June 2011 (BST)

Thank for your help.
Now, the file "mapnik_style.xml" looks so:
<?xml version="1.0" encoding="utf-8"?>

<Map bgcolor="#f2efe9" srs="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs +over">

<FontSet name="book-fonts">
    <Font face_name="DejaVu Sans Book" />
</FontSet>

<Style name="highways">
    <Rule>
        <Filter>[highway] <> ''</Filter>
        <LineSymbolizer>
            <CssParameter name="stroke">#808080</CssParameter>
            <CssParameter name="stroke-width">2</CssParameter>
            <CssParameter name="stroke-linejoin">round</CssParameter>
            <CssParameter name="stroke-linecap">round</CssParameter>
        </LineSymbolizer>
    </Rule>
    <Rule>
        <Filter>[highway] <> ''</Filter>
        <TextSymbolizer name="name" fontset_name="book-fonts" size="9" fill="#000" halo_radius="1" placement="line" />
    </Rule>
</Style>

<Layer name="highways" status="on" srs="+proj=latlong +datum=WGS84">
    <StyleName>highways</StyleName>
    <Datasource>
        <Parameter name="type">osm</Parameter>
        <Parameter name="file">/var/mapnik/my/schwaben.osm</Parameter>
    </Datasource>
</Layer>

</Map>
but mistakes remain
$ ./render.py
Traceback (most recent call last):
  File "./render.py", line 9, in <module>
    load_map(m, mapfile)
RuntimeError: XML document not well formed:
StartTag: invalid element name (encountered in file 'mapnik_style.xml' at line 20)
$
Thank you, Sergey
This code from source? Mistakes are remain whith "<>" in code. You should copy code from source of page and join 2 and 3 lines in one...
I strongly apologise, but I do not understand.
I should copy a piece of a code from schwaben.osm? What it is necessary to write there? Can write an example?
And what for it is necessary to download ~500Мb the data osm.
Why for this example it was impossible to allocate not the big piece of a map in JOSM and to fulfil it?
Thank you, Sergey