Skip to content

Commit

Permalink
[Backport branch-8-0] Include list expressions in GetStyles SLD output (
Browse files Browse the repository at this point in the history
#6946)

Fixes #6911
  • Loading branch information
github-actions[bot] committed Oct 17, 2023
1 parent 245afbf commit 117c2ee
Show file tree
Hide file tree
Showing 7 changed files with 250 additions and 0 deletions.
52 changes: 52 additions & 0 deletions mapogcsld.c
Expand Up @@ -5386,6 +5386,58 @@ char *msSLDGetFilter(classObj *psClass, const char *pszWfsFilter) {
} else if (psClass->expression.type == MS_EXPRESSION) {
pszFilter =
msSLDParseLogicalExpression(psClass->expression.string, pszWfsFilter);
} else if (psClass->expression.type == MS_LIST) {
if (psClass->layer && psClass->layer->classitem &&
psClass->expression.string) {

char *pszTmp = NULL;
char *pszTmpFilters = NULL;

char **listExpressionValues = NULL;
int numListExpressionValues = 0;
int i = 0;
int tokenCount = 0;

listExpressionValues = msStringSplit(psClass->expression.string, ',',
&numListExpressionValues);

// loop through all values in the list and create a PropertyIsEqualTo
// for each value
for (i = 0; i < numListExpressionValues; i++) {
if (listExpressionValues[i] && listExpressionValues[i][0] != '\0') {

snprintf(szBuffer, sizeof(szBuffer),
"<ogc:PropertyIsEqualTo><ogc:PropertyName>%s</"
"ogc:PropertyName><ogc:Literal>%s</ogc:Literal></"
"ogc:PropertyIsEqualTo>\n",
psClass->layer->classitem, listExpressionValues[i]);

pszTmpFilters = msStringConcatenate(pszTmpFilters, szBuffer);
tokenCount++;
}
}

pszTmp = msStringConcatenate(pszTmp, "<ogc:Filter>");

// no need for an OR clause if there is only one item in the list
if (tokenCount == 1) {
pszTmp = msStringConcatenate(pszTmp, pszTmpFilters);
} else if (tokenCount > 1) {
pszTmp = msStringConcatenate(pszTmp, "<ogc:Or>");
pszTmp = msStringConcatenate(pszTmp, pszTmpFilters);
pszTmp = msStringConcatenate(pszTmp, "</ogc:Or>");
}

pszTmp = msStringConcatenate(pszTmp, "</ogc:Filter>");

// don't filter when the list is empty
if (tokenCount > 0) {
pszFilter = msStrdup(pszTmp);
}
msFreeCharArray(listExpressionValues, numListExpressionValues);
free(pszTmp);
free(pszTmpFilters);
}
} else if (psClass->expression.type == MS_REGEX) {
if (psClass->layer && psClass->layer->classitem &&
psClass->expression.string) {
Expand Down
26 changes: 26 additions & 0 deletions msautotest/wxs/expected/wms_getstyles_expressions13.xml
@@ -0,0 +1,26 @@
<StyledLayerDescriptor version="1.1.0" xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd" xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:se="http://www.opengis.net/se" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<NamedLayer>
<se:Name>Test13</se:Name>
<UserStyle>
<se:FeatureTypeStyle>
<se:Rule>
<ogc:Filter><ogc:Or><ogc:PropertyIsEqualTo><ogc:PropertyName>FID</ogc:PropertyName><ogc:Literal>2</ogc:Literal></ogc:PropertyIsEqualTo>
<ogc:PropertyIsEqualTo><ogc:PropertyName>FID</ogc:PropertyName><ogc:Literal>4</ogc:Literal></ogc:PropertyIsEqualTo>
<ogc:PropertyIsEqualTo><ogc:PropertyName>FID</ogc:PropertyName><ogc:Literal>6</ogc:Literal></ogc:PropertyIsEqualTo>
</ogc:Or></ogc:Filter><se:PointSymbolizer>
<se:Graphic>
<se:Mark>
<se:WellKnownName>square</se:WellKnownName>
<se:Fill>
<se:SvgParameter name="fill">#dc0000</se:SvgParameter>
</se:Fill>
</se:Mark>
<se:Size>1</se:Size>
</se:Graphic>
</se:PointSymbolizer>
</se:Rule>
</se:FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>

24 changes: 24 additions & 0 deletions msautotest/wxs/expected/wms_getstyles_expressions14.xml
@@ -0,0 +1,24 @@
<StyledLayerDescriptor version="1.1.0" xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd" xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:se="http://www.opengis.net/se" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<NamedLayer>
<se:Name>Test14</se:Name>
<UserStyle>
<se:FeatureTypeStyle>
<se:Rule>
<ogc:Filter><ogc:PropertyIsEqualTo><ogc:PropertyName>FID</ogc:PropertyName><ogc:Literal>2</ogc:Literal></ogc:PropertyIsEqualTo>
</ogc:Filter><se:PointSymbolizer>
<se:Graphic>
<se:Mark>
<se:WellKnownName>square</se:WellKnownName>
<se:Fill>
<se:SvgParameter name="fill">#dc0000</se:SvgParameter>
</se:Fill>
</se:Mark>
<se:Size>1</se:Size>
</se:Graphic>
</se:PointSymbolizer>
</se:Rule>
</se:FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>

23 changes: 23 additions & 0 deletions msautotest/wxs/expected/wms_getstyles_expressions15.xml
@@ -0,0 +1,23 @@
<StyledLayerDescriptor version="1.1.0" xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd" xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:se="http://www.opengis.net/se" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<NamedLayer>
<se:Name>Test15</se:Name>
<UserStyle>
<se:FeatureTypeStyle>
<se:Rule>
<se:PointSymbolizer>
<se:Graphic>
<se:Mark>
<se:WellKnownName>square</se:WellKnownName>
<se:Fill>
<se:SvgParameter name="fill">#dc0000</se:SvgParameter>
</se:Fill>
</se:Mark>
<se:Size>1</se:Size>
</se:Graphic>
</se:PointSymbolizer>
</se:Rule>
</se:FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>

25 changes: 25 additions & 0 deletions msautotest/wxs/expected/wms_getstyles_expressions16.xml
@@ -0,0 +1,25 @@
<StyledLayerDescriptor version="1.1.0" xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd" xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:se="http://www.opengis.net/se" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<NamedLayer>
<se:Name>Test16</se:Name>
<UserStyle>
<se:FeatureTypeStyle>
<se:Rule>
<ogc:Filter><ogc:Or><ogc:PropertyIsEqualTo><ogc:PropertyName>locationtype</ogc:PropertyName><ogc:Literal>primary location</ogc:Literal></ogc:PropertyIsEqualTo>
<ogc:PropertyIsEqualTo><ogc:PropertyName>locationtype</ogc:PropertyName><ogc:Literal>secondary location</ogc:Literal></ogc:PropertyIsEqualTo>
</ogc:Or></ogc:Filter><se:PointSymbolizer>
<se:Graphic>
<se:Mark>
<se:WellKnownName>square</se:WellKnownName>
<se:Fill>
<se:SvgParameter name="fill">#dc0000</se:SvgParameter>
</se:Fill>
</se:Mark>
<se:Size>1</se:Size>
</se:Graphic>
</se:PointSymbolizer>
</se:Rule>
</se:FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>

25 changes: 25 additions & 0 deletions msautotest/wxs/expected/wms_getstyles_expressions17.xml
@@ -0,0 +1,25 @@
<StyledLayerDescriptor version="1.1.0" xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd" xmlns="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc" xmlns:se="http://www.opengis.net/se" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<NamedLayer>
<se:Name>Test17</se:Name>
<UserStyle>
<se:FeatureTypeStyle>
<se:Rule>
<ogc:Filter><ogc:Or><ogc:PropertyIsEqualTo><ogc:PropertyName>poi</ogc:PropertyName><ogc:Literal>"main" square</ogc:Literal></ogc:PropertyIsEqualTo>
<ogc:PropertyIsEqualTo><ogc:PropertyName>poi</ogc:PropertyName><ogc:Literal>city's centre</ogc:Literal></ogc:PropertyIsEqualTo>
</ogc:Or></ogc:Filter><se:PointSymbolizer>
<se:Graphic>
<se:Mark>
<se:WellKnownName>square</se:WellKnownName>
<se:Fill>
<se:SvgParameter name="fill">#dc0000</se:SvgParameter>
</se:Fill>
</se:Mark>
<se:Size>1</se:Size>
</se:Graphic>
</se:PointSymbolizer>
</se:Rule>
</se:FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>

75 changes: 75 additions & 0 deletions msautotest/wxs/wms_styles_expressions.map
Expand Up @@ -17,6 +17,11 @@
# RUN_PARMS: wms_getstyles_expressions10.xml [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetStyles&layers=Test10" > [RESULT_DEMIME]
# RUN_PARMS: wms_getstyles_expressions11.xml [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetStyles&layers=Test11" > [RESULT_DEMIME]
# RUN_PARMS: wms_getstyles_expressions12.xml [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetStyles&layers=Test12" > [RESULT_DEMIME]
# RUN_PARMS: wms_getstyles_expressions13.xml [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetStyles&layers=Test13" > [RESULT_DEMIME]
# RUN_PARMS: wms_getstyles_expressions14.xml [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetStyles&layers=Test14" > [RESULT_DEMIME]
# RUN_PARMS: wms_getstyles_expressions15.xml [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetStyles&layers=Test15" > [RESULT_DEMIME]
# RUN_PARMS: wms_getstyles_expressions16.xml [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetStyles&layers=Test16" > [RESULT_DEMIME]
# RUN_PARMS: wms_getstyles_expressions17.xml [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetStyles&layers=Test17" > [RESULT_DEMIME]

MAP
NAME WMS_TEST
Expand Down Expand Up @@ -172,4 +177,74 @@ MAP
END
END
END

# list expression
LAYER
NAME "Test13"
TYPE POINT
CLASSITEM "FID"
CLASS
EXPRESSION {2,4,6}
STYLE
COLOR 220 0 0
WIDTH 1
END
END
END

# list expression with one value
LAYER
NAME "Test14"
TYPE POINT
CLASSITEM "FID"
CLASS
EXPRESSION {2}
STYLE
COLOR 220 0 0
WIDTH 1
END
END
END

# empty list expression
LAYER
NAME "Test15"
TYPE POINT
CLASSITEM "FID"
CLASS
EXPRESSION {}
STYLE
COLOR 220 0 0
WIDTH 1
END
END
END

# string list expression
LAYER
NAME "Test16"
TYPE POINT
CLASSITEM "locationtype"
CLASS
EXPRESSION {primary location,secondary location}
STYLE
COLOR 220 0 0
WIDTH 1
END
END
END

# string list expression with quotes
LAYER
NAME "Test17"
TYPE POINT
CLASSITEM "poi"
CLASS
EXPRESSION {"main" square,city's centre}
STYLE
COLOR 220 0 0
WIDTH 1
END
END
END
END

0 comments on commit 117c2ee

Please sign in to comment.