5. Defining Styles

Style definition for the deegree WMS will be done by creating one or more Styled Layer Descriptor (SLD) documents and assigning the UserStyles defined within it to one or more layers of the WMS. An SLD document that can be used for deegree WMS style definitions is valid against the OGC SLD 1.0.0 specification and defines one single 'NamedLayer'. The name of the <NamedLayer> element can be chosen freely and won't be evaluated currently. Within the <NamedLayer> element the user may define as many <UserStyle> elements as he likes. For better clarity we recommend to use more then one SLD document if the WMS offers a great amount of layers. The name of the 'UserStyles' corresponds with the name of the styles that can be assigned to a layer within the WMS configuration file described above.

The following extract shows an example of of a SLD

<?xml version="1.0" encoding="UTF-8"?>
	<StyledLayerDescriptor version="String" 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">
	<NamedLayer>
		<Name>osnabrueck style definition</Name>
		<!-- ================= -->
		<!-- waterpolygone -->
		<!-- ================= -->
		<UserStyle>
			<Name>default:osnabrueck:gewaessepoly</Name>
			<Title>OS_GewPoly</Title>
			<IsDefault>1</IsDefault>
			<FeatureTypeStyle>
				<Name>OS_GewPolyStyle</Name>
				<Rule>
					<Name>OS_GewPoly</Name>
					<MinScaleDenominator>0</MinScaleDenominator>
					<MaxScaleDenominator>999999999</MaxScaleDenominator>
					<PolygonSymbolizer>
						<Geometry>
							<ogc:PropertyName>GEOM</ogc:PropertyName>
						</Geometry>
						<Fill>
							<CssParameter name="fill">#3333FF</CssParameter>
							<CssParameter name="fill-opacity">0.3</CssParameter>
						</Fill>
						<Stroke>
							<CssParameter name="stroke">#0000FF</CssParameter>
							<CssParameter name="stroke-opacity">1.0</CssParameter>
							<CssParameter name="stroke-width">1.0</CssParameter>
							<CssParameter name="stroke-dasharray">1</CssParameter>
						</Stroke>
					</PolygonSymbolizer>
				</Rule>
			</FeatureTypeStyle>
		</UserStyle>
		<UserStyle>
			<Name>BlueFill</Name>
			<Title>BlueFill</Title>
			<IsDefault>1</IsDefault>
			<FeatureTypeStyle>
				<Name>BlueFill</Name>
				<Rule>
					<Name>BlueFill</Name>
					<MinScaleDenominator>0</MinScaleDenominator>
					<MaxScaleDenominator>999999999</MaxScaleDenominator>
					<PolygonSymbolizer>
						<Geometry>
							<ogc:PropertyName>GEOM</ogc:PropertyName>
						</Geometry>
						<Fill>
							<CssParameter name="fill">#0000FF</CssParameter>
							<CssParameter name="fill-opacity">1</CssParameter>
						</Fill>
						<Stroke>
							<CssParameter name="stroke">#000000</CssParameter>
							<CssParameter name="stroke-opacity">1.0</CssParameter>
							<CssParameter name="stroke-width">1.0</CssParameter>
							<CssParameter name="stroke-dasharray">1</CssParameter>
						</Stroke>
					</PolygonSymbolizer>
				</Rule>
			</FeatureTypeStyle>
		</UserStyle>

For a detailed description of defining a Styled Layer Descriptor document please have a look at the OGC SLD 1.0.0 specification. Deegree supports most forms of style definition except for raster data (RasterSymbolizer).

One additional feature of the deegree WMS in context of defining styles that has been mentioned before is its capability of using an individual default style for each layer. To realize this for each layer a <UserStyle> must be defined that have a name starting with 'default:' followed by the layer’s name (e.g. default:osnabrueck:gewaessepoly is the default style for the layer osnabrueck:gewaessepoly; see SLD fragment above). So if the default style is defined in a GetMap request the individual default style will be selected. If you don't define an individual default style 50% gray for fills and 1 pixel thick black lines will be used.

5.1. Label placement

The deegree WMS supports the automatic and optimized placement of labels for points and polygons (linestring label placement isn't supported yet but will follow soon). To force an automatic label placement an additional attribute have to be used at the <PointPlacement> element of the <TextSymbolizer>

		<UserStyle>
			<Name>default:europe:urban_places_label</Name>
			<Title>urban_places_label</Title>
			<IsDefault>1</IsDefault>
			<FeatureTypeStyle>
				<Name>MyFeatureTypeStyle098</Name>
				<Rule>
					<Name>urban_Text</Name>
					<MinScaleDenominator>0</MinScaleDenominator>
					<MaxScaleDenominator>3000000</MaxScaleDenominator>
					<TextSymbolizer>
						<Geometry>
							<ogc:PropertyName>GEOM</ogc:PropertyName>
						</Geometry>
						<Label>
							<ogc:PropertyName>NAME</ogc:PropertyName>
						</Label>
						<Font>
							<CssParameter name="font-family">Arial</CssParameter>
							<CssParameter name="font-family">Sans-Serif</CssParameter>
							<CssParameter name="font-style">italic</CssParameter>
							<CssParameter name="font-size">10</CssParameter>
							<CssParameter name="font-color">#222222</CssParameter>
						</Font>
						<LabelPlacement>
							<PointPlacement auto="true"/>
						</LabelPlacement>
						<Halo>
							<Fill>
								<CssParameter name="fill">#00FFFF</CssParameter>
								<CssParameter name="fill-opacity">0.8</CssParameter>
							</Fill>
						</Halo>
					</TextSymbolizer>
				</Rule>
			</FeatureTypeStyle>
	</UserStyle>

The <UserStyle> given above defines a label for the geometry of a feature named 'GEOM'. The label will print the content of the features 'NAME' property (consider that property names have to be in uppercase). The geometry can be a point, a polygon or a multi-polygon. As <LabelPlacement> <PointPlacement> is chosen so the label is related to a point which is the point geometry by itself or the centroid of the visible part of a polygon. It has an additional attribute named 'auto' not defined in the SLD specification that forces a label placement optimization if it is set to 'true'. If it is missing or set to 'false' no optimization will be done and the user is free to fix the position of the labels by its own definitions (see SLD specifications how to do this).

Labelplacement for Linestrings is a little bit different, but not much:

<Rule>
	<Name>OS_Strassen_ALT_Name</Name>
	<MinScaleDenominator>0</MinScaleDenominator>
	<MaxScaleDenominator>10000</MaxScaleDenominator>
	<TextSymbolizer>
		<Geometry>
			<ogc:PropertyName>GEOM</ogc:PropertyName>
		</Geometry>
		<Label>
			<ogc:PropertyName>STRNAME</ogc:PropertyName>
		</Label>
		<Font>
			<CssParameter name="font-family">Serif</CssParameter>
			<CssParameter name="font-style">normal</CssParameter>
			<CssParameter name="font-weight">normal</CssParameter>
			<CssParameter name="font-size">12</CssParameter>
			<CssParameter name="font-color">#000000</CssParameter>
		</Font>
		<LabelPlacement>
			<LinePlacement>
				<PerpendicularOffset>above</PerpendicularOffset>
				<!-- width of the line the label is associated with -->
				<LineWidth>2.5</LineWidth>
				<!-- gap between labels measured in label width -->
				<Gap>5</Gap>
			</LinePlacement>
		</LabelPlacement>
	</TextSymbolizer>
</Rule>

Instead of the Element <PointPlacement> <LinePlacement> will be used. At the moment LinePlacement don't support automatical label placement optimization but using the three elements contained in the <LinePlacement> element you already can realize good results. The <PerpendicularOffset> defines the relative position of the label according to the line. You can use a number as defined in the SLD specifications or set a predefined value (above, below, center). If you use one of predefined values it is usefull to set a value for <LineWidth> to ensure that if you choose 'above' the label will be really above the line and not partially within it.

Using the <Gap> element you can determine the gap between the labels of one Linestring. The value of <Gap> is measured in the length of the label string. This means if a river shall be labeled with 'Rhine' one gap will have the length of the string 'Rhine'. The labeling will look like this Rhine Rhine Rhine. If you choose <Gap>0</Gap> you will get a labelling like this Rhine Rhine Rhine Rhine Rhine.