$webwork.htmlEncode($page.space.name) : LabelingOptions
This page last changed on Nov 29, 2005 by dblasby.
Controlling Label PlacementControlling where the WMS server places labels with SLD is bit complex. The SLD specification only defines the most basic way of controlling placement explictly says that defining more control is "a real can of worms". Geoserver fully supports the SLD specification plus adds a few extra parameters so you can make pretty maps.
Basic SLD PlacementThe SLD specification indicates two types of LabelPlacement:
<xsd:element name="PointPlacement"> <xsd:complexType> <xsd:sequence> <xsd:element ref="sld:AnchorPoint" minOccurs="0"/> <xsd:element ref="sld:Displacement" minOccurs="0"/> <xsd:element ref="sld:Rotation" minOccurs="0"/> </xsd:sequence> </xsd:complexType> </xsd:element> ... <xsd:element name="LinePlacement"> <xsd:complexType> <xsd:sequence> <xsd:element ref="sld:PerpendicularOffset" minOccurs="0"/> </xsd:sequence> </xsd:complexType> </xsd:element> PointPlacementWhen you use a <PointPlacement> element, the geometry you are labeling will be reduced to a single point (usually the "middle" of the geometry - see algorithm below for details). You can control where the label is relative to this point using the options:
The best way to understand these is with examples: AnchorPointThe anchor point determines where the label is placed relative to the label point. These measurements are relative to the bounding box of the label. The (x,y) location inside the label's bounding box (specified by the AnchorPoint) is placed at the label point.
<PointPlacement> <AnchorPoint> <AnchorPointX> 0.5 </AnchorPointX> <AnchorPointY> 0.5 </AnchorPointY> </AnchorPoint> </PointPlacement> By changing the values, you can control where the label is placed.
DisplacementDisplacement allows fine control of the placement of the label. The displacement values are in pixels and simply move the location of the label on the resulting image. <PointPlacement> <Displacement> <DisplacementX> 10 </DisplacementX> <DisplacementY> 0 </DisplacementY> </Displacement> </PointPlacement>
RotationRotation is simple - it rotates the label clockwise the number of degrees you specify. See the examples below for how it interacts with AnchorPoints and displacements. <Rotation> 45 </Rotation>
LinePlacementWhen you are labeling a line (i.e. a road or river), you can specify a <LinePlacement> element. This tells the labeling system two things: The line placement option is very simple - it only allows you to move a label up-and-down from a line. <xs:elementname="LinePlacement"> <xs:complexType> <xs:sequence> <xs:element ref="sld:PerpendicularOffset" minOccurs="0"/> </xs:sequence> </xs:complexType> </xs:element> ... <xs:element name="PerpendicularOffset" type="sld:ParameterValueType"/> This is very similiar to the DisplacementY option (see above). <LabelPlacement> <LinePlacement> <PerpendicularOffset> 10 </PerpendicularOffset> </LinePlacement> </LabelPlacement>
Summary of SLD optionsGeoserver Specific Enhanced Options
Priority Labeling (<Priority>)Geoserver has extended the standard SLD to also include priority labeling. This allows you to control which labels are rendered in preference to other labels. For example, lets assume you have a dataset like this: City Name | population -------------+------------ Yonkers | 197,818 Jersey City | 237,681 Newark | 280,123 New York | 8,107,916 Most people don't know where "Yonkers" city is, but do know where "New York" city is. On our map, we want to give "New York" priority so its more likely to be labeled when its in conflict (overlapping) "Yonkers".
In our TextSymbolizer we can put an Expression to retreive or calculate the priority for each feature: <Priority> <PropertyName>population</PropertyName> </Priority>
Grouping Geometries (<VendorOption name="group">)Sometime you will have a set of related features that you only want a single label. The grouping option groups all features with the same label text, then finds a representative geometry for the group. Roads datasets are an obvious example - you only want a single label for all of "main street", not a label for every piece of "main street."
<VendorOption name="group">yes</VendorOption>
Overlapping and Separating Labels (<VendorOption name="spaceAround">)By default geoserver will not put labels "on top of each other". By using the spaceAround option you can allow overlaps to overlap and you can also add extra space around a label. <VendorOption name="spaceAround">10</VendorOption>
NOTE: the value you specify (an integer in pixels) actually provides twice the space that you might expect. This is because you can specify a spaceAround for one label as 5, and for another label (in another TextSymbolizer) as 3. The distance between them will be 8. For two labels in the first symbolizer ("5") they will each be 5 pixels apart from each other, for a total of 10 pixels!
Goodness of FitGeoserver will remove labels if they are a particularly bad fit for the geometry they are labeling. Currently, there's no way to easily change this values (MIN_GOODNESS_FIT = 0.7).
Geoserver/Geotools Labeling Algorithm Summary![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
Document generated by Confluence on Jan 16, 2008 23:27 |