Hi everyone!
I convert .osm - data into pgsql-database.
When I try to render images from these databases/tables.
I use Python version 2.7.2 with Mapnik-2.0.1rc0.
My .py:
#!/usr/bin/python
import mapnik
from mapnik import Layer, PostGIS
from datetime import datetime, timedelta
import sys, os
def render_image(start_time,end_time):
ll = (30.708,-27.414,32.179,-25.652)
prj = mapnik.Projection("+proj=latlong +datum=WGS84")
c0 = prj.forward(mapnik.Coord(ll[0],ll[1]))
c1 = prj.forward(mapnik.Coord(ll[2],ll[3]))
z = 3
imgx = 336 * z
imgy = 450 * z
m = mapnik.Map(imgx,imgy)
#mapnik.load_map(m,"some_kind_of_stylesheet.xml")
db_params = dict(
dbname = 'gis',
user = 'Hein',
password = '1234',
host = 'localhost',
port = 5432,
estimate_extent = False,
extent = "3390650.221286806, -3163145.87245787, 3609898.596229789, -2956043.104540316"
)
lyr = Layer('points',"+init=epsg:900913")
###db_params['table'] = '(planet_osm_line,planet_osm_point,planet_osm_polygon,planet_osm_roads)'
db_params['table'] = 'planet_osm_point'
lyr.datasource = PostGIS(**db_params)
lyr.styles.append('points')
m.layers.append(lyr)
if hasattr(mapnik,'mapnik_version') and mapnik.mapnik_version() >= 800:
bbox = mapnik.Box2d(c0.x,c0.y,c1.x,c1.y)
else:
bbox = mapnik.Envelope(c0.x,c0.y,c1.x,c1.y)
m.zoom_to_box(bbox)
im = mapnik.Image(imgx,imgy)
mapnik.render(m, im)
view = im.view(0,0,imgx,imgy) # x,y,width,height
view.save("map.png",'png')
if __name__ == "__main__":
cur_time = datetime(2010,8,10,0,0,0)
end_time = datetime(2010,12,6,23,59,59)
delta = timedelta(minutes=+30)
while cur_time < end_time:
render_image(cur_time.isoformat(), (cur_time+delta).isoformat())
cur_time = cur_time + delta
I got this file from example-code and modified it.
But there are some lines, where I don't know, what they mean and if they are useful.
What kind of XML-stylesheet must I use? Where can I get sample XML-code, that I can use?
I would be very happy if anyone could help me.
Thank you!
Greets,
Matze