Skip to content
Permalink
Browse files
Add RENDERMODE PROCESSING directive to use SLD rendering in Mapfiles
  • Loading branch information
jbo-ads committed Feb 25, 2020
1 parent c3449ac commit 857a1384518fcae279396abc8370d34350768a8f
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
@@ -1013,6 +1013,40 @@ int msDrawVectorLayer(mapObj *map, layerObj *layer, imageObj *image)
if(layer->minfeaturesize > 0)
minfeaturesize = Pix2LayerGeoref(map, layer, layer->minfeaturesize);

// Select how to render classes
// MS_FIRST_MATCHING_CLASS: Default and historic MapServer behavior
// MS_ALL_MATCHING_CLASSES: SLD behavior
int ref_rendermode;
char * rendermodestr = msLayerGetProcessingKey(layer, "RENDERMODE");
if (layer->rendermode == MS_ALL_MATCHING_CLASSES)
{
// SLD takes precedence
ref_rendermode = MS_ALL_MATCHING_CLASSES;
}
else if (!rendermodestr)
{
// Default Mapfile
ref_rendermode = MS_FIRST_MATCHING_CLASS;
}
else if (!strcmp(rendermodestr,"FIRST_MATCHING_CLASS"))
{
// Explicit default Mapfile
ref_rendermode = MS_FIRST_MATCHING_CLASS;
}
else if (!strcmp(rendermodestr,"ALL_MATCHING_CLASSES"))
{
// SLD-like Mapfile
ref_rendermode = MS_ALL_MATCHING_CLASSES;
}
else
{
msLayerClose(layer);
msSetError(MS_MISCERR,
"Unknown RENDERMODE: %s, should be one of: FIRST_MATCHING_CLASS, ALL_MATCHING_CLASSES.",
"msDrawVectorLayer()",
rendermodestr);
return MS_FAILURE;
}

/* step through the target shapes and their classes */
msInitShape(&shape);
@@ -1046,7 +1080,7 @@ int msDrawVectorLayer(mapObj *map, layerObj *layer, imageObj *image)
// i.e. only the first applicable class is actually applied. As a consequence,
// cache can be enabled when relevant.
classcount++;
rendermode = layer->rendermode;
rendermode = ref_rendermode;
if ((classcount == 1) && (msShapeGetNextClass(classindex, layer, map, &shape, classgroup, nclasses) == -1))
{
rendermode = MS_FIRST_MATCHING_CLASS;
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -3,6 +3,8 @@
#
# RUN_PARMS: map_painter_reference.png [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WMS&VERSION=1.3&REQUEST=GetMap&CRS=EPSG:4326&BBOX=42,-5,52,9&FORMAT=image/png&WIDTH=800&HEIGHT=800&LAYERS=multipolygon" > [RESULT_DEMIME]
#
# RUN_PARMS: map_sldlike_painter_reference.png [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WMS&VERSION=1.3&REQUEST=GetMap&CRS=EPSG:4326&BBOX=42,-5,52,9&FORMAT=image/png&WIDTH=800&HEIGHT=800&LAYERS=sldlike_multipolygon" > [RESULT_DEMIME]
#
# RUN_PARMS: sld_painter_reference.png [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WMS&VERSION=1.3&REQUEST=GetMap&CRS=EPSG:4326&BBOX=42,-5,52,9&FORMAT=image/png&WIDTH=800&HEIGHT=800&LAYERS=multipolygon&SLD_BODY=<StyledLayerDescriptor version=%221.1.0%22><NamedLayer><se:Name>multipolygon</se:Name><UserStyle><se:FeatureTypeStyle><se:Rule><se:Name>all_green</se:Name><se:PolygonSymbolizer><se:Fill><se:SvgParameter name=%22fill%22>#00ff00</se:SvgParameter></se:Fill><se:Stroke><se:SvgParameter name=%22stroke%22>#ffff00</se:SvgParameter><se:SvgParameter name=%22stroke-width%22>5.00</se:SvgParameter></se:Stroke></se:PolygonSymbolizer></se:Rule><se:Rule><se:Name>red_3_5</se:Name><ogc:Filter><ogc:And><ogc:PropertyIsLessThanOrEqualTo><ogc:PropertyName>N_EDGES</ogc:PropertyName><ogc:Literal>5</ogc:Literal></ogc:PropertyIsLessThanOrEqualTo><ogc:PropertyIsGreaterThanOrEqualTo><ogc:PropertyName>N_EDGES</ogc:PropertyName><ogc:Literal>3</ogc:Literal></ogc:PropertyIsGreaterThanOrEqualTo></ogc:And></ogc:Filter><se:PolygonSymbolizer><se:Fill><se:SvgParameter name=%22fill%22>#ff0000</se:SvgParameter></se:Fill><se:Stroke><se:SvgParameter name=%22stroke%22>#ffff00</se:SvgParameter><se:SvgParameter name=%22stroke-width%22>5.00</se:SvgParameter></se:Stroke></se:PolygonSymbolizer></se:Rule><se:Rule><se:Name>blue_quadrilateral</se:Name><ogc:Filter><ogc:PropertyIsEqualTo><ogc:PropertyName>N_EDGES</ogc:PropertyName><ogc:Literal>4</ogc:Literal></ogc:PropertyIsEqualTo></ogc:Filter><se:PolygonSymbolizer><se:Fill><se:SvgParameter name=%22fill%22>#0000ff</se:SvgParameter></se:Fill><se:Stroke><se:SvgParameter name=%22stroke%22>#ffff00</se:SvgParameter><se:SvgParameter name=%22stroke-width%22>5.00</se:SvgParameter></se:Stroke></se:PolygonSymbolizer></se:Rule></se:FeatureTypeStyle></UserStyle></NamedLayer></StyledLayerDescriptor>" > [RESULT_DEMIME]
#

@@ -66,4 +68,40 @@ MAP
END
END

LAYER
TYPE POLYGON
NAME sldlike_multipolygon
PROCESSING "RENDERMODE=ALL_MATCHING_CLASSES"
CONNECTIONTYPE OGR
CONNECTION data/set.json
STATUS ON
SIZEUNITS pixels
CLASS
NAME all_green
STYLE
WIDTH 5
OUTLINECOLOR 255 255 0
COLOR 0 255 0
END
END
CLASS
NAME red_3_5
EXPRESSION ([N_EDGES] >= 3 and [N_EDGES] <= 5)
STYLE
WIDTH 5
OUTLINECOLOR 255 255 0
COLOR 255 0 0
END
END
CLASS
NAME blue_quadrilateral
EXPRESSION ([N_EDGES] == 4)
STYLE
WIDTH 5
OUTLINECOLOR 255 255 0
COLOR 0 0 255
END
END
END

END

0 comments on commit 857a138

Please sign in to comment.