.. _sld_reference_labeling: Labeling ======== Controlling Label Placement --------------------------- Controlling where the WMS server places labels with SLD is bit complex. The SLD specification only defines the most basic way of controlling placement explicitly 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 Placement ------------------- The SLD specification indicates two types of LabelPlacement: * for Point Geometries ("PointPlacement") * for Linear (line) geometries ("LinePlacement") .. note:: Relative to Where? See below for the actual algorithm details, but: * Polygons are intersected with the viewport and the centroid is used. * Lines are intersected with the viewport and the middle of the line is used. Code ```` .. code-block:: xml ... PointPlacement -------------- When you use a 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: .. list-table:: :widths: 30 70 * - **Option** - **Meaning** (Name) * - AnchorPoint - This is relative to the LABEL. Using this you can do things such as center the label on top of the point, have the label to the left of the point, or have the label centered under the point. * - Displacement - This is in PIXELS and lets you fine-tune the location of the label. * - Rotation - This is the clockwise rotation of the label in degrees. The best way to understand these is with examples: AnchorPoint ``````````` The 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. .. figure:: img/label_bbox.gif :align: center The anchor point is defined relative to the label's bounding box. The bottom left is (0,0), the top left is (1,1), and the middle is (0.5,0.5). .. code-block:: xml 0.5 0.5 By changing the values, you can control where the label is placed. .. figure:: img/point_x0y0_5.gif (x=0,y=0.5) DEFAULT - place the label to the right of the label point .. figure:: img/point_x0_5y0_5.gif (x=0.5,y=0.5) - place the centre of the label at the label point .. figure:: img/point_x15y0_5.gif (x=1,y=0.5) - place the label to the left of the label point .. figure:: img/point_x0_5y0.gif (x=0.5,y=0) - place the label centered above the label point Displacement ```````````` Displacement 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. .. code-block:: xml 10 0 .. figure:: img/point_x0y0_5_displacex10.gif :align: center displacement of x=10 pixels, compare with anchor point (x=0,y=0.5) above .. figure:: img/point_x0y1_displacey10.gif :align: center displacement of y=-10 pixels, compare with anchor point (x=0.5,y=1.0) not shown Rotation ```````` Rotation 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. .. code-block:: xml 45 .. figure:: img/rot1.gif simple 45 degrees rotation .. figure:: img/rot2.gif 45 degrees rotation with anchor point (x=0.5,y=0.5) .. figure:: img/rot3.gif 45 degrees with 40 pixel X displacement .. figure:: img/rot4.gif 45 degrees rotation with 40 pixel Y displacement with anchor point (x=0.5,y=0.5) LinePlacement ````````````` When you are labeling a line (i.e. a road or river), you can specify a element. This tells the labeling system two things: (a) that you want Geoserver to determine the best rotation and placement for the label (b) a minor option to control how the label is placed relative to the line. The line placement option is very simple - it only allows you to move a label up-and-down from a line. .. code-block:: xml ... This is very similiar to the DisplacementY option (see above). .. code-block:: xml 10 .. figure:: img/lp_1.gif PerpendicularOffset=0 .. figure:: img/lp_2.gif PerpendicularOffset=10 pixels Composing labels from multiple attributes ````````````````````````````````````````` The