Skip navigation links

Package org.geotools.styling

Allows for symbolization of geospatial data.

See: Description

Package org.geotools.styling Description

Allows for symbolization of geospatial data.

For many of us in geotools *this* is the reason we came along for the ride - a pretty picture. The contents of this package are adapted from the OpenGIS® Styled Layer Descriptor specification v1.0.0.

Conformance to SLD 1.0.0

We may experiment with our own (or SLD 1.1) ideas but will mark such experiments for you. This is only an issue of you are considering writing out these objects for interoptability with other systems.

General stratagy for supporting multiple SLD versions (and experiments):

Care and Feeding of Style Objects

SLD is an XML specification, the definition of objects capturing this information, the binding of objects to these XML documents, and the provision of events on object modification all need to be accounted for.


As with all geotools work construction of styling constructs is handled by a Factory(GOF). Quickly a Factory is used when working with interfaces, anything that would of been a constructor is set up as an create method.

  StyleFactory factory = StyleFactoryFinder.createStyleFactory();
  StyleLayerDescriptor sld = factory.createStyleLayerDescriptor();
  // an empty sld document
  sld.setTitle("Basic Black");
  sld.setAbstract("Grayscale style suitable for use with photocopiers");

When creating a complex data structure direct use of a Factory is a pain. Which leads us to the next section.



When constructing a complex data structure, such as an SLD document, the use of a Factory is a bit of a pain. That is where StyleBuilder is brought to bare. A Builder is simply a class that help you construct a complicated data structure, for a make involved/interesting example of a builder have a look at the graph package.



The following code example has been borrowed from the geotools website, for additional examples (and advice) please consult the user documentation.

    private Style buildStyle() throws Exception {
        StyleBuilder sb = new StyleBuilder();
        FilterFactory ff = sb.getFilterFactory();
        Style style = sb.createStyle();

        // "testPoint" feature type style
        Mark testMark = sb.createMark(sb.attributeExpression("name"),
                sb.createFill(Color.RED, 0.5), null);
        Graphic graph = sb.createGraphic(null, new Mark[] { testMark }, null,
                sb.literalExpression(1), sb.attributeExpression("size"),
                new Symbolizer[] { sb.createPointSymbolizer(graph) }));

        // "labelPoint" feature type style
        AnchorPoint anchorPoint = sb.createAnchorPoint(sb.attributeExpression("X"),
        PointPlacement pointPlacement = sb.createPointPlacement(anchorPoint, null,
        TextSymbolizer textSymbolizer = sb.createTextSymbolizer(sb.createFill(Color.BLACK),
                new Font[] { sb.createFont("Lucida Sans", 10), sb.createFont("Arial", 10) },
                sb.createHalo(), sb.attributeExpression("name"), pointPlacement, null);
        Mark circle = sb.createMark(StyleBuilder.MARK_CIRCLE, Color.RED);
        Graphic graph2 = sb.createGraphic(null, circle, null, 1, 4, 0);
        PointSymbolizer pointSymbolizer = sb.createPointSymbolizer(graph2);
                new Symbolizer[] { textSymbolizer, pointSymbolizer }));

        return style;


The following links will be of interest:
  • SLD 1.0.0
  • Design Patterns, GOF
GeoTools 2.0
Ian Turton, CCG, James Macgill, CCG, Jody Garnett, Refractions Research

Copyright © 1996–2022 Geotools. All rights reserved.