[OSM-dev] Specifying area and zoom in Mapnik

Keith Sharp kms at passback.co.uk
Fri Mar 23 16:53:14 GMT 2007


Hello,

Thanks Artem, that's it working!

Keith.

On Fri, 2007-03-23 at 16:13 +0000, Artem Pavlenko wrote:
> 
> On 23 Mar 2007, at 15:52, Keith Sharp wrote:
> 
> > Hello,
> > 
> > 
> > I've got Mapnik installed and rendering data from my PostGIS install
> > of
> > the weekly planet.osm if I use the generate_tiles.py script from
> > svn.  I
> > can modify the area and zoom level I want and it all works.
> > 
> > 
> 
> > 
> > What I would like to do now is create a script where I can specify
> > an
> > image size, and the area I want to render.  I am having difficulty
> > working out how to do this.  I got as far as:
> > 
> > 
> > 
> > 
> > #!/usr/bin/python
> > 
> > 
> > from mapnik import *
> > 
> > 
> > mapfile = "/home/kms/src/osm/mapnik/osm/osm.xml"
> > m = Map(800, 800, "+proj=latlong +ellps=WGS84")
> > load_map(m, mapfile)
> Here srs gets  overwritten with one form mapfile. I suspect you have
> mercator in osm.xml
> 
> > bbox = Envelope(Coord(-50.0, -50.0), Coord(50.0, 50.0))
> 
> 
> Given the above is true you need to specify coordinates in Mercator
> projection
> 
> 
> p = Projection("+proj=merc +datum=WGS84")
> c0 = p.forward(Coord(-50,-50))
> c1 = p.forward(Coord(50,50))
> bbox = Envelope(c0,c1)
> 
> 
> HTH
> 
> 
> Cheers,
> Artem
> 
> 
> 
> 
> 
> > m.zoom_to_box(bbox)
> > render_to_file(m, 'map.png', 'png')
> > 
> > 
> 
> 
> 
> > 
> > 
> > 
> > But this doesn't do what I expect.  My main question is how do I
> > specify
> > the bbox as a pair of WGS84 kat/lon coordinates?
> > 
> > 
> > For example I'd like to render the entire UK as:
> > 
> > 
> > -8.920, 48.900 to 2.250, 61.300
> > 
> > 
> > or the area around Glasgow West:
> > 
> > 
> > -4.350, 55.860 to -4.290, 55.900
> > 
> > 
> > Any help would be appreciated!
> > 
> > 
> > Keith.
> > 
> > 
> > PS. Regarding getting the tile rendering stuff up and running - I
> > plan
> > on tidying my notes up and putting them on the Wiki.
> > 
> > 
> > 
> > 
> > _______________________________________________
> > dev mailing list
> > dev at openstreetmap.org
> > http://lists.openstreetmap.org/cgi-bin/mailman/listinfo/dev
> > 
> > 
> 
> Artem Pavlenko
> http://mapnik.org
> 
> 
> 
> 
> 





More information about the dev mailing list