Skip to content

Commit

Permalink
SLD: Add support to arithmetic expressions (MapServer#5831)
Browse files Browse the repository at this point in the history
This adds support to arithmetic expressions in SLD documents read by MapServer. It implements the first section of MS RFC 124: Improving SLD Support in MapServer : https://mapserver.org/development/rfc/ms-rfc-124.html
  • Loading branch information
jbo-ads authored and rouault committed Sep 4, 2019
1 parent dd8ae3e commit 4fbd7ae
Show file tree
Hide file tree
Showing 92 changed files with 2,546 additions and 201 deletions.
6 changes: 6 additions & 0 deletions mapcopy.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,11 @@ int msCopyLabel(labelObj *dst, labelObj *src)
for(i=0; i<MS_LABEL_BINDING_LENGTH; i++) {
MS_COPYSTRING(dst->bindings[i].item, src->bindings[i].item);
dst->bindings[i].index = src->bindings[i].index; /* no way to use the macros */
MS_COPYSTRING(dst->exprBindings[i].string, src->exprBindings[i].string);
dst->exprBindings[i].type = src->exprBindings[i].type;
}
MS_COPYSTELEM(numbindings);
MS_COPYSTELEM(nexprbindings);

MS_COPYSTRING(dst->font, src->font);

Expand Down Expand Up @@ -471,8 +474,11 @@ int msCopyStyle(styleObj *dst, styleObj *src)
for(i=0; i<MS_STYLE_BINDING_LENGTH; i++) {
MS_COPYSTRING(dst->bindings[i].item, src->bindings[i].item);
dst->bindings[i].index = src->bindings[i].index; /* no way to use the macros */
MS_COPYSTRING(dst->exprBindings[i].string, src->exprBindings[i].string);
dst->exprBindings[i].type = src->exprBindings[i].type;
}
MS_COPYSTELEM(numbindings);
MS_COPYSTELEM(nexprbindings);

MS_COPYCOLOR(&(dst->color), &(src->color));
MS_COPYCOLOR(&(dst->outlinecolor),&(src->outlinecolor));
Expand Down
23 changes: 20 additions & 3 deletions mapfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1675,9 +1675,11 @@ void initLabel(labelObj *label)
label->styles = NULL;

label->numbindings = 0;
label->nexprbindings = 0;
for(i=0; i<MS_LABEL_BINDING_LENGTH; i++) {
label->bindings[i].item = NULL;
label->bindings[i].index = -1;
msInitExpression(&(label->exprBindings[i]));
}

msInitExpression(&(label->expression));
Expand Down Expand Up @@ -1718,8 +1720,10 @@ int freeLabel(labelObj *label)
}
msFree(label->styles);

for(i=0; i<MS_LABEL_BINDING_LENGTH; i++)
for(i=0; i<MS_LABEL_BINDING_LENGTH; i++) {
msFree(label->bindings[i].item);
msFreeExpression(&(label->exprBindings[i]));
}

msFreeExpression(&(label->expression));
msFreeExpression(&(label->text));
Expand Down Expand Up @@ -1963,15 +1967,24 @@ static int loadLabel(labelObj *label)
label->bindings[MS_LABEL_BINDING_SIZE].item = NULL;
label->numbindings--;
}
if (label->exprBindings[MS_LABEL_BINDING_SIZE].string) {
msFreeExpression(&label->exprBindings[MS_LABEL_BINDING_SIZE]);
label->nexprbindings--;
}

if((symbol = getSymbol(7, MS_NUMBER,MS_BINDING,MS_TINY,MS_SMALL,MS_MEDIUM,MS_LARGE,MS_GIANT)) == -1)
if((symbol = getSymbol(8, MS_EXPRESSION,MS_NUMBER,MS_BINDING,MS_TINY,MS_SMALL,MS_MEDIUM,MS_LARGE,MS_GIANT)) == -1)
return(-1);

if(symbol == MS_NUMBER) {
label->size = (double) msyynumber;
} else if(symbol == MS_BINDING) {
label->bindings[MS_LABEL_BINDING_SIZE].item = msStrdup(msyystring_buffer);
label->numbindings++;
} else if (symbol == MS_EXPRESSION) {
msFree(label->exprBindings[MS_LABEL_BINDING_SIZE].string);
label->exprBindings[MS_LABEL_BINDING_SIZE].string = msStrdup(msyystring_buffer);
label->exprBindings[MS_LABEL_BINDING_SIZE].type = MS_EXPRESSION;
label->nexprbindings++;
} else
label->size = symbol;
break;
Expand Down Expand Up @@ -2599,9 +2612,11 @@ int initStyle(styleObj *style)
style->linejoinmaxsize = MS_CJC_DEFAULT_JOIN_MAXSIZE;

