On Mon, 2008-10-13 at 18:24 -0400, Filipe Fortes wrote:
> Hello All,
>  
> I'm just starting out with Mapnik and having an issue trying to
> duplicate the mercator projection used in Google Maps.
>  
> I've taken the Hello World example from the map and modified it to use
> a different projection:
> 
>         #!/usr/bin/env python
>         from mapnik import *
>         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'
>         m = Map(600,300,projection)
>         m.background = Color('steelblue')
>         m.srs = projection
>         s = Style()
>         r = Rule()
>         r.symbols.append(PolygonSymbolizer(Color('#f2eff9')))
>         r.symbols.append(LineSymbolizer(Color('rgb(50%,50%,50%)'),0.1))
>         s.rules.append(r)
>         m.append_style('My Style',s)
>         lyr = Layer('world')
>         lyr.datasource = Shapefile(file='shapefiles/world_borders')
>         lyr.styles.append('My Style')
>         lyr.srs = '+proj=latlong +datum=WGS84'
>         m.layers.append(lyr)
>         p = Projection(projection)
>         lower_left_xy = p.forward(Coord(-180.0, -45.0))
>         upper_right_xy = p.forward(Coord(180.0, 80.0))
>         bbox = Envelope(lower_left_xy,upper_right_xy)
>         m.zoom_to_box(bbox)
>         render_to_file(m,'images/world.png', 'png')
>  
> I've attached the output -- as you can see, it's only rendering a
> subset of the countries, and I can't find any rhyme or reason why only
> those countries are showing up.
>  
> I've also switched and used the TM world borders shapefile [1] --
> which renders exactly the same with the exception of also rendering
> the US. If I go back to using the latlong projection, this problem
> disappears.
>  
> I'm guessing there's something basic I'm missing here, so I appreciate
> any one taking the time out to help a newbie :)

That looks like the sort of issue that can happen when you deal with
projecting data at or very close to the 'edge' of the world. Problems
happen when the extremes of the bounding box in one projection wrap when
projected to another. I had this with OSM shapefiles:
https://lists.berlios.de/pipermail/mapnik-devel/2007-September/000236.html

Try:
- reducing the +-180 in the Coord() to say +-179
- check the extent on the shapefile (shpinfo will give you this)

You may need to clip the edges of your shapefile very slightly (again
try +-179 to see if that helps). 1 degree is overkill but should
demonstrate if this helps.

The more reliable solution is to convert your shapefiles to match the
map projection and then use these in Mapnik. Avoiding the reprojection
during the rendering is key.

        Jon


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

Reply via email to