Mapnik library has a Projection object (I'm using Python bindings):
spherical_mercator = '+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 +nadgrids=@null +no_defs +over'
p = mapnik.Projection(spherical_mercator)
nw = num2deg(column, row, zoom) # Upper left corner of the tile
se = num2deg(column+1, row+1, zoom) # Lower-right corner
coords = p.forward(mapnik.Box2d(nw.x, nw.y, se.x, se.y))
The tile has 256x256 pixels. I'm supposed to render the tiles using a buffer of 64 pixels (25%) - how do I obtain a Box2d to the selected area enlarged by 25%?
I'm sure the mapnik library has some built-in tool to make this calculation, but I'm unable to find it - documentation seems pretty scarce and I don't know enough about the math involved to figure out from the source code (I'm a programmer, not a geographer).
[update]
Seems like multiplication is overloaded to do just that in Box2d:
buffered_coords = coords * 1.5
So far, seems like the utfgrid don't match the png image for the same tile (it is offset and out of scale):
I would expect the following utfgrid to resemble an "ascii art" version of the above tile (Bauru is the red polygon and the actual character is not "#", it is "\u00000").
grid({
"keys" : ["68", "40"],
"data" : {
"68" : {
"NM_MUNICIP" : "Bauru",
"ID" : 1794.0,
"CD_GEOCODM" : "3506003"
},
"40" : {
"NM_MUNICIP" : "Arealva",
"ID" : 1766.0,
"CD_GEOCODM" : "3503406"
}
},
"grid" : [
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
" ###############################################################",
"################################################################",
"!!##############################################################",
"!!!#############################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
"################################################################",
" ###############################################################",
" ###############################################################",
"################################################################",
" ###############################################################",
"################################################################",
"################################################################",
" ###############################################################",
"################################################################",
" ############################################################",
" #############################################################",
"################################################################",
" ###############################################################"
]
});
Almost the same code is used to render both artifacts, but I'm still doing something wrong. back to the source.
[update]
The grid on the right is supposed to match the dashed area in the left tile. I can't figure out the kind of distortion involved. Is it mirrored and offset to the left?