style->numbindings = 0;
style->nexprbindings = 0;
for(i=0; i<MS_STYLE_BINDING_LENGTH; i++) {
style->bindings[i].item = NULL;
style->bindings[i].index = -1;
msInitExpression(&(style->exprBindings[i]));
}

return MS_SUCCESS;
Expand Down Expand Up @@ -2920,8 +2935,10 @@ int freeStyle(styleObj *style)
msFreeExpression(&style->_geomtransform);
msFree(style->rangeitem);

for(i=0; i<MS_STYLE_BINDING_LENGTH; i++)
for(i=0; i<MS_STYLE_BINDING_LENGTH; i++) {
msFree(style->bindings[i].item);
msFreeExpression(&(style->exprBindings[i]));
}

return MS_SUCCESS;
}
Expand Down
26 changes: 25 additions & 1 deletion maplayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ int msLayerWhichItems(layerObj *layer, int get_all, const char *metadata)

if(layer->_geomtransform.type == MS_GEOMTRANSFORM_EXPRESSION)
msTokenizeExpression(&layer->_geomtransform, layer->items, &(layer->numitems));

/* class level counts */
for(i=0; i<layer->numclasses; i++) {

Expand All @@ -839,6 +839,12 @@ int msLayerWhichItems(layerObj *layer, int get_all, const char *metadata)
nt += layer->class[i]->styles[j]->numbindings;
if(layer->class[i]->styles[j]->_geomtransform.type == MS_GEOMTRANSFORM_EXPRESSION)
nt += msCountChars(layer->class[i]->styles[j]->_geomtransform.string, '[');
for(k=0; k<MS_STYLE_BINDING_LENGTH; k++) {
if (layer->class[i]->styles[j]->exprBindings[k].type == MS_EXPRESSION)
{
nt += msCountChars(layer->class[i]->styles[j]->exprBindings[k].string, '[');
}
}
}

if(layer->class[i]->expression.type == MS_EXPRESSION)
Expand All @@ -852,6 +858,12 @@ int msLayerWhichItems(layerObj *layer, int get_all, const char *metadata)
if(layer->class[i]->labels[l]->styles[j]->_geomtransform.type == MS_GEOMTRANSFORM_EXPRESSION)
nt += msCountChars(layer->class[i]->labels[l]->styles[j]->_geomtransform.string, '[');
}
for(k=0; k<MS_LABEL_BINDING_LENGTH; k++) {
if (layer->class[i]->labels[l]->exprBindings[k].type == MS_EXPRESSION)
{
nt += msCountChars(layer->class[i]->labels[l]->exprBindings[k].string, '[');
}
}

if(layer->class[i]->labels[l]->expression.type == MS_EXPRESSION)
nt += msCountChars(layer->class[i]->labels[l]->expression.string, '[');
Expand Down Expand Up @@ -908,6 +920,12 @@ int msLayerWhichItems(layerObj *layer, int get_all, const char *metadata)
for(k=0; k<MS_STYLE_BINDING_LENGTH; k++) {
if(layer->class[i]->styles[j]->bindings[k].item)
layer->class[i]->styles[j]->bindings[k].index = string2list(layer->items, &(layer->numitems), layer->class[i]->styles[j]->bindings[k].item);
if (layer->class[i]->styles[j]->exprBindings[k].type == MS_EXPRESSION)
{
msTokenizeExpression(
&(layer->class[i]->styles[j]->exprBindings[k]),
layer->items, &(layer->numitems));
}
}
if(layer->class[i]->styles[j]->_geomtransform.type == MS_GEOMTRANSFORM_EXPRESSION)
msTokenizeExpression(&(layer->class[i]->styles[j]->_geomtransform), layer->items, &(layer->numitems));
Expand All @@ -928,6 +946,12 @@ int msLayerWhichItems(layerObj *layer, int get_all, const char *metadata)
for(k=0; k<MS_LABEL_BINDING_LENGTH; k++) {
if(layer->class[i]->labels[l]->bindings[k].item)
layer->class[i]->labels[l]->bindings[k].index = string2list(layer->items, &(layer->numitems), layer->class[i]->labels[l]->bindings[k].item);
if (layer->class[i]->labels[l]->exprBindings[k].type == MS_EXPRESSION)
{
msTokenizeExpression(
&(layer->class[i]->labels[l]->exprBindings[k]),
layer->items, &(layer->numitems));
}
}

/* label expression */
Expand Down
Loading

0 comments on commit 4fbd7ae

Please sign in to comment.