3

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):

enter image description here

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?

enter image description here

1 Answer 1

1

My code turned out to be OK, the problem was solved by rebuilding mapnik from the github repository.

Lessons learned:

  • the utfgrid should always look like an ascii art version of the rendered tile.
  • if not, watch out for '\u0000' characters in the utfgrid - since the spec has provisions that avoid such characters, there is a high chance you have a buggy mapnik library installed.
  • I should trust my code.

This is what the correct utfgrid looks like:

grid({
    "keys" : ["477", "219", "40", "252", "50", "68", "414"],
    "data" : {
        "50"  : { "NM_MUNICIP" : "Ava\u00ed", "ID" : 1776.0, "CD_GEOCODM" : "3504305" },
        "40"  : { "NM_MUNICIP" : "Arealva", "ID" : 1766.0, "CD_GEOCODM" : "3503406" },
        "219" : { "NM_MUNICIP" : "Iacanga", "ID" : 1945.0, "CD_GEOCODM" : "3519105" },
        "414" : { "NM_MUNICIP" : "Pederneiras", "ID" : 2140.0, "CD_GEOCODM" : "3536703" },
        "68"  : { "NM_MUNICIP" : "Bauru", "ID" : 1794.0, "CD_GEOCODM" : "3506003" },
        "477" : { "NM_MUNICIP" : "Regin\u00f3polis", "ID" : 2203.0, "CD_GEOCODM" : "3542503" },
        "252" : { "NM_MUNICIP" : "Itaju", "ID" : 1978.0, "CD_GEOCODM" : "3522000" } },
    "grid" : [
    "               !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#####$$", 
    "               !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!########$", 
    "                !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!############", 
    "                !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!###############", 
    "                 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!################", 
    "                 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#################", 
    "                 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#################", 
    "                 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!################$", 
    "                  !!!!!!!!!!!!!!!!!!!!!!!!!!!!#################$", 
    "                  !!!!!!!!!!!!!!!!!!!!!!!!!!!#################$$", 
    "                   !!!!!!!!!!!!!!!!!!!!!!!!###################$$", 
    "                   !!!!!!!!!!!!!!!!!!!!!!!###################$$$", 
    "                  !!!!!!!!!!!!!!!!!!!!!!!###################$$$$", 
    "                  !!!!!!!!!!!##!!!!!!!!!!###################$$$$", 
    "                  !!!!!!!!!!!#####!!!!!!####################$$$$", 
    "                 !!!!!!####!########!!!!#####################$$$", 
    "                 !!!!################!!#########################", 
    "                !!!!############################################", 
    "               !!!!#############################################", 
    "                !!##############################################", 
    "               !!###############################################", 
    "                ################################################", 
    "%                ###############################################", 
    "%%%%%  %%      & ###############################################", 
    "%%%%%%%%%%%&&&&&&###############################################", 
    "%%%%%%%%%%&&&&&&&###############################################", 
    "%%%%%%%%%%&&&&&&&&##############################################", 
    "%%%%%%%%&&&&&&&&&&&#############################################", 
    "%%%%%%%%&&&&&&&&&&&&############################################", 
    "%%%%%%&&&&&&&&&&&&&&############################################", 
    "%%%%&&&&&&&&&&&&&&&&###########################################'", 
    "%%%&&&&&&&&&&&&&&&&&##########################################''", 
    "%%&&&&&&&&&&&&&&&&&&&#########################################''", 
    "%%&&&&&&&&&&&&&&&&&&&&&####################################'''''", 
    "%%&&&&&&&&&&&&&&&&&&&&&&&#################################''''''", 
    "%%&&&&&&&&&&&&&&&&&&&&&&&&&##############################'''''''", 
    "%%&&&&&&&&&&&&&&&&&&&&&&&&&#############################''''''''", 
    "%%&&&&&&&&&&&&&&&&&&&&&&&&&&############################''''''''", 
    "%%&&&&&&&&&&&&&&&&&&&&&&&&&&###########################'''''''''", 
    "%%&&&&&&&&&&&&&&&&&&&&&&&&&&###########################'''''''''", 
    "%%&&&&&&&&&&&&&&&&&&&&&&&&&###########################''''''''''", 
    "%&&&&&&&&&&&&&&&&&&&&&&&&&&##########################'''''''''''", 
    "%&&&&&&&&&&&&&&&&&&&&&&&&&&##########################'''''''''''", 
    "%&&&&&&&&&&&&&&&&&&&&&&&&&&#########################''''''''''''", 
    "%&&&&&&&&&&&&&&&&&&&&&&&&&&&#######################'''''''''''''", 
    "%&&&&&&&&&&&&&&&&&&&&&&&&&&&&#####################''''''''''''''", 
    "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&##################'''''''''''''''", 
    "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&################''''''''''''''''", 
    "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&##############'''''''''''''''''", 
    "%&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&############''''''''''''''''''", 
    "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&###########'''''''''''''''''''", 
    "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&##########''''''''''''''''''''", 
    "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&#########'''''''''''''''''''''", 
    "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&''''''####''''''''''''''''''''''", 
    "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&'''''''''''''''''''''''''''''''''", 
    "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&''''''''''''''''''''''''''''''''", 
    "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&''''''''''''''''''''''''''''''''''", 
    "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&''''''''''''''''''''''''''''''''''", 
    "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&'''''''''''''''''''''''''''''''''", 
    "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&'''''''''''''''''''''''''''''''''", 
    "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&''''''''''''''''''''''''''''''''", 
    "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&''''''''''''''''''''''''''''''''", 
    "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&''''''''''''''''''''''''''''''''", 
    "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&'''''''''''''''''''''''''''''''"
    ]
}); 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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