@@ -398,7 +398,7 @@ char * str_replace_all(apr_pool_t *pool, const char *string,
398398char * dbfilename (apr_pool_t * pool , char * template ,
399399 mapcache_tileset * tileset , mapcache_grid * grid ,
400400 apr_array_header_t * dimensions , apr_hash_t * fmt , int z ,
401- int dbx , int dby , int xcount , int ycount )
401+ int dbx , int dby , int xcount , int ycount , int top )
402402{
403403 int tilx = dbx * xcount ;
404404 int tily = dby * ycount ;
@@ -469,6 +469,26 @@ char * dbfilename(apr_pool_t * pool, char * template,
469469 apr_psprintf (pool , curfmt , dby ));
470470 }
471471
472+ // Z top
473+ if (top > 0 ) {
474+ char * curfmt ;
475+ curfmt = apr_hash_get (fmt , "top" , APR_HASH_KEY_STRING );
476+ path = str_replace_all (pool , path , "{top}" ,
477+ apr_psprintf (pool , curfmt , top ));
478+ curfmt = apr_hash_get (fmt , "top_x" , APR_HASH_KEY_STRING );
479+ path = str_replace_all (pool , path , "{top_x}" ,
480+ apr_psprintf (pool , curfmt , dbx ));
481+ curfmt = apr_hash_get (fmt , "inv_top_x" , APR_HASH_KEY_STRING );
482+ path = str_replace_all (pool , path , "{inv_top_x}" ,
483+ apr_psprintf (pool , curfmt , dbx ));
484+ curfmt = apr_hash_get (fmt , "top_y" , APR_HASH_KEY_STRING );
485+ path = str_replace_all (pool , path , "{top_y}" ,
486+ apr_psprintf (pool , curfmt , dby ));
487+ curfmt = apr_hash_get (fmt , "inv_top_y" , APR_HASH_KEY_STRING );
488+ path = str_replace_all (pool , path , "{inv_top_y}" ,
489+ apr_psprintf (pool , curfmt , dby ));
490+ }
491+
472492 return path ;
473493}
474494
@@ -659,7 +679,7 @@ int main(int argc, char * argv[])
659679 int minzoom , maxzoom ;
660680 char * dbfile ;
661681 apr_hash_t * formats ;
662- int xcount , ycount ;
682+ int xcount , ycount , top ;
663683 } * cache ;
664684 apr_array_header_t * caches = NULL ;
665685 int i , ix , iy , iz ;
@@ -1067,6 +1087,11 @@ int main(int argc, char * argv[])
10671087 apr_hash_set (c -> formats , "div_y" , APR_HASH_KEY_STRING , "(not set)" );
10681088 apr_hash_set (c -> formats , "inv_div_x" , APR_HASH_KEY_STRING , "(not set)" );
10691089 apr_hash_set (c -> formats , "inv_div_y" , APR_HASH_KEY_STRING , "(not set)" );
1090+ apr_hash_set (c -> formats , "top" , APR_HASH_KEY_STRING , "(not set)" );
1091+ apr_hash_set (c -> formats , "top_x" , APR_HASH_KEY_STRING , "(not set)" );
1092+ apr_hash_set (c -> formats , "top_y" , APR_HASH_KEY_STRING , "(not set)" );
1093+ apr_hash_set (c -> formats , "inv_top_x" , APR_HASH_KEY_STRING , "(not set)" );
1094+ apr_hash_set (c -> formats , "inv_top_y" , APR_HASH_KEY_STRING , "(not set)" );
10701095 for (hi = apr_hash_first (ctx .pool , c -> formats )
10711096 ; hi
10721097 ; hi = apr_hash_next (hi ))
@@ -1089,6 +1114,13 @@ int main(int argc, char * argv[])
10891114 text = NULL ;
10901115 if (node ) text = node -> txt ;
10911116 if (text ) c -> ycount = (int )strtol (text , NULL , 10 );
1117+
1118+ // Read top
1119+ c -> top = -1 ;
1120+ node = ezxml_child (c -> node , "top" );
1121+ text = NULL ;
1122+ if (node ) text = node -> txt ;
1123+ if (text ) c -> top = (int )strtol (text , NULL , 10 );
10921124 }
10931125
10941126
@@ -1266,10 +1298,31 @@ int main(int argc, char * argv[])
12661298 & (til_region_bbox .maxx ), & (til_region_bbox .maxy ));
12671299
12681300 dbx_has_inv = strstr (cache -> dbfile ,"{inv_x}" )
1269- || strstr (cache -> dbfile ,"{inv_div_x}" );
1301+ || strstr (cache -> dbfile ,"{inv_div_x}" )
1302+ || strstr (cache -> dbfile ,"{inv_top_x}" );
12701303 dby_has_inv = strstr (cache -> dbfile ,"{inv_y}" )
1271- || strstr (cache -> dbfile ,"{inv_div_y}" );
1272- if ((cache -> xcount > 0 ) && (cache -> ycount > 0 )) {
1304+ || strstr (cache -> dbfile ,"{inv_div_y}" )
1305+ || strstr (cache -> dbfile ,"{inv_top_y}" );
1306+ if (cache -> top > 0 ) {
1307+ mapcache_grid_get_xy (& ctx , grid , region_bbox .minx , region_bbox .miny ,
1308+ cache -> top , & (til_region_bbox .minx ), & (til_region_bbox .miny ));
1309+ mapcache_grid_get_xy (& ctx , grid , region_bbox .maxx , region_bbox .maxy ,
1310+ cache -> top , & (til_region_bbox .maxx ), & (til_region_bbox .maxy ));
1311+ if (dbx_has_inv ) {
1312+ db_region_bbox .minx = grid -> levels [cache -> top ]-> maxx - til_region_bbox .maxx ;
1313+ db_region_bbox .maxx = grid -> levels [cache -> top ]-> maxx - til_region_bbox .minx ;
1314+ } else {
1315+ db_region_bbox .minx = til_region_bbox .minx ;
1316+ db_region_bbox .maxx = til_region_bbox .maxx ;
1317+ }
1318+ if (dby_has_inv ) {
1319+ db_region_bbox .miny = grid -> levels [cache -> top ]-> maxy - til_region_bbox .maxy ;
1320+ db_region_bbox .maxy = grid -> levels [cache -> top ]-> maxy - til_region_bbox .miny ;
1321+ } else {
1322+ db_region_bbox .miny = til_region_bbox .miny ;
1323+ db_region_bbox .maxy = til_region_bbox .maxy ;
1324+ }
1325+ } else if ((cache -> xcount > 0 ) && (cache -> ycount > 0 )) {
12731326 if (dbx_has_inv ) {
12741327 int inv_minx = grid -> levels [iz ]-> maxx - til_region_bbox .minx ;
12751328 int inv_maxx = grid -> levels [iz ]-> maxx - til_region_bbox .maxx ;
@@ -1332,15 +1385,15 @@ int main(int argc, char * argv[])
13321385 double progz = (double )(iz - minzoom ) * incz ;
13331386 double progx = (double )(ix - db_region_bbox .minx ) * incx ;
13341387 double progy = (double )(iy - db_region_bbox .miny ) * incy ;
1335- fprintf (stderr , "\033[2K In progress (z:%d x:%d y:%d): %.3f%% done\r " ,
1388+ fprintf (stderr , "\033[2K In progress (z:%d x:%d y:%d): %.3f%% done\n " ,
13361389 iz , ix , iy , (progz + progx + progy ) * 100.0 );
13371390 fflush (stderr );
13381391 }
13391392
13401393 // Retrieve DB file name and check for its existence (read access)
13411394 file_name = dbfilename (ctx .pool , cache -> dbfile , tileset , grid ,
13421395 dimensions , cache -> formats , iz , ix , iy , cache -> xcount ,
1343- cache -> ycount );
1396+ cache -> ycount , cache -> top );
13441397
13451398 // Unless this has already been done on this file,
13461399 // Retrieve file size and count cached tiles regardless the region of
@@ -1379,7 +1432,22 @@ int main(int argc, char * argv[])
13791432 }
13801433
13811434 // Compute file bounding box expressed in tiles
1382- if ((cache -> xcount > 0 ) && (cache -> ycount > 0 )) {
1435+ if (cache -> top > 0 ) {
1436+ if (dbx_has_inv ) {
1437+ til_file_bbox .minx = grid -> levels [cache -> top ]-> maxx - 1 - ix ;
1438+ til_file_bbox .maxx = grid -> levels [cache -> top ]-> maxx - 1 - ix ;
1439+ } else {
1440+ til_file_bbox .minx = ix ;
1441+ til_file_bbox .maxx = ix ;
1442+ }
1443+ if (dby_has_inv ) {
1444+ til_file_bbox .miny = grid -> levels [cache -> top ]-> maxy - 1 - iy ;
1445+ til_file_bbox .maxy = grid -> levels [cache -> top ]-> maxy - 1 - iy ;
1446+ } else {
1447+ til_file_bbox .miny = iy ;
1448+ til_file_bbox .maxy = iy ;
1449+ }
1450+ } else if ((cache -> xcount > 0 ) && (cache -> ycount > 0 )) {
13831451 if (dbx_has_inv ) {
13841452 til_file_bbox .maxx = grid -> levels [iz ]-> maxx - 1 - ix * cache -> xcount ;
13851453 til_file_bbox .minx = til_file_bbox .maxx + cache -> xcount + 1 ;
0 commit comments