Class TLspSLDStyler

All Implemented Interfaces:
ILspStyler

public class TLspSLDStyler extends ALspLabelStyler

Styles Lightspeed layers according to the OGC Styled Layer Descriptor / Symbology Encoding standards. It styles all objects as described in a single TLcdSLDFeatureTypeStyle, passed during construction of the styler. It supports both LABELS and BODIES paint representations.

A feature type style can be decoded from a file with TLcdSLDFeatureTypeStyleDecoder.decodeFeatureTypeStyle(String) or can be created with TLcdSLDFeatureTypeStyle.newBuilder() using the SLD domain model.

Normally there is no need to create instances of this class yourself. See below on how to create vector and raster layers which are styled using SLD.

Creating vector layers styled with SLD

Creating the layer can be done using the TLspShapeLayerBuilder.sldStyle(TLcdSLDFeatureTypeStyle) method:


   TLcdSLDFeatureTypeStyle sld = new TLcdSLDFeatureTypeStyleDecoder().decodeFeatureTypeStyle("path/to/sld");
   TLspLayer sldStyledLayer =
     TLspShapeLayerBuilder.newBuilder()
                          .model(aModel)
                          .sldStyle(sld)
                          .build();
 

This will result in a layer which uses a TLspSLDStyler allowing you to update certain settings of the styler:


   TLspLayer sldStyledLayer = ...;
   TLspSLDStyler bodyStyler = (TLspSLDStyler)sldStyledLayer.getStyler(TLspPaintRepresentationState.REGULAR_BODY);
   bodyStyler.setIconElevationMode(ElevationMode#ON_TERRAIN);
 

If you want to update the SLD later on, you need to use the TLspLayer.configureForSLDStyling(TLcdSLDFeatureTypeStyle) method:


   TLspLayer sldStyledLayer = ...;
   TLcdSLDFeatureTypeStyle sld = new TLcdSLDFeatureTypeStyleDecoder().decodeFeatureTypeStyle("path/to/another/sld");
   sldStyledLayer.configureForSLDStyling(sld);
 

Note that the above snippets result in a layer that uses the specified SLD to render the data in the regular paint state. Please refer to TLspShapeLayerBuilder to adjust the styling for edited or selected paint states.

Creating raster layers styled with SLD

Creating the layer can be done using the TLspRasterLayerBuilder.sldStyle(TLcdSLDFeatureTypeStyle) method:


   TLcdSLDFeatureTypeStyle sld = new TLcdSLDFeatureTypeStyleDecoder().decodeFeatureTypeStyle("path/to/sld");
   ILspEditableStyledLayer sldStyledLayer =
     TLspRasterLayerBuilder.newBuilder()
                           .model(aModel)
                           .sldStyle(sld)
                           .build();
 

If you want to update the SLD later on, you need to use the TLspRasterLayer.configureForSLDStyling(TLcdSLDFeatureTypeStyle) method:


   ILspEditableStyledLayer sldStyledLayer = ...;
   if(sldStyledLayer instanceof TLspRasterLayer){
     TLcdSLDFeatureTypeStyle sld = new TLcdSLDFeatureTypeStyleDecoder().decodeFeatureTypeStyle("path/to/another/sld");
     ((TLspRasterLayer)sldStyledLayer).configureForSLDStyling(sld);
   }

 

Performance considerations

Dash patterns in line symbolizers can only be drawn efficiently if they can be converted to a 16 bit pattern. Other patterns will be drawn with TLspComplexStrokedLineStyle, which may impact performance. So for instance '4 1 2 1' is an efficient pattern, while '4 1 2 2' will degrade performance.

Vendor options

A symbolizer can optionally contain vendor options, which define additional behavior beyond the OGC Styled Layer Descriptor / Symbology Encoding standards. A vendor option is defined by a name and a value. The following vendor options are supported:

  • A vendor option followLine, which takes a boolean value and can be configured on a text symbolizer to render curved labels that follow a feature's geometry.
  • The vendor options startGap and endGap, which take a double value and can be configured on a line symbolizer to respectively define a gap in pixels at the first and the last point of the line. Note that this is currently only supported if the line width is also expressed in pixels (not world-sized).
  • A vendor option conflictResolution, which takes a boolean value and can be configured on a text symbolizer to disable label placement conflict resolution (label decluttering).
  • The vendor option composite with value copy, which can be configured on a point symbolizer to indicate that the alpha channel of its icon needs to be copied to the line style provided by another symbolizer in the same styling rule.
  • A vendor option removeAlphaChannel, which takes a boolean value and can be configured on a raster symbolizer to remove the alpha channel from an image.
  • The vendor options colorReplace and colorReplaceTolerance, which can be configured on a raster symbolizer to replace colors in an image. The colorReplace option takes a string value consisting of a comma-separated list of values defined as hexSourceColor:hexDestinationColor. For example, #000000:#00000000 replaces a black color with a transparent color. Depending on the band semantics of the source image (grayscale, palette, RGB or RGBA) and the specified destination color(s) (RGB or RGBA), a color conversion operation is optionally performed first to make sure that the color replacement can be done. More specifically, the visualized image will have RGBA band semantics if the destination color(s) and/or the source image include an alpha component; in all other cases, the visualized image will have RGB semantics. The colorReplaceTolerance option takes an integer value that is used for matching the source color in the input image. The value is defined in the range (0 - 255) and defines the maximum distance between the red, green, blue and alpha components of the source color and the colors in the input image.
  • The vendor options extrudedShapeMinimum, extrudedShapeMaximum, extrudedShapeReference which respectively take a double, a double and a ILspWorldElevationStyle.ElevationMode, can be configured on a polygon symbolizer to respectively define the minimum value in meters, the maximum value in meters and elevation mode of the rendered extruded shapes.
Since:
2012.1
See Also:
  • Constructor Details

    • TLspSLDStyler

      public TLspSLDStyler(TLcdSLDFeatureTypeStyle aFeatureTypeStyle)
      Creates a new SLD styler for the given TLcdSLDFeatureTypeStyle. A default, best effort, implementation is used to evaluate expressions that occur in the feature type style. Use TLspSLDStyler(TLcdSLDFeatureTypeStyle, TLcdSLDContext) if you need to change this to support custom domain objects or functions.

      Note: normally there is no need to create instances of this class yourself. See the class javadoc on how to create layers which use SLD for styling.

      Parameters:
      aFeatureTypeStyle - An SLD feature type style that defines the styles that this styler should generate. Never null.
    • TLspSLDStyler

      public TLspSLDStyler(TLcdSLDFeatureTypeStyle aFeatureTypeStyle, TLcdSLDContext aSLDContext)
      Creates a new SLD styler for the given TLcdSLDFeatureTypeStyle. The aSLDContext can be reused by multiple stylers, the different objects that make up this context should be thread safe.

      Note: normally there is no need to create instances of this class yourself. See the class javadoc on how to create layers which use SLD for styling.

      Parameters:
      aFeatureTypeStyle - An SLD feature type style that defines the styles that this styler should generate. Never null.
      aSLDContext - The SLD context that has to be used when applying aFeatureTypeStyle, should not be null.
  • Method Details

    • style

      public void style(Collection<?> aObjects, ALspStyleCollector aStyleCollector, TLspContext aContext)
      Description copied from class: ALspLabelStyler

      Implementation of ILspStyler.style that either casts the ALspStyleCollector to ALspLabelStyleCollector if possible, or adapts it otherwise. In the latter case, the labeling-specific calls (label, anchorLabel, algorithm, ...) are ignored. The ALspLabelStyleCollector is then passed to the style(Collection,ALspLabelStyleCollector,TLspContext) method.

      Specified by:
      style in interface ILspStyler
      Overrides:
      style in class ALspLabelStyler
      Parameters:
      aObjects - The objects to be styled.
      aStyleCollector - A style collector to which all styling information should be passed, this collector is only valid within this method call, and can no longer be used afterwards.
      aContext - Provides context information that may affect styling, such as view specific properties.
    • style

      public void style(Collection<?> aObjects, ALspLabelStyleCollector aStyleCollector, TLspContext aContext)
      Description copied from class: ALspLabelStyler

      Convenience method that takes an ALspLabelStyleCollector as argument instead of an ALspStyleCollector. This method is called from ALspLabelStyler.style(Collection, ALspStyleCollector, TLspContext).

      Specified by:
      style in class ALspLabelStyler
      Parameters:
      aObjects - The set of domain objects to provide information for
      aStyleCollector - The label style collector to submit the information to.
      aContext - The context
      See Also:
    • setPolygonElevationMode

      public void setPolygonElevationMode(ILspWorldElevationStyle.ElevationMode aElevationMode)
      Sets the default elevation mode that is used by styles that correspond to polygon symbolizers. By default, the elevation mode is null, so the styler tries to use an elevation mode that gives the best visual result.
      Parameters:
      aElevationMode - A valid elevation mode.
    • getPolygonElevationMode

      public ILspWorldElevationStyle.ElevationMode getPolygonElevationMode()
      Returns the elevation mode for polygon symbolizers, or null if the default is used.
      Returns:
      The elevation mode for polygon symbolizers, null by default.
    • getLineElevationMode

      public ILspWorldElevationStyle.ElevationMode getLineElevationMode()
      Returns the elevation mode for line symbolizers, or null if the default is used.
      Returns:
      The elevation mode for line symbolizers, null by default.
    • setLineElevationMode

      public void setLineElevationMode(ILspWorldElevationStyle.ElevationMode aLineElevationMode)
      Sets the default elevation mode that is used by styles that correspond to line symbolizers. By default, the elevation mode is null, so the styler tries to use an elevation mode that gives the best visual result.
      Parameters:
      aLineElevationMode - A valid elevation mode.
    • getIconElevationMode

      public ILspWorldElevationStyle.ElevationMode getIconElevationMode()
      Returns the elevation mode for icon symbolizers, or null if the default is used.
      Returns:
      The elevation mode for icon symbolizers, null by default.
    • setIconElevationMode

      public void setIconElevationMode(ILspWorldElevationStyle.ElevationMode aIconElevationMode)
      Sets the elevation mode that is used by styles that correspond to icon symbolizers. By default, the elevation mode is null, so the styler tries to use an elevation mode that gives the best visual result.
      Parameters:
      aIconElevationMode - A valid elevation mode.
    • setZOrder

      public void setZOrder(int aZOrder)
      Sets the Z-order for point, line and polygon symbolizers, determining which shapes that are painted on top of one another.
      Parameters:
      aZOrder - a Z-order value
      See Also:
    • getZOrder

      public int getZOrder()
      Returns the Z-order for point, line and polygon symbolizers, determining which shapes that are painted on top of one another.
      Returns:
      the Z-order value
    • getFeatureTypeStyle

      public final TLcdSLDFeatureTypeStyle getFeatureTypeStyle()
      Returns the currently used SLD feature type style.

      Note: making changes to the returned instance is not supported. Instead, set a new instance using the setSLDFeatureTypeStyle(TLcdSLDFeatureTypeStyle) method.

      Returns:
      the currently used SLD feature type style
      Since:
      2017.0
    • setSLDFeatureTypeStyle

      public final void setSLDFeatureTypeStyle(TLcdSLDFeatureTypeStyle aSLDFeatureTypeStyle)

      Sets the SLD feature type style to use for styling.

      Note: normally there is no need to call this method yourself. See the class javadoc on how to update the SLD feature type style used to style a layer.

      Parameters:
      aSLDFeatureTypeStyle - The new feature type style
      Since:
      2017.0