0

I am using tm_wgs84_sans_antarctica.shp with mapnik to generate tiles. I am using the tiles with Google Maps Javascript API V3. But the projection is way off. Here is roughly what my code looks like:

import mapnik
m = mapnik.Map(
      tile.size()[0],
      tile.size()[0],
      )
s = mapnik.Style()
r = mapnik.Rule()

polygon_symbolizer = mapnik.PolygonSymbolizer(mapnik.Color('#f2eff9'))
r.symbols.append(polygon_symbolizer)
s.rules.append(r)

m.append_style('My Style',s)

ds = mapnik.Shapefile(file='tm_wgs84_sans_antarctica.shp')
layer = mapnik.Layer('world')
layer.datasource = ds
layer.styles.append('My Style')
m.layers.append(layer)

bbox = tile.bounds()
bbox = mapnik.Box2d(bbox[0], bbox[1], bbox[2], bbox[3])
m.zoom_to_box(bbox)
im = mapnik.Image( *tile.size() )
mapnik.render(m, im)

As you can see I am not setting any srs either in map or in layer. I tried different combination of projection strings without really understanding what they mean, but either got no map or wrongly projected map. Please let me know if any other information is required.

Thanks.

  • is there a prj file with the shp and dbf files? If so it should have the projection information in the prj file. It is in text format. – mhoran_psprep Mar 28 '12 at 21:57
0

The prj file has this:

GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.017453292519943295]]

Using srs +init=epsg:4326 which is defined as:

+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs

fixed the problem. Now the shape file gets rendered fine with google maps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.