[OSM-dev] mod_tile - meta tile computation
Philipp Borgers
borgers at mi.fu-berlin.de
Tue Dec 28 20:04:08 GMT 2010
Sorry for the first, stupid mail.
I'm trying to write a nginx module which does more or less the same like
mod_tile. I reviewed a lot of the code but now I have a little problem
with the computation of paths to meta tiles. Could someone please
explain me how mod_tile creates file paths from a request and how the
offset is computed? My own code looks exactly the same but returns
x=0,z=0 for every input. I'm highly confused :)
The original code should look like this:
int xyz_to_meta(char *path, size_t len, const char *tile_dir, const char *xmlconfig, int x, int y, int z)
{
unsigned char i, hash[5], offset, mask;
// Each meta tile winds up in its own file, with several in each leaf directory
// the .meta tile name is beasd on the sub-tile at (0,0)
mask = METATILE - 1;
offset = (x & mask) * METATILE + (y & mask);
x &= ~mask;
y &= ~mask;
for (i=0; i<5; i++) {
hash[i] = ((x & 0x0f) << 4) | (y & 0x0f);
x >>= 4;
y >>= 4;
}
#ifdef DIRECTORY_HASH
snprintf(path, len, "%s/%s/%d/%u/%u/%u/%u/%u.meta", tile_dir, xmlconfig, z, hash[4], hash[3], hash[2], hash[1], hash[0]);
#else
snprintf(path, len, "%s/%s/%d/%u/%u.meta", tile_dir, xmlconfig, z, x, y);
#endif
return offset;
}
#endif
The nginx code looks like this:
#define METATILE (8)
static ngx_int_t
ngx_http_serve_request_handler(ngx_http_request_t *r, struct protocol *cmd)
{
char *path;
unsigned char hash[5],offset, mask;
int i,x,y;
ngx_http_core_loc_conf_t *clcf;
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
if((path = ngx_palloc(r->pool, 256)) == NULL)
return NGX_HTTP_INTERNAL_SERVER_ERROR;
printf("original: %d, %d, %d\n", cmd->z, cmd->x, cmd->y);
x = cmd->x;
y = cmd->y;
//build meta file name
mask = METATILE - 1;
offset = (x & mask) * METATILE + (y & mask);
x &= ~mask;
y &= ~mask;
for(i=0; i<5;i++) {
hash[i] = ((x & 0x0f) << 4) | (y & 0x0f);
x >>=4;
y >>=4;
}
printf("%d,%u,%u\n",cmd->z,x,y);
return NGX_OK;
}
Thanks for any help.
best regards
philipp
More information about the dev
mailing list