Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow applying dimensions through WMS filter #185

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 43 additions & 27 deletions lib/source_wms.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,44 @@ struct mapcache_source_wms {
mapcache_http *http;
};

void _apply_dimensions(mapcache_context *ctx, apr_table_t *params, mapcache_map *map)
{
const char *filter_tmpl;
if(map->dimensions && map->dimensions->nelts>0) {
int i;
for(i=0; i<map->dimensions->nelts; i++) {
mapcache_requested_dimension *rdim = APR_ARRAY_IDX(map->dimensions,i,mapcache_requested_dimension*);
/* set both DIM_key=val and key=val KVP params */
apr_table_setn(params,rdim->dimension->name,rdim->cached_value);
if(strcasecmp(rdim->dimension->name,"TIME") && strcasecmp(rdim->dimension->name,"ELEVATION")) {
char *dim_name = apr_pstrcat(ctx->pool,"DIM_",rdim->dimension->name,NULL);
apr_table_setn(params,dim_name,rdim->cached_value);
}
}
}

filter_tmpl = apr_table_get(params,"FILTER");
if (filter_tmpl != 0 && strstr(filter_tmpl,"{dim")) {
char *filter = apr_pstrdup(ctx->pool,filter_tmpl);
int i;
for(i=0; i<map->dimensions->nelts; i++) {
mapcache_requested_dimension *entry = APR_ARRAY_IDX(map->dimensions,i, mapcache_requested_dimension*);
char *dimval;
char *single_dim;
if(!entry->cached_value) {
ctx->set_error(ctx,500,"BUG: dimension (%s) not set",entry->dimension->name);
return;
}
dimval = apr_pstrdup(ctx->pool,entry->cached_value);
single_dim = apr_pstrcat(ctx->pool,"{dim:",entry->dimension->name,"}",NULL);
while(strstr(filter,single_dim)) {
filter = mapcache_util_str_replace(ctx->pool,filter, single_dim, dimval);
}
}
apr_table_setn(params,"FILTER",filter);
}
}

/**
* \private \memberof mapcache_source_wms
* \sa mapcache_source::render_map()
Expand All @@ -64,20 +102,9 @@ void _mapcache_source_wms_render_map(mapcache_context *ctx, mapcache_source *pso
apr_table_setn(params,"SRS",map->grid_link->grid->srs);

apr_table_overlap(params,wms->getmap_params,APR_OVERLAP_TABLES_SET);

if(map->dimensions && map->dimensions->nelts>0) {
int i;
for(i=0; i<map->dimensions->nelts; i++) {
mapcache_requested_dimension *rdim = APR_ARRAY_IDX(map->dimensions,i,mapcache_requested_dimension*);
/* set both DIM_key=val and key=val KVP params */
apr_table_setn(params,rdim->dimension->name,rdim->cached_value);
if(strcasecmp(rdim->dimension->name,"TIME") && strcasecmp(rdim->dimension->name,"ELEVATION")) {
char *dim_name = apr_pstrcat(ctx->pool,"DIM_",rdim->dimension->name,NULL);
apr_table_setn(params,dim_name,rdim->cached_value);
}
}
}


_apply_dimensions(ctx, params, map);

/* if the source has no LAYERS parameter defined, then use the tileset name
* as the LAYERS to request. When using mirror-mode, the source has no layers
* defined, it is added based on the incoming request
Expand Down Expand Up @@ -118,19 +145,8 @@ void _mapcache_source_wms_query(mapcache_context *ctx, mapcache_source *source,
apr_table_setn(params,"INFO_FORMAT",fi->format);

apr_table_overlap(params,wms->getfeatureinfo_params,0);

if(map->dimensions && map->dimensions->nelts>0) {
int i;
for(i=0; i<map->dimensions->nelts; i++) {
mapcache_requested_dimension *rdim = APR_ARRAY_IDX(map->dimensions,i,mapcache_requested_dimension*);
/* set both DIM_key=val and key=val KVP params */
apr_table_setn(params,rdim->dimension->name,rdim->cached_value);
if(strcasecmp(rdim->dimension->name,"TIME") && strcasecmp(rdim->dimension->name,"ELEVATION")) {
char *dim_name = apr_pstrcat(ctx->pool,"DIM_",rdim->dimension->name,NULL);
apr_table_setn(params,dim_name,rdim->cached_value);
}
}
}

_apply_dimensions(ctx, params, map);

fi->data = mapcache_buffer_create(30000,ctx->pool);
http = mapcache_http_clone(ctx, wms->http);
Expand Down