Skip to content

Commit

Permalink
SLD generation: write UserStyle.Name from CLASS.GROUP (one UserStyle …
Browse files Browse the repository at this point in the history
…per class that share the same CLASS.GROUP) and UserStyle.IsDefault from LAYER.CLASSGROUP
  • Loading branch information
rouault committed Oct 24, 2019
1 parent 2107829 commit 6dbece4
Show file tree
Hide file tree
Showing 16 changed files with 370 additions and 18 deletions.
62 changes: 60 additions & 2 deletions mapogcsld.c
Original file line number Diff line number Diff line change
Expand Up @@ -4145,12 +4145,25 @@ static void msSLDAppendName(msStringBuffer* sb, const char* pszName, int nVersio
msFree(pszEncoded);
}

static void msSLDGenerateUserStyle(msStringBuffer* sb, layerObj *psLayer, int nVersion)
static void msSLDGenerateUserStyle(msStringBuffer* sb, layerObj *psLayer, int nVersion,
const char* pszTargetGroup)
{
const char* pszWfsFilter;

msStringBufferAppend(sb, "<UserStyle>\n");

if( pszTargetGroup )
{
msSLDAppendName(sb, pszTargetGroup, nVersion);
if( psLayer->classgroup &&
strcmp(psLayer->classgroup, pszTargetGroup) == 0 )
{
msStringBufferAppend(sb, nVersion > OWS_1_0_0 ?
"<se:IsDefault>true</se:IsDefault>\n" :
"<IsDefault>true</IsDefault>\n");
}
}

msStringBufferAppend(sb, nVersion > OWS_1_0_0 ?
"<se:FeatureTypeStyle>\n" : "<FeatureTypeStyle>\n");

Expand All @@ -4161,6 +4174,20 @@ static void msSLDGenerateUserStyle(msStringBuffer* sb, layerObj *psLayer, int nV
char* pszFilter;
double dfMinScale =-1, dfMaxScale = -1;

/* Only write down classes that match the group of interest */
if( psLayer->class[i]->group )
{
if( pszTargetGroup == NULL ||
strcmp(psLayer->class[i]->group, pszTargetGroup) != 0 )
{
continue;
}
}
else if( pszTargetGroup != NULL )
{
continue;
}

msStringBufferAppend(sb, nVersion > OWS_1_0_0 ? "<se:Rule>\n" : "<Rule>\n" );

/* if class has a name, use it as the RULE name */
Expand Down Expand Up @@ -4298,6 +4325,33 @@ char *msSLDGenerateSLDLayer(layerObj *psLayer, int nVersion)
psLayer->type == MS_LAYER_LINE ||
psLayer->type == MS_LAYER_POLYGON )) {

int i;
int numClassGroupNames = 0;
char** papszClassGroupNames =
(char**) msSmallMalloc(sizeof(char*) * psLayer->numclasses);
for (i=0; i<psLayer->numclasses; i++) {
const char* group = psLayer->class[i]->group;
int j;
for( j = 0; j < numClassGroupNames; j++ )
{
if( group == NULL )
{
if( papszClassGroupNames[j] == NULL )
break;
}
else if( papszClassGroupNames[j] != NULL &&
strcmp(papszClassGroupNames[j], group) == 0 )
{
break;
}
}
if( j >= numClassGroupNames )
{
papszClassGroupNames[numClassGroupNames] = group ? msStrdup(group) : NULL;
numClassGroupNames ++;
}
}

msStringBufferAppend(sb, "<NamedLayer>\n");

pszWMSLayerName = msOWSLookupMetadata(&(psLayer->metadata), "MO", "name");
Expand All @@ -4307,7 +4361,11 @@ char *msSLDGenerateSLDLayer(layerObj *psLayer, int nVersion)
"NamedLayer",
nVersion);

msSLDGenerateUserStyle(sb, psLayer, nVersion);
for (i=0; i<numClassGroupNames; i++) {
msSLDGenerateUserStyle(sb, psLayer, nVersion, papszClassGroupNames[i]);
msFree(papszClassGroupNames[i]);
}
msFree(papszClassGroupNames);

msStringBufferAppend(sb, "</NamedLayer>\n");
}
Expand Down
46 changes: 46 additions & 0 deletions msautotest/sld/expected/sld_named_userstyle_get_styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
Content-Type: application/vnd.ogc.sld+xml; charset=UTF-8

<StyledLayerDescriptor version="1.0.0" xmlns="http://www.opengis.net/sld" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd">
<NamedLayer>
<Name>lline</Name>
<UserStyle>
<Name>red_and_blue</Name>
<IsDefault>true<IsDefault>
<FeatureTypeStyle>
<Rule>
<LineSymbolizer>
<Stroke>
<CssParameter name="stroke">#ff0000</CssParameter>
<CssParameter name="stroke-opacity">0.50</CssParameter>
<CssParameter name="stroke-width">5.00</CssParameter>
</Stroke>
</LineSymbolizer>
</Rule>
<Rule>
<LineSymbolizer>
<Stroke>
<CssParameter name="stroke">#0000ff</CssParameter>
<CssParameter name="stroke-opacity">0.50</CssParameter>
<CssParameter name="stroke-width">3.00</CssParameter>
</Stroke>
</LineSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
<UserStyle>
<Name>green</Name>
<FeatureTypeStyle>
<Rule>
<LineSymbolizer>
<Stroke>
<CssParameter name="stroke">#00ff00</CssParameter>
<CssParameter name="stroke-opacity">0.50</CssParameter>
<CssParameter name="stroke-width">5.00</CssParameter>
</Stroke>
</LineSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>

63 changes: 63 additions & 0 deletions msautotest/sld/sld_named_userstyle_get_styles.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#
# REQUIRES: INPUT=GDAL OUTPUT=PNG SUPPORTS=WMS

# GetStyles
# RUN_PARMS: sld_named_userstyle_get_styles.xml [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetStyles&LAYERS=lline" > [RESULT]

MAP

NAME TEST
SHAPEPATH ./data
SIZE 300 300
IMAGECOLOR 100 100 100
FONTSET "data/fonts.lst"
PROJECTION
"init=epsg:4326"
END
WEB
IMAGEPATH "/tmp/ms_tmp/"
IMAGEURL "/ms_tmp/"
METADATA
"wms_title" "Test SLD"
"wms_onlineresource" "http://localhost/path/to/wms_simple?"
"wms_srs" "EPSG:4326"
"ows_schemas_location" "http://schemas.opengis.net"
"ows_enable_request" "*"
"ows_sld_enabled" "true"
END
END

LAYER
NAME lline
DATA hexagon
TYPE LINE
STATUS ON
SIZEUNITS pixels
CLASSGROUP "red_and_blue"
CLASS
GROUP "red_and_blue"
STYLE
WIDTH 5
OPACITY 50
COLOR 255 0 0
END
END
CLASS
GROUP "red_and_blue"
STYLE
WIDTH 3
OPACITY 50
COLOR 0 0 255
END
END
CLASS
GROUP "green"
STYLE
WIDTH 5
OPACITY 50
COLOR 0 255 0
END
END
END

END
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<NamedLayer>
<se:Name>TN.AirTransportNetwork.AirLink</se:Name>
<UserStyle>
<se:Name>inspire_common:DEFAULT</se:Name>
<se:IsDefault>true</se:IsDefault>
<se:FeatureTypeStyle>
<se:Rule>
<se:Name>myclass4</se:Name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<NamedLayer>
<se:Name>TN.RoadTransportNetwork.RoadLink</se:Name>
<UserStyle>
<se:Name>inspire_common:DEFAULT</se:Name>
<se:IsDefault>true</se:IsDefault>
<se:FeatureTypeStyle>
<se:Rule>
<se:Name>myclass1</se:Name>
Expand Down Expand Up @@ -29,6 +31,8 @@
<NamedLayer>
<se:Name>TN.RailTransportNetwork.RailwayLink</se:Name>
<UserStyle>
<se:Name>inspire_common:DEFAULT</se:Name>
<se:IsDefault>true</se:IsDefault>
<se:FeatureTypeStyle>
<se:Rule>
<se:Name>myclass3</se:Name>
Expand All @@ -46,6 +50,8 @@
<NamedLayer>
<se:Name>TN.AirTransportNetwork.AirLink</se:Name>
<UserStyle>
<se:Name>inspire_common:DEFAULT</se:Name>
<se:IsDefault>true</se:IsDefault>
<se:FeatureTypeStyle>
<se:Rule>
<se:Name>myclass4</se:Name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<NamedLayer>
<se:Name>TN.RoadTransportNetwork.RoadLink</se:Name>
<UserStyle>
<se:Name>inspire_common:DEFAULT</se:Name>
<se:IsDefault>true</se:IsDefault>
<se:FeatureTypeStyle>
<se:Rule>
<se:Name>myclass1</se:Name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<NamedLayer>
<se:Name>TN.RailTransportNetwork.RailwayLink</se:Name>
<UserStyle>
<se:Name>inspire_common:DEFAULT</se:Name>
<se:IsDefault>true</se:IsDefault>
<se:FeatureTypeStyle>
<se:Rule>
<se:Name>myclass3</se:Name>
Expand All @@ -19,6 +21,8 @@
<NamedLayer>
<se:Name>TN.AirTransportNetwork.AirLink</se:Name>
<UserStyle>
<se:Name>inspire_common:DEFAULT</se:Name>
<se:IsDefault>true</se:IsDefault>
<se:FeatureTypeStyle>
<se:Rule>
<se:Name>myclass4</se:Name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<NamedLayer>
<se:Name>TN.AirTransportNetwork.AirLink</se:Name>
<UserStyle>
<se:Name>inspire_common:DEFAULT</se:Name>
<se:IsDefault>true</se:IsDefault>
<se:FeatureTypeStyle>
<se:Rule>
<se:Name>myclass4</se:Name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<NamedLayer>
<se:Name>TN.RoadTransportNetwork.RoadLink</se:Name>
<UserStyle>
<se:Name>inspire_common:DEFAULT</se:Name>
<se:IsDefault>true</se:IsDefault>
<se:FeatureTypeStyle>
<se:Rule>
<se:Name>myclass1</se:Name>
Expand Down Expand Up @@ -29,6 +31,8 @@
<NamedLayer>
<se:Name>TN.RailTransportNetwork.RailwayLink</se:Name>
<UserStyle>
<se:Name>inspire_common:DEFAULT</se:Name>
<se:IsDefault>true</se:IsDefault>
<se:FeatureTypeStyle>
<se:Rule>
<se:Name>myclass3</se:Name>
Expand All @@ -46,6 +50,8 @@
<NamedLayer>
<se:Name>TN.AirTransportNetwork.AirLink</se:Name>
<UserStyle>
<se:Name>inspire_common:DEFAULT</se:Name>
<se:IsDefault>true</se:IsDefault>
<se:FeatureTypeStyle>
<se:Rule>
<se:Name>myclass4</se:Name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<NamedLayer>
<se:Name>TN.RoadTransportNetwork.RoadLink</se:Name>
<UserStyle>
<se:Name>inspire_common:DEFAULT</se:Name>
<se:IsDefault>true</se:IsDefault>
<se:FeatureTypeStyle>
<se:Rule>
<se:Name>myclass1</se:Name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<NamedLayer>
<se:Name>TN.RailTransportNetwork.RailwayLink</se:Name>
<UserStyle>
<se:Name>inspire_common:DEFAULT</se:Name>
<se:IsDefault>true</se:IsDefault>
<se:FeatureTypeStyle>
<se:Rule>
<se:Name>myclass3</se:Name>
Expand All @@ -19,6 +21,8 @@
<NamedLayer>
<se:Name>TN.AirTransportNetwork.AirLink</se:Name>
<UserStyle>
<se:Name>inspire_common:DEFAULT</se:Name>
<se:IsDefault>true</se:IsDefault>
<se:FeatureTypeStyle>
<se:Rule>
<se:Name>myclass4</se:Name>
Expand Down

0 comments on commit 6dbece4

Please sign in to comment.