...using the right from address...

On Fri, May 16, 2008 at 10:06 PM, Frederik Ramm <[EMAIL PROTECTED]> wrote:
> Hi,
>
>    I have a simple question concerning reprojection. It's probably just
> some stupid thing I'm doing wrong but I cannot find it.
>
> I have my PostGIS database initialized with lat/lon data (through
> osm2pgsl with the -l option). All the layers in the map file have
> srs="+init=epsg:4326" set, and the enclosing <Map> object as well.
>
> When I create images in EPSG:4326, everything works fine as expected;
> the following python script...
>
>     mapfile = "osm.xml"
>     map_uri = "karlsruhe.png"
>     ll = (8.32, 48.95, 8.48, 49.07)
>     imgx = 400
>     imgy = 300
>
>     m = Map(imgx,imgy)
>     load_map(m,mapfile)
>     prj = Projection("+init=epsg:4326")
>     c0 = prj.forward(Coord(ll[0],ll[1]))
>     c1 = prj.forward(Coord(ll[2],ll[3]))
>     bbox = Envelope(c0.x,c0.y,c1.x,c1.y)
>     m.zoom_to_box(bbox)
>     im = Image(imgx,imgy)
>     render(m, im)
>     view = im.view(0,0,imgx,imgy) # x,y,width,height
>     im.save(map_uri,'png')
>
> ... gives me a proper map of Karlsruhe within one or two seconds:
> http://www.remote.org/frederik/tmp/right.png (I know the forward
> projection is a null operation in this case, I just have the code in
> there always.)
>
> Now I simply want the same image shown in a Mercator projection. For now
> it doesn't matter which, I choose to go ahead with the spherical
> mercator used in OSM circles. So I change the <Map> element of my map
> file to have
>
> srs="+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 [EMAIL PROTECTED] +no_defs +over"
>
> and I also change the projection initialization on the above python
> script to
>
> prj = 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 [EMAIL PROTECTED] +no_defs +over")
>
> I leave all the other "srs" thingies in my map file unchanged since they
> describe the projection of the source data, which remains unchanged.
>
> This time, the script runs for about 20 seconds, and produces an image
> that has a wee bit of forest painted somewhere on the side - completely
> off (http://www.remote.org/frederik/tmp/wrong.png).
>
> Now what is wrong here? I know that I could load my data into PostGIS
> using the desired projection but I want Mapnik to project it for me so
> that I can use anything. I have tried different projections from the
> above spherical mercator, e.g. EPSG:3395, but had the same problem.
>
> Any ideas?
>

hmmm.. should work fine.

I ran a test here with similar inputs (code appended). The map files
have the srs defined the same as in the python code, as you describe
above. I reused the style sheet I'm using for the london progress
images otherwise.
The only difference is that my postgis db is projected into merc
(epsg:3395), ie: not spherical mercator, but not latlong either. I
kept the inputs the same... it's definitely reprojecting the output --
you'd see tile boundary artifacts on the cyclemap if it wasn't.

Anyway, I got the images:
http://beerwarmer.randomjunk.co.uk/progress-images/karlsruhe-ll.png
http://beerwarmer.randomjunk.co.uk/progress-images/karlsruhe-sph.png

which is what you'd expect.

If you send me your exact python and osm.xml I can take a closer look
to see if I can spot the problem

Dave



test_fred_ll.py:

from mapnik import *
def do_render():
   mapfile = "osm-ll.xml"
   map_uri = "karlsruhe-ll.png"
   ll = (8.32, 48.95, 8.48, 49.07)
   imgx = 400
   imgy = 300
   m = Map(imgx,imgy)
   load_map(m,mapfile)
   prj = Projection("+init=epsg:4326")
   c0 = prj.forward(Coord(ll[0],ll[1]))
   c1 = prj.forward(Coord(ll[2],ll[3]))
   bbox = Envelope(c0.x,c0.y,c1.x,c1.y)
   m.zoom_to_box(bbox)
   im = Image(imgx,imgy)
   render(m, im)
   view = im.view(0,0,imgx,imgy) # x,y,width,height
   im.save(map_uri,'png')
do_render()

test_fred_sphmerc.py:

from mapnik import *
def do_render():
   mapfile = "osm-sphmerc.xml"
   map_uri = "karlsruhe-sph.png"
   ll = (8.32, 48.95, 8.48, 49.07)
   imgx = 400
   imgy = 300
   m = Map(imgx,imgy)
   load_map(m,mapfile)
   prj = 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 [EMAIL PROTECTED] +no_defs
+over")
   c0 = prj.forward(Coord(ll[0],ll[1]))
   c1 = prj.forward(Coord(ll[2],ll[3]))
   bbox = Envelope(c0.x,c0.y,c1.x,c1.y)
   m.zoom_to_box(bbox)
   im = Image(imgx,imgy)
   render(m, im)
   view = im.view(0,0,imgx,imgy) # x,y,width,height
   im.save(map_uri,'png')
do_render()
_______________________________________________
Mapnik-users mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/mapnik-users

Reply via email to