If you pass the -v flag to nik2img it will output all sorts of info about 
bounding boxes in the native projection of the map and layers and in EPSG:4326 
or Long/Lat (which of course will be redundant if your map or layers are 
already in Long/Lat).

Anyway, that can help get a grasp on relative bounds of things.

There are two problems I see in your script below. One is that your long/lat 
bbox is not right. The other is that you are telling Mapnik that the data is in 
Mercator, which it is not. .osm data is natively in long/lat.

Basically, you can set the map.srs to whatever you want the map to be displayed 
in, but you *must* match the layer.srs to the correct projection for the source 
data.

Here is a script that should work like nik2img:

import mapnik

m = mapnik.Map(500,500)
mapnik.load_map(m,"test.xml")

merc = 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 +nadgri...@null +no_defs +over")
lon_lat_bbox = 
mapnik.Envelope(-1.5749997,50.7998221333,-1.2170842,51.0384324667)
merc_bbox = merc.forward(lon_lat_bbox)

m.srs = merc.params()
m.zoom_to_box(merc_bbox)                                                        
                                                                                
                               
mapnik.render_to_file(m,"my.png")

You might ask - How did I get the full bounds of the .osm file used in 
'test.xml'? Like this:

$ python
>>> from mapnik import Osm
>>> Osm(file='test2.osm').envelope()
Box2d(-1.5749997,50.8159089,-1.2170842,51.0223457)

Hope that helps,


Dane

On Sep 18, 2010, at 11:56 AM, Matrix Bai wrote:

> Hello everyone:
> 
> I'm newbie with mapnik, when I use the demo easymapnik example I confronted 
> some problems, most of time I get a blank map. I know it's the projection 
> problem and tried many ways others used, and the result is negative. So I 
> made a simple python file to render map and the result is the same, a blank 
> map.
> 
> My python file.
> 
> #!/usr/bin/python
> 
> import mapnik
> 
> mapnikfile = "test.xml"
> 
> proj = "+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 +nadgri...@null +no_defs +over"
> 
> m = mapnik.Map(500,500)
> 
> ll=(-1.45,50.9,51,1.35)
> 
> mapnik.load_map(m,mapnikfile)
> 
> m.srs = proj
> 
> prj = mapnik.Projection(proj)
> 
> bbox = prj.forward(mapnik.Envelope(ll[0],ll[1],ll[2],ll[3]))
> print bbox
> #m.zoom_all()       #when I use zoom_all() instead of zoom_to_box(bbox), I 
> got the right map
> m.zoom_to_box(bbox)                                                           
>                                                                               
>                               
> 
> print m.envelope()
> 
> m.layers[0].srs=proj # I set the layer's srs and don't know how to convert 
> the envelope to merc form
> print "map layers"
> print m.layers[0].srs
> print m.layers[0].envelope()
> mapnik.render_to_file(m,"my.png")
> 
> 
> ~                                 
> I used the test.xml and test2.osm in the 
> http://trac.mapnik.org/browser/trunk/plugins/input/osm?rev=919
> 
> After check some properties , the layer's srs is "+proj=latlong +datum=WGS84" 
> and the map's srs is "+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 +nadgri...@null +no_defs +over".It seems like 
> the reason why I just got blank map. 
> 
> I thought I should let the layer's coordinate as map's.  So I try to set the 
> layer's srs to the same as map's, but I don't find how to convert layer's 
> envelope to the merc form.
> 
> Can anyone tell me how to convert the layer's envelope or point my mistake?
> 
> Thank you!
> 
> 
> With nik2img.py, the result is good.
> 
> -- 
> Matrix Bai
> http://matrix.3p-blog.com
> 
> _______________________________________________
> Mapnik-users mailing list
> [email protected]
> https://lists.berlios.de/mailman/listinfo/mapnik-users

_______________________________________________
Mapnik-users mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/mapnik-users

Reply via email to