OpenGeo

OpenGeo Stack Workshop

Previous topic

Styling with SLD

Next topic

External Graphics with SLD

Creating a New SLD

In previous modules the style for a layer was configured by uploading an existing SLD. In this section the task of creating a new SLD document from scratch will be covered.

  1. From the Welcome Page navigate to Config ‣ Data ‣ Style ‣ New.

  2. Enter “bus_stops_style” in the text field and click New

    ../_images/sld_create1.jpg

    Creating a new style

  3. In the SLD Editor enter in the following XML:

    <StyledLayerDescriptor version="1.0.0" xmlns="http://www.opengis.net/sld"          xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink">
       <NamedLayer>
         <Name>bus_stops</Name>
         <UserStyle>
           <FeatureTypeStyle>
    
             <Rule>
               <PointSymbolizer>
               </PointSymbolizer>
             </Rule>
    
           </FeatureTypeStyle>
         </UserStyle>
       </NamedLayer>
    </StyledLayerDescriptor>
    
    ../_images/sld_create2.jpg

    Creating a new SLD with the style editor

    Note

    The above SLD is very basic. The thing to note is the <PointSymbolizer> element. In SLD a Symbolizer is the fundamental unit of styling. It specifies aspects of a style such as color, line width, labeling, and much more.

  4. Click Submit to add the new SLD, then Apply and Save changes.

  5. Using skills learned in the geoserver.basics module, modify the default style of the bay_area_bus_stops feature type to the newly created bus_stops_style.

    ../_images/sld_create3.jpg

    Changing the default style of the bay_area_bus_stops feature type

  6. Use the Map Preview to preview the new style.

    ../_images/sld_create4.jpg

    Previewing the bay_area_bus_stops layer with the bus_stops_style applied

At this point a new SLD has been successfully created from scratch. The next section will focus on adding to this very basic SLD to add some more interesting styling.