Package org.geotools.styling
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):
- These interfaces will reflect the current published specification
- Our implementations will be BIGGER and more capabile then any one specification
- We cannot defined explicit interfaces tracking each version until we move to Java 5 (perferably GeoAPI would hold these anyways)
- We can provided javadocs indicating extentions, and isolate these using the normal java convention: TextSymbolizer and TextSymbolizer2 (In short you will have to go out of your way to work with a hack or experiment, you won't depend on one by accident)
- We can use Factories (aka SLD1Factory and SLD1_1Factory and SEFactory) to support the creation of conformant datastructures. Code (such as user interfaces) can be parameratized with these factories when they need to confirm to an exact version supported by an individual service. We hope that specifications are always adative, and will be forced to throw unsupported exceptions when functionality is removed from a specification.
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.
StyleFactory
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.
Notes:
- At this time one implementation of StyleFactory is available, this will not provide true in the future (as SLD experiments, and code generation are brought to bare on future specifications).
StyleBuilder
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.
Example
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();
style.setName("MyStyle");
// "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"),
sb.attributeExpression("rotation"));
style.addFeatureTypeStyle(sb.createFeatureTypeStyle("testPoint",
new Symbolizer[] { sb.createPointSymbolizer(graph) }));
// "labelPoint" feature type style
AnchorPoint anchorPoint = sb.createAnchorPoint(sb.attributeExpression("X"),
sb.attributeExpression("Y"));
PointPlacement pointPlacement = sb.createPointPlacement(anchorPoint, null,
sb.literalExpression(0));
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);
style.addFeatureTypeStyle(sb.createFeatureTypeStyle("labelPoint",
new Symbolizer[] { textSymbolizer, pointSymbolizer }));
return style;
}
References
The following links will be of interest:
- SLD 1.0.0
- Design Patterns, GOF
- Since:
- GeoTools 2.0
- Author:
- Ian Turton, CCG, James Macgill, CCG, Jody Garnett, Refractions Research
-
Class Summary Class Description AbstractContrastMethodStrategy AbstractStyleFactory Abstract base class for implementing style factories.AbstractStyleVisitor A basic implementation of the StyleVisitor interface.AbstractSymbolizer AnchorPointImpl Direct implementation of AnchorPoint.BasicLineStyle A style object is quite hard to set up, involving fills, strokes, symbolizers and rules.BasicPolygonStyle A style object is quite hard to set up, involving fills, strokes, symbolizers and rules.ChannelSelectionImpl ChannelSelectionImplColorMapEntryImpl Default color map entry implementationColorMapImpl A simple implementation of the color map interface.ColorReplacementImpl An implementation of ColorReplacement; this is a wrapper around an implementaiton of the "Recode" function as defined by SymbologyEncoding 1.1.ContrastEnhancementImpl The ContrastEnhancement object defines contrast enhancement for a channel of a false-color image or for a color image.DefaultResourceLocator Default locator for online resources.DescriptionImpl DisplacementImpl ExponentialContrastMethodStrategy ExtentImpl ExternalGraphicImpl ExternalMarkImpl Default implementation of ExternalMark.FeatureTypeConstraintImpl FeatureTypeStyleImpl Implementation of Feature Type Style; care is taken to ensure everything is mutable.FillImpl FillImpl.ConstantFill FontImpl Provides a Java representation of the Font element of an SLD.GraphicImpl Direct implementation of Graphic.GraphicImpl.ConstantGraphic HaloImpl Direct implementation of Halo.HistogramContrastMethodStrategy ImageOutlineImpl LayerFeatureConstraintsImpl LinePlacementImpl Default implementation of LinePlacement.LineSymbolizerImpl Provides a representation of a LineSymbolizer in an SLD Document.LogarithmicContrastMethodStrategy MarkImpl Default implementation of Mark.NamedLayerImpl Default implementation of named layer.NamedStyleImpl A NamedStyle is used to refer to a style that has a name in a WMS.NormalizeContrastMethodStrategy OtherTextImpl OverlapBehaviorImpl OverlapBehavior tells a system how to behave when multiple raster images in a layer overlap each other, for example with satellite-image scenes.PointPlacementImpl PointSymbolizerImpl Provides a Java representation of the PointSymbolizer.PolygonSymbolizerImpl Provides a representation of a PolygonSymbolizer in an SLD Document.RasterSymbolizerImpl Default implementation of RasterSymbolizer.RemoteOWSImpl RuleImpl Provides the default implementation of Rule.SelectedChannelTypeImpl Default implementation of SelectedChannelType.ShadedReliefImpl Default implementation of ShadedRelief.SLD Utility class that provides static helper methods for common operations on GeoTools styling objects (e.g.StrokeImpl Provides a Java representation of the Stroke object in an SLD document.StyleBuilder An utility class designed to ease style building with convenience methods.StyledLayerDescriptorImpl Holds styling information (from a StyleLayerDescriptor document).StyledLayerImpl Default implementation of StyledLayer.StyleFactoryImpl Factory for creating Styles.StyleFactoryImpl2 StyleImpl Implementation of style.TextSymbolizerImpl Provides a Java representation of an SLD TextSymbolizer that defines how text symbols should be rendered.UserLayerImpl DJB: on inlinefeature support: The inline features also lets you "sort of" make your WMS into a WFS-T.VendorSymbolizerImpl ExtensioSymbolizer capturing a vendor specific extension. -
Enum Summary Enum Description UomOgcMapping Defines the Units of Measure (UOMs) specified by the OGC SE standard and their mappings to Java Units defined injavax.measure.unit
. -
Exception Summary Exception Description StyleFactoryCreationException An exception that can be thrown by the StyleFactory if it fails to create the implementation of the StyleFactory.