XML file for openstreetmap and PostGIS datasource

798 views
Skip to first unread message

tm...@s.netic.de

unread,
Sep 16, 2013, 1:03:33 PM9/16/13
to map...@googlegroups.com
Hello,

i installed mapnik-v2.2.0 and also a PostGIS database.

I now search an XML file that lets me render maps in different zoom scales.
I once had this for mapnik-0.7, but no old files work any more.

Has anybody got an XML file that i can use in Python scripts for this purpose?

It is important that i can specify PostGIS as datasource.


Best regards
Torsten

Frederik Ramm

unread,
Sep 16, 2013, 1:43:56 PM9/16/13
to map...@googlegroups.com
Hi,

On 16.09.2013 19:03, tm...@s.netic.de wrote:
> I now search an XML file that lets me render maps in different zoom scales.
> I once had this for mapnik-0.7, but no old files work any more.

Have you tried either openstreetmap-carto or "osm bright"? Both are
standard styles that work with an osm2pgsql import.

Bye
Frederik

--
Frederik Ramm ## eMail fred...@remote.org ## N49�00'09" E008�23'33"

tm...@s.netic.de

unread,
Sep 18, 2013, 3:42:34 PM9/18/13
to map...@googlegroups.com
Hello Frederik,

thanks for your hints.  I looked at both, they need tilemill and the installation for Linux is supported for Ubuntu, but i run OpenSuSe 12.3.

I like the example gallery of tilemill, they look awesome and it seems very flexible.

But i tried to continue with the latest set of XML style available, which changed a lot since i last used it with mapnik-0.7.

I now have an "osm.xml" and a subdirectory "inc" with some more XML files.  I edited settings.xml.inc and datasource-settings.xml.inc and when now starting a small script:

import mapnik
image = 'world_style.png'
m = mapnik.Map(600, 300)
mapnik.load_map(m, 'osm.xml')
m.zoom_all()
mapnik.render_to_file(m, image)
print "rendered image to '%s'" % image

Then now i get:
inc/entities.xml.inc:10: parser warning : PEReference: %layers; not found
%layers;
        ^
Traceback (most recent call last):
  File "./wer.py", line 10, in <module>
    mapnik.load_map(m, 'osm.xml')
RuntimeError: XML document not well formed:
Entity 'datasource-settings' not defined at line 4066 of 'osm.xml'

I don't understand that as inc/entities.xml.inc looks fine to me:

<!ENTITY % settings SYSTEM "settings.xml.inc">
%settings;
<!ENTITY datasource-settings SYSTEM "datasource-settings.xml.inc">
<!ENTITY fontset-settings SYSTEM "fontset-settings.xml.inc">
<!ENTITY srs900913 "+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">
<!ENTITY srsmercator "+proj=merc +datum=WGS84 +over">
<!ENTITY srs4326 "+init=epsg:4326">
<!ENTITY % layers SYSTEM "layers.xml.inc">
%layers;
<!ENTITY maxscale_zoom0 "<MaxScaleDenominator>250000000000</MaxScaleDenominator>">
<!ENTITY maxscale_zoom1 "<MaxScaleDenominator>500000000</MaxScaleDenominator>">

%settings; is fine but %layers; gives an error.  I don't get what is wrong here.

Has anybody got a hint here?

Basically i look for a simple way to draw a map from PostGIS input data.


Best regards
Torsten


tm...@s.netic.de

unread,
Sep 18, 2013, 5:50:24 PM9/18/13
to map...@googlegroups.com
Hello,

hooray, i finally made it to render a map, what was missing was a call to generate_xml with some parameters to prepare the XML style files.  Then some few manual changes to connect to the DB and i get correct XML files & settings.

Now i can render a map using this example:


import mapnik
image = 'world_style.png'
#m = mapnik.Map(1200, 600, "+proj=latlong +datum=WGS84")
m = mapnik.Map(1200, 600, "+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")
extent = mapnik.Box2d(-180.0, -90.0, 180.0, 90.0)
#extent = mapnik.Envelope(10.0, 45.0, 11.0, 46.0)
mapnik.load_map(m, 'osm.xml')
#m.zoom_all()
#m.zoom_to_box(extent)
m.zoom_to_box(mapnik.Box2d(-8024477.28459,5445190.38849,-7381388.20071,5662941.44855))
print "scale", m.scale()

mapnik.render_to_file(m, image)
print "rendered image to '%s'" % image

But i wonder about the strange coordinates i need to use.  I'd rather like to use WGS84 coordinates and i wonder how to achieve this?


Best regards
Torsten

Artem Pavlenko

unread,
Sep 19, 2013, 4:07:00 AM9/19/13
to map...@googlegroups.com
You could try something like this :

wgs84 = mapnik.Projection("+proj=latlon +datum=WGS84")
mercator = mapnik.Projection("+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")

prj_transform = mapnik.ProjTransform(wgs84,mercator)

m.zoom_to_box(prj_transform.forward(mapnik.Box2d(10.0, 45.0, 11.0,
46.0))) # bounding box in geographic coord system

you might want to clamp latitude values to -85..85 range as mercator
doesn't work with -90/90

HTH
Artem
> --
> You received this message because you are subscribed to the Google Groups
> "mapnik" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mapnik+un...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Sven Geggus

unread,
Sep 19, 2013, 10:09:29 AM9/19/13
to map...@googlegroups.com
tm...@s.netic.de wrote:

> Now i can render a map using this example

Have a look at nik2img as a (better) alternative to generate_tiles

Sven

--
It's easier for our software to compete with Linux when there's piracy than
when there's not. (Bill Gates)

/me is giggls@ircnet, http://sven.gegg.us/ on the Web

tm...@s.netic.de

unread,
Sep 19, 2013, 3:22:04 PM9/19/13
to map...@googlegroups.com
Hello artemp,

Thanks for that code part.  It works great.  Also, it is a nice area of the map you chose.



Best regards
Torsten


On Monday, 16 September 2013 19:03:33 UTC+2, qtm...@googlemail.com wrote:
Reply all
Reply to author
Forward
0 new messages