#

## OpenGeo Stack Workshop

# Optimizing a Road SLD

The road SLD created in the previous section is lacking of some cartographic features. This section will cover the task of manually optimizing the SLD to add effects such as road outlines and advanced labeling.

1. Navigate to the SLD Editor for the roads_style SLD.

   Editing the roads_style SLD

2. Insert an empty `<FeatureTypeStyle>` element before the existing `<FeatureTypeStyle>` element.

       <FeatureTypeStyle>
       </FeatureTypeStyle>

   Inserting a new FeatureTypeStyle element

   Note

   In an SLD each `<FeatureTypeStyle>` is drawn in order as a separate layer in the order they are encountered in the document. Therefore to correctly implement a road outline multiple `<FeatureTypeStyle>` elements are required, with the outlines occurring first.

3. Inside of the new `<FeatureTypeStyle></FeatureTypeStyle>` element insert the following XML:

       <Rule>
         <Title>Highway 1:700K - 1:180K Outline</Title>
         <ogc:Filter>
           <ogc:PropertyIsEqualTo>
             <ogc:PropertyName>type</ogc:PropertyName>
             <ogc:Literal>highway</ogc:Literal>
           </ogc:PropertyIsEqualTo>
         </ogc:Filter>
         <MinScaleDenominator>181359.0</MinScaleDenominator>
         <MaxScaleDenominator>700000.0</MaxScaleDenominator>
         <LineSymbolizer>
           <Stroke>
             <CssParameter name="stroke">#a9a69e</CssParameter>
             <CssParameter name="stroke-width">2.5</CssParameter>
           </Stroke>
         </LineSymbolizer>
       </Rule>

   Note

   The above style rule adds a dark grey line which is a pixel wider than the associated Highway 1:700K - 1:180K style rule. Because it appears first in the document it will be rendered first and will appear as an outline when the Highway 1:700K - 1:180K is rendered on top of it.

4. After the `<Rule>` element added in the previous step add the following XML:

        <Rule>
         <Title>Highway 1:180K - 1:20K Outline</Title>
         <ogc:Filter>
           <ogc:PropertyIsEqualTo>
             <ogc:PropertyName>type</ogc:PropertyName>
             <ogc:Literal>highway</ogc:Literal>
           </ogc:PropertyIsEqualTo>
         </ogc:Filter>
         <MinScaleDenominator>19329.0</MinScaleDenominator>
         <MaxScaleDenominator>180000.0</MaxScaleDenominator>
         <LineSymbolizer>
           <Stroke>
             <CssParameter name="stroke">#a9a69e</CssParameter>
             <CssParameter name="stroke-width">5.5</CssParameter>
           </Stroke>
         </LineSymbolizer>
       </Rule>

5. Add the following rule after the rule added in the previous step:

       <Rule>
         <Title>Highway 1:20K - 1:5K Outline</Title>
         <ogc:Filter>
           <ogc:PropertyIsEqualTo>
             <ogc:PropertyName>type</ogc:PropertyName>
             <ogc:Literal>highway</ogc:Literal>
           </ogc:PropertyIsEqualTo>
         </ogc:Filter>
         <MinScaleDenominator>5000.0</MinScaleDenominator>
         <MaxScaleDenominator>19329.0</MaxScaleDenominator>
         <LineSymbolizer>
           <Stroke>
             <CssParameter name="stroke">#a9a69e</CssParameter>
             <CssParameter name="stroke-width">9</CssParameter>
           </Stroke>
         </LineSymbolizer>
       </Rule>

6. Add the following rule after the rule added in the previous step:

       <Rule>
          <Title>Highway &lt; 1:5K Outline</Title>
          <ogc:Filter>
            <ogc:PropertyIsEqualTo>
              <ogc:PropertyName>type</ogc:PropertyName>
              <ogc:Literal>highway</ogc:Literal>
            </ogc:PropertyIsEqualTo>
          </ogc:Filter>
          <MaxScaleDenominator>5000.0</MaxScaleDenominator>
          <LineSymbolizer>
            <Stroke>
              <CssParameter name="stroke">#a9a69e</CssParameter>
              <CssParameter name="stroke-width">12</CssParameter>
            </Stroke>
          </LineSymbolizer>
        </Rule>

7. Submit, Apply, and Save changes. Use the Map Preview or Styler to verify the style change.

   Adding road outlines

8. Repeating steps above add a set of outline rules for the primary roads. at approximately line 75.

       <Rule>
         <Title>Primary 1:180K - 1:20K Outline</Title>
         <ogc:Filter>
           <ogc:PropertyIsEqualTo>
             <ogc:PropertyName>type</ogc:PropertyName>
             <ogc:Literal>primary</ogc:Literal>
           </ogc:PropertyIsEqualTo>
         </ogc:Filter>
         <MinScaleDenominator>19329.0</MinScaleDenominator>
         <MaxScaleDenominator>180000.0</MaxScaleDenominator>
         <LineSymbolizer>
           <Stroke>
             <CssParameter name="stroke">#a9a69e</CssParameter>
             <CssParameter name="stroke-width">2.5</CssParameter>
           </Stroke>
         </LineSymbolizer>
       </Rule>
       <Rule>
         <Title>Primary 1:20K - 1:5K Outline</Title>
         <ogc:Filter>
           <ogc:PropertyIsEqualTo>
             <ogc:PropertyName>type</ogc:PropertyName>
             <ogc:Literal>primary</ogc:Literal>
           </ogc:PropertyIsEqualTo>
         </ogc:Filter>
         <MinScaleDenominator>5000.0</MinScaleDenominator>
         <MaxScaleDenominator>19329.0</MaxScaleDenominator>
         <LineSymbolizer>
           <Stroke>
             <CssParameter name="stroke">#a9a69e</CssParameter>
             <CssParameter name="stroke-width">5</CssParameter>
           </Stroke>
         </LineSymbolizer>
       </Rule>
       <Rule>
         <Title>Primary &lt; 1:5K Outline</Title>
         <ogc:Filter>
           <ogc:PropertyIsEqualTo>
             <ogc:PropertyName>type</ogc:PropertyName>
             <ogc:Literal>primary</ogc:Literal>
           </ogc:PropertyIsEqualTo>
         </ogc:Filter>
         <MaxScaleDenominator>5000.0</MaxScaleDenominator>
         <LineSymbolizer>
           <Stroke>
             <CssParameter name="stroke">#a9a69e</CssParameter>
             <CssParameter name="stroke-width">9</CssParameter>
           </Stroke>
         </LineSymbolizer>
       </Rule>

9. Repeating steps above add a set of outline rules for the secondary roads.

       <Rule>
         <Title>Secondary 1:20K - 1:5K Outline</Title>
         <ogc:Filter>
           <ogc:PropertyIsEqualTo>
             <ogc:PropertyName>type</ogc:PropertyName>
             <ogc:Literal>secondary</ogc:Literal>
           </ogc:PropertyIsEqualTo>
         </ogc:Filter>
         <MinScaleDenominator>5000.0</MinScaleDenominator>
         <MaxScaleDenominator>19329.0</MaxScaleDenominator>
         <LineSymbolizer>
           <Stroke>
             <CssParameter name="stroke">#a9a69e </CssParameter>
             <CssParameter name="stroke-width">5</CssParameter>
           </Stroke>
         </LineSymbolizer>
       </Rule>
       <Rule>
         <Title>Secondary &lt; 1:5K Outline</Title>
         <ogc:Filter>
           <ogc:PropertyIsEqualTo>
             <ogc:PropertyName>type</ogc:PropertyName>
             <ogc:Literal>secondary</ogc:Literal>
           </ogc:PropertyIsEqualTo>
         </ogc:Filter>
         <MaxScaleDenominator>5000.0</MaxScaleDenominator>
         <LineSymbolizer>
           <Stroke>
             <CssParameter name="stroke">#a9a69e</CssParameter>
             <CssParameter name="stroke-width">5</CssParameter>
           </Stroke>
         </LineSymbolizer>
       </Rule>

10. Submit, Apply, and Save changes.

    Viewing the roads_style with road outlines

11. Back in the SLD Editor find the `<Rule>` element for the Highway 1:700K - 1:180K.

    Note

    There is a find utility in the toolbar of the SLD editor.

    Searching for text with the SLD editor’s find utility

12. Find the `<PointPlacement>` inside of the `<TextSymbolizer>` at approximately line 218. Replace the `<PointPlacement>` element with the following XML:

        <LinePlacement>
        </LinePlacement>

    Note

    The `<LinePlacement>` element specifies that a label should be placed along the line.

    Setting a label to linear placement

13. Before the closing `</TextSymbolizer>` element add the following XML:

        <VendorOption name="followLine">true</VendorOption>

    Note

    `<VendorOption>` elements are used to specify extended features and options that are not available in the core of SLD, but supported by GeoServer. In this case the followLine option is used to specify that labels should follow lines, better known as “curved labeling”.

14. After the `<VendorOption>` add the following XML:

        <VendorOption name="group">true</VendorOption>

    Note

    The `<VendorOption name="group">` element is used to group labels that have the same value along lines that are adjacent in a network. This prevents the same road being labeled multiple times unnecessarily.

    Optimizing an SLD with vendor options

15. Submit, Apply, and Save changes. Use the Map Preview or Styler to view the label change at the 1:700K - 1:180K scale.

    Viewing label optimizations

16. Repeat the steps above for all remaining rules which contain a `<TextSymbolizer>` element.

### Navigation

- index
- modules |
- next |
- previous |
- OpenGeo Stack Workshop »
- Advanced Styling with SLD »
- Optimizing a Road SLD