Hi Simon,

On Sep 15, 2010, at 2:44 AM, simon blackmore wrote:

> Hi everyone,
> 
> Please excuse such a rudimentary question here but I am struggling with a 
> simple scaling issue.
> 

Not rudimentary at all, in fact a bit tricky really :)

> I am using the following code. Its all good I render a beautiful map. But I 
> am not sure what I am doing
> with the scale.

So, the context here is that tweaking the image dimensions and the bbox 
separately(manually) is likely to lead to different aspect ratios between the 
two.

Mapnik internally fixes the aspect ratio before rendering, and by default does 
this by growing the bbox to match the image dimensions.

This is an undocumented feature so you'd only know this by peeking in the C+ 
code:

http://trac.mapnik.org/browser/trunk/src/map.cpp#L68

> 
> Say I set imgx at 4000 how do I know exactly what imgy should be.
> 

Well, per the above, you can set the width (x) and height (y) to what ever you 
want and the bbox will be adjusted in turn.

> for example If imgy =  20000 the map into a really stretched along the y 
> axis. But I want to just render
> my chosen selection accurately.

Right, but what exactly do you mean by selection? My guess is you mean the 
exact area of your data, and if that is right then my suggestion is below.

> 
> Any basic help or links would be really appreciated.
> 

I'm guessing what you might want is to provide an exact bbox (fetched from some 
other program) and then have mapnik figure out the proper aspect ratio of w/h 
(so you can provide either and they will be adjusted without messing with your 
bbox).

To do this we need to instruct Mapnik to adjust the output image dimensions 
instead of the bbox, and you can do this by setting the 'aspect_fix_mode' to 
GROW_CANVAS.

In your python script add a line like:

m.aspect_fix_mode = mapnik.aspect_fix_mode.GROW_CANVAS

Also, for you or anyone interested in fiddling with these parameters I recently 
added them as a switch to nik2img (in trunk):

http://code.google.com/p/mapnik-utils/source/detail?r=1042# 

Dane


> Many thanks
> 
> Simon
> 
> 
> 
> #!/usr/bin/python
> 
> import mapnik
> import sys, os
> import cairo
> 
> if __name__ == "__main__":
>    try:
>        mapfile = os.environ['MAPNIK_MAP_FILE']
>    except KeyError:
>        mapfile = "osm.xml"
>        map_output = 'manchester4000exp.svg'
>    #---------------------------------------------------
>    #  Change this to the bounding box you want
> 
>    ll = (-2.25575, 53.4859, -2.22755, 53.46748)
>    #---------------------------------------------------
> 
>    imgx = 4000
>    imgy = 6135
> 
> 
>    m = mapnik.Map(imgx,imgy)
>    mapnik.load_map(m,mapfile)
>    prj = 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")
>    c0 = prj.forward(mapnik.Coord(ll[0],ll[1]))
>    c1 = prj.forward(mapnik.Coord(ll[2],ll[3]))
>    bbox = mapnik.Envelope(c0.x,c0.y,c1.x,c1.y)
>    m.zoom_to_box(bbox)
> 
> file = open(map_output, 'wb')
> surface = cairo.SVGSurface(file.name, imgx, imgy)
> mapnik.render(m, surface)
> surface.finish()
> 
> _______________________________________________
> 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