Skip to content
Permalink
Browse files

Only advertize common layer SRSs on root layer (#176)

  • Loading branch information...
jbo-ads authored and tbonfort committed Sep 6, 2018
1 parent e66aef2 commit dca7999347d4a7a7973c3873b60242d5e007cb6b
Showing with 51 additions and 12 deletions.
  1. +51 −11 lib/service_wms.c
  2. +0 −1 tests/expected/wms_capabilities.xml
@@ -174,31 +174,71 @@ void _create_capabilities_wms(mapcache_context *ctx, mapcache_request_get_capabi
ezxml_set_txt(tmpxml,title);

/*
* announce all layer srs's in the root layer. This part of the wms spec we
* cannot respect with a caching solution, as each tileset can only be served
* under a specified number of projections.
*
* TODO: check for duplicates in gris srs
* announce all common layer srs's in the root layer.
*/
{
int srs_count = (int)apr_hash_count(cfg->grids);
char** srs_list = (char**)malloc(srs_count * sizeof(char*));
int layer_count = (int)apr_hash_count(cfg->tilesets);
struct srs_item { char * name; int count; };
struct srs_item * srs_list = malloc(srs_count * sizeof(struct srs_item));
int srs_iter = 0;
int nb_common_srs = 0;
int i;

// Build list of all layer's SRS
grid_index = apr_hash_first(ctx->pool,cfg->grids);
while(grid_index) {
const void *key;
apr_ssize_t keylen;
mapcache_grid *grid = NULL;
apr_hash_this(grid_index,&key,&keylen,(void**)&grid);
srs_list[srs_iter++] = grid->srs;
srs_list[srs_iter].count = 0;
srs_list[srs_iter++].name = grid->srs;
grid_index = apr_hash_next(grid_index);
}
qsort(srs_list, srs_count, sizeof(char*), sort_strings);
for(i = 0; i < srs_count; i ++)
{
ezxml_set_txt(ezxml_add_child(toplayer,"SRS",0),srs_list[i]);
qsort(srs_list, srs_count, sizeof(struct srs_item), sort_strings);

// Find out how many tilesets use each SRS
tileindex_index = apr_hash_first(ctx->pool,cfg->tilesets);
while(tileindex_index) {
const void *key;
apr_ssize_t keylen;
mapcache_tileset *tileset = NULL;
apr_hash_this(tileindex_index,&key,&keylen,(void**)&tileset);
for(i=0; i<tileset->grid_links->nelts; i++) {
mapcache_grid_link *gridlink;
mapcache_grid *grid;
int j,k;
gridlink = APR_ARRAY_IDX(tileset->grid_links,i,mapcache_grid_link*);
grid = gridlink->grid;
for (j=0; j<srs_iter; j++) {
if (!strcmp(grid->srs,srs_list[j].name)) {
srs_list[j].count++;
break;
}
}
for (k=0; k<grid->srs_aliases->nelts; k++) {
char * gridalias = APR_ARRAY_IDX(grid->srs_aliases,k,char*);
for (j=0; j<srs_iter; j++) {
if (!strcmp(gridalias,srs_list[j].name)) {
srs_list[j].count++;
break;
}
}
}
}
tileindex_index = apr_hash_next(tileindex_index);
}

// Output only SRS common to all layers
for(i = 0; i < srs_count; i ++) {
if (srs_list[i].count == layer_count) {
ezxml_set_txt(ezxml_add_child(toplayer,"SRS",0),srs_list[i].name);
nb_common_srs++;
}
}
if (nb_common_srs == 0) {
ezxml_add_child(toplayer,"SRS",0);
}
free(srs_list);
}
@@ -61,7 +61,6 @@
<Layer>
<Title>no title set, add some in metadata</Title>
<SRS>EPSG:3857</SRS>
<SRS>EPSG:4326</SRS>
<SRS>EPSG:900913</SRS>
<Layer cascaded="1" queryable="0">
<Name>global</Name>

0 comments on commit dca7999

Please sign in to comment.
You can’t perform that action at this time.