schmitzm.geotools.styling
Class StylingUtil

java.lang.Object
  extended by schmitzm.geotools.styling.StylingUtil

public class StylingUtil
extends Object

Diese Klasse enthaelt Hilfsfunktionen zum GeoTools-Styling

Version:
1.1
Author:
Martin Schmitz (University of Bonn/Germany), Stefan Alfons Krüger

Field Summary
static StyleBuilder builder
          Deprecated. wurde ersetzt durch STYLE_BUILDER
static SLDTransformer SLDTRANSFORMER
          Standard-Instanz eines SLDTransformer.
static StyleBuilder STYLE_BUILDER
          Standard-Instanz eines StyleBuilder.
static StyleFactory STYLE_FACTORY
          Standard-Instanz einer StyleFactory
static StyleFactory styleFactory
          Deprecated. wurde ersetzt durch STYLE_FACTORY
static Color TRANSPARENT_COLOR
          Transparente Farbe
 
Constructor Summary
StylingUtil()
           
 
Method Summary
static ColorMap clearColorMapLabels(ColorMap colorMap)
          Removes all label information from the ColorMapEntrys of the given ColorMap
static Graphic clone(Graphic graphic)
          Clons a Graphic element
static Style clone(Style style)
          Clones a Style by converting it to XML and reading it back in.
static Symbolizer clone(Symbolizer sym)
           
static ColorMap cloneColorMap(ColorMap colorMap)
          Kopiert eine ColorMap.
static ColorMapEntry cloneColorMapEntry(ColorMapEntry colorMapEntry)
          Kopiert einen ColorMapEntry.
static boolean colorMapEntriesEqual(ColorMapEntry cme1, ColorMapEntry cme2)
          Prueft, ob zwei ColorMapEntry-Instanzen gleich sind.
static boolean colorMapsEqual(ColorMap cm1, ColorMap cm2)
          Prueft, ob zwei ColorMap-Instanzen gleich sind.
static void copyAllValues(TextSymbolizer from, TextSymbolizer to)
          Copies all Values from one TextSymbolizer to another TextSymbolizer
static BrewerPalette createBrewerPalette(String name, Color[] colors)
          Creates a new BrewerPalette with only one scheme (which includes all colors).
static ColorMapEntry createColorMapEntry(String label, Double quantity, Color color, double opacity)
          Erzeugt einen ColorMapEntry.
static Style createDefaultStyle(Object object)
          Erstellt einen Default-Style fuer ein Geo-Objekt.
static GridSampleDimension createDiscreteGridSampleDimension(String name, ColorMap colorMap, double[] noDataValues, Unit unit)
          Erzeugt eine GridSampleDimension aus einer ColorMap.
static Box createLegendPanel(FeatureTypeStyle[] featureTypeStyles, FeatureType featureType)
          Creates a Box that shows a legend for a list of FeatureTypeStyles and a targeted featureType
static Category createNoDataCategory(double geoValue)
          Erzeugt eine Category fuer die NoData-Werte transparent dargestellt werden.
static Category createNoDataCategory(int value, double geoValue)
          Erzeugt eine Category fuer die NoData-Werte transparent dargestellt werden.
static Style createSelectionStyle(Object geoObject)
           
static Style createStyleFromColorMap(ColorMap colorMap, String name)
          Creates a Style for a Grid layer from a ColorMap Title will be set to GridUtil.UNTITLED_RASTER_STYLE_TITLE
static Style createStyleFromColorMap(ColorMap colorMap, String name, String title)
          Creates a Style for a Grid layer from a ColorMap
static Style createStyleFromSLD(Element element)
          Erzeugt einen Style aus einem JDOM-Element, des eine SLD-Definition enthaelt
static Style createStyleSimple(Object geoObject, Color color, Color color2)
           
static MemoryFeatureCollection filterSLDVisibleOnly(FeatureCollection fc, Style style, Double scaleDenominator)
          SLD Rules können die Paramter MinScaleDenominator und MaxScaleDenominator enthalten.
static ColorMapEntry findColorMapEntry(ColorMap colorMap, double value)
          Ermittelt fuer einen Wert den ColorMapEntry aus einer ColorMap.
static Color getColorFromColorMapEntry(ColorMapEntry entry)
          Liefert die Farbe eines Farbpaletten-Eintrag.
static Color getColorFromExpression(Expression expression)
          Liefert die Farbe eines Farbpaletten-Eintrag.
static ColorMap getColorMapFromStyle(Style style)
          Liefert die Farbpalette zu einem Style, wenn der Style aus einem RasterSymbolizer erzeugt wurde.
static Color getFillColor(Fill fill)
           
static Color getGraphicColor(Graphic graphic)
           
static Color getLineSymbolizerColor(LineSymbolizer ps)
           
static Double getOpacityFromColorMapEntry(ColorMapEntry entry)
          Liefert die Transparenz eines Farbpaletten-Eintrag.
static Double getOpacityFromExpression(Expression expression)
          Liefert die Transparenz eines Farbpaletten-Eintrag.
static Color getPointSymbolizerColor(PointSymbolizer ps)
           
static Color getPolygonSymbolizerColor(PolygonSymbolizer ps)
           
static Double getQuantityFromColorMapEntry(ColorMapEntry entry)
          Liefert den Wert eines Farbpaletten-Eintrag.
static Double getQuantityFromExpression(Expression expression)
          Liefert den Wert eines Farbpaletten-Eintrag.
static Color getStrokeColor(Stroke stroke)
           
static Color getSymbolizerColor(Symbolizer symb)
           
static TextSymbolizer getTextSymbolizer(Style style, Feature f)
           
static List<TextSymbolizer> getTextSymbolizers(Style style)
           
static List<TextSymbolizer> getTextSymbolizers(Symbolizer[] symbolizers)
           
static Style[] loadSLD(File sldFile)
          Loads Styles from a SLD File
static Style[] loadSLD(InputStream inputStream)
          Loads Styles from a SLD InputStream
static Style[] loadSLD(URL url)
          Loads Styles from a SLD InputStream
static void replaceFillColor(Fill fill, Color oldColor, Color newColor)
          Replaces the "main" color in a given Fill element
static void replaceGraphicColor(Graphic graphic, Color oldColor, Color newColor)
          Replaces the "main" color in a given Graphic element
static void replaceLineSymbolizerColor(LineSymbolizer ps, Color oldColor, Color newColor)
          Replaces the "main" color in a given LineSymbolizer element
static void replacePointSymbolizerColor(PointSymbolizer ps, Color oldColor, Color newColor)
          Replaces the "main" color in a given PointSymbolizer element
static void replacePolygonSymbolizerColor(PolygonSymbolizer ps, Color oldColor, Color newColor)
          Replaces the "main" color in a given PolygonSymbolizer element
static void replaceStrokeColor(Stroke stroke, Color oldColor, Color newColor)
          Replaces the "main" color in a given Stroke element
static void replaceSymbolizerColor(Symbolizer symb, Color oldColor, Color newColor)
          Replaces the "main" color in a given Symbolizer element
static void saveStyleToSLD(Style style, File exportFile)
          Saves the Style to OGC SLD using ISO-8859-1 as charset.
static void saveStyleToSLD(Style style, File exportFile, Charset charset)
          Saves the Style to OGC SLD.
static void setColorForColorMapEntry(ColorMapEntry entry, Color color)
          Setzt die Farbe eines Farbpaletten-Eintrag.
static void setOpacityForColorMapEntry(ColorMapEntry entry, double opacity)
          Setzt die Transparenz eines Farbpaletten-Eintrag.
static void setQuantityForColorMapEntry(ColorMapEntry entry, double quantity)
          Setzt den Wert eines Farbpaletten-Eintrag.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TRANSPARENT_COLOR

public static final Color TRANSPARENT_COLOR
Transparente Farbe


STYLE_BUILDER

public static final StyleBuilder STYLE_BUILDER
Standard-Instanz eines StyleBuilder.


SLDTRANSFORMER

public static final SLDTransformer SLDTRANSFORMER
Standard-Instanz eines SLDTransformer.


builder

public static final StyleBuilder builder
Deprecated. wurde ersetzt durch STYLE_BUILDER
Standard-Instanz eines StyleBuilder.


STYLE_FACTORY

public static final StyleFactory STYLE_FACTORY
Standard-Instanz einer StyleFactory


styleFactory

public static final StyleFactory styleFactory
Deprecated. wurde ersetzt durch STYLE_FACTORY
Standard-Instanz einer StyleFactory

Constructor Detail

StylingUtil

public StylingUtil()
Method Detail

createDefaultStyle

public static Style createDefaultStyle(Object object)
Erstellt einen Default-Style fuer ein Geo-Objekt.

Parameters:
object - GridCoverage2D, org.geotools.coverage.grid.io.AbstractGridCoverage2DReader oder FeatureCollection
Returns:
null falls kein Style generiert werden kann

createNoDataCategory

public static Category createNoDataCategory(double geoValue)
Erzeugt eine Category fuer die NoData-Werte transparent dargestellt werden.

Parameters:
geoValue - Geo-Wert, der NoData repraesentiert

createNoDataCategory

public static Category createNoDataCategory(int value,
                                            double geoValue)
Erzeugt eine Category fuer die NoData-Werte transparent dargestellt werden.

Parameters:
value - Sample-Wert der Category
geoValue - Geo-Wert, der NoData repraesentiert

createDiscreteGridSampleDimension

public static GridSampleDimension createDiscreteGridSampleDimension(String name,
                                                                    ColorMap colorMap,
                                                                    double[] noDataValues,
                                                                    Unit unit)
Erzeugt eine GridSampleDimension aus einer ColorMap.

Parameters:
name - Name fuer die GridSampleDimension
colorMap - fuer jeden Eintrag der ColorMap wird eine Category erzeugt
noDataValues - Werte fuer die zusaetzliche Categorys erstellt werden, welche die transparent dargestellt werden (wenn null wird keine zusaetzliche Category erstellt)
unit - Einheit der Werte in der GridSampleDimension (kann null sein)

getColorMapFromStyle

public static ColorMap getColorMapFromStyle(Style style)
Liefert die Farbpalette zu einem Style, wenn der Style aus einem RasterSymbolizer erzeugt wurde.

Parameters:
style - Style Wenn null, dann wird style auf GridUtil.createDefaultStyle() gesetzt
Returns:
null wenn der Style nicht auf einem RasterSymbolizer basiert.

findColorMapEntry

public static ColorMapEntry findColorMapEntry(ColorMap colorMap,
                                              double value)
Ermittelt fuer einen Wert den ColorMapEntry aus einer ColorMap.

Parameters:
value - Wert
Returns:
null, wenn in der ColorMap kein expliziter Eintrag fuer den Wert hinterlegt ist

cloneColorMap

public static ColorMap cloneColorMap(ColorMap colorMap)
Kopiert eine ColorMap.

Returns:
null wenn die uebergebene ColorMap null ist

colorMapsEqual

public static boolean colorMapsEqual(ColorMap cm1,
                                     ColorMap cm2)
Prueft, ob zwei ColorMap-Instanzen gleich sind.

Parameters:
cm1 - eine Farbpalette
cm2 - eine andere Farbpalette

colorMapEntriesEqual

public static boolean colorMapEntriesEqual(ColorMapEntry cme1,
                                           ColorMapEntry cme2)
Prueft, ob zwei ColorMapEntry-Instanzen gleich sind. Dies ist der Fall, wenn ihnen der gleiche Wert, die gleiche Farbe, die gleiche Transparenz und das gleiche Label zugeordnet ist.

Parameters:
cme1 - ein Farbpaletten-Eintrag
cme2 - ein anderer Farbpaletten-Eintrag

createColorMapEntry

public static ColorMapEntry createColorMapEntry(String label,
                                                Double quantity,
                                                Color color,
                                                double opacity)
Erzeugt einen ColorMapEntry.

Parameters:
label - Label fuer den Farbpaletten-Eintrag
quantity - Wert fuer den Farbpaletten-Eintrag
color - Farbe fuer den Farbpaletten-Eintrag
opacity - Transparenz fuer die Farbe des Farbpaletten-Eintrag

cloneColorMapEntry

public static ColorMapEntry cloneColorMapEntry(ColorMapEntry colorMapEntry)
Kopiert einen ColorMapEntry.

Returns:
null wenn der uebergebene ColorMapEntry null ist

getQuantityFromExpression

public static Double getQuantityFromExpression(Expression expression)
Liefert den Wert eines Farbpaletten-Eintrag.

Parameters:
expression - Expression, die einen String oder einen Double liefert
Returns:
null, wenn null uebergeben wird

getQuantityFromColorMapEntry

public static Double getQuantityFromColorMapEntry(ColorMapEntry entry)
Liefert den Wert eines Farbpaletten-Eintrag.

Parameters:
entry - Farbpaletten-Eintrag
Returns:
null, wenn null uebergeben wird

setQuantityForColorMapEntry

public static void setQuantityForColorMapEntry(ColorMapEntry entry,
                                               double quantity)
Setzt den Wert eines Farbpaletten-Eintrag.

Parameters:
entry - Farbpaletten-Eintrag
quantity - neuer Wert

getOpacityFromExpression

public static Double getOpacityFromExpression(Expression expression)
Liefert die Transparenz eines Farbpaletten-Eintrag.

Parameters:
expression - Expression, die einen String oder einen Double liefert
Returns:
1.0, wenn null uebergeben wird

getOpacityFromColorMapEntry

public static Double getOpacityFromColorMapEntry(ColorMapEntry entry)
Liefert die Transparenz eines Farbpaletten-Eintrag.

Parameters:
entry - Farbpaletten-Eintrag
Returns:
1.0, wenn null uebergeben wird

setOpacityForColorMapEntry

public static void setOpacityForColorMapEntry(ColorMapEntry entry,
                                              double opacity)
Setzt die Transparenz eines Farbpaletten-Eintrag.

Parameters:
entry - Farbpaletten-Eintrag
opacity - Transparenzwert

getColorFromExpression

public static Color getColorFromExpression(Expression expression)
Liefert die Farbe eines Farbpaletten-Eintrag.

Parameters:
expression - Expression, die einen String liefert

getColorFromColorMapEntry

public static Color getColorFromColorMapEntry(ColorMapEntry entry)
Liefert die Farbe eines Farbpaletten-Eintrag.

Parameters:
entry - Farbpaletten-Eintrag

setColorForColorMapEntry

public static void setColorForColorMapEntry(ColorMapEntry entry,
                                            Color color)
Setzt die Farbe eines Farbpaletten-Eintrag.

Parameters:
entry - Farbpaletten-Eintrag
color - eine Farbe

createStyleFromSLD

public static Style createStyleFromSLD(Element element)
Erzeugt einen Style aus einem JDOM-Element, des eine SLD-Definition enthaelt

Parameters:
element - Element mit SLD-Definition

createStyleFromColorMap

public static Style createStyleFromColorMap(ColorMap colorMap,
                                            String name,
                                            String title)
Creates a Style for a Grid layer from a ColorMap

Parameters:
colorMap - If null, then defaultStyle for Grid will be used
name - The name to give to the Style. null will result in name= GridUtil.UNNAMED_RASTER_STYLE_NAME or GridUtil#DEFAULT_RASTER_STYLE_NAME} (if no colorMap is given).
title - The Title to give to the Style. null will result in title= GridUtil.UNTITLED_RASTER_STYLE_TITLE or GridUtil.DEFAULT_RASTER_STYLE_TITLE (if no colorMap is given)
Returns:
Always a Style that you can be applyed to a GridCoverage.

clearColorMapLabels

public static ColorMap clearColorMapLabels(ColorMap colorMap)
Removes all label information from the ColorMapEntrys of the given ColorMap


createStyleFromColorMap

public static Style createStyleFromColorMap(ColorMap colorMap,
                                            String name)
Creates a Style for a Grid layer from a ColorMap Title will be set to GridUtil.UNTITLED_RASTER_STYLE_TITLE

Parameters:
colorMap - If null, then defaultStyle for Grid will be used
name - The name to give to the Style. null will result in name GridUtil.UNTITLED_RASTER_STYLE_TITLE
Returns:
Always a Style that you can apply to a GridCoverage. Style has name GridUtil.DEFAULT_RASTER_STYLE_NAME if no colormap was provided.

loadSLD

public static Style[] loadSLD(URL url)
Loads Styles from a SLD InputStream

Parameters:
url - URL to read the SLD from
Returns:
An Array of Styles, can be length==0 if no UserStyles in SLD file. null if file not exists

loadSLD

public static Style[] loadSLD(InputStream inputStream)
Loads Styles from a SLD InputStream

Parameters:
inputStream - InputStream to read the SLD from
Returns:
An Array of Styles, can be length==0. null if file not exists

loadSLD

public static Style[] loadSLD(File sldFile)
                       throws FileNotFoundException
Loads Styles from a SLD File

Parameters:
sldFile - File to read the SLD from
Returns:
An Array of Styles, can be length==0
Throws:
FileNotFoundException

saveStyleToSLD

public static final void saveStyleToSLD(Style style,
                                        File exportFile,
                                        Charset charset)
                                 throws TransformerException,
                                        IOException
Saves the Style to OGC SLD. Overwrites any existing file.

Parameters:
style - Style to save
charset - The charset to use for the XML, e.g. . If null, ISO-8859-1 is used.
Throws:
TransformerException
IOException

saveStyleToSLD

public static final void saveStyleToSLD(Style style,
                                        File exportFile)
                                 throws TransformerException,
                                        IOException
Saves the Style to OGC SLD using ISO-8859-1 as charset. Overwrites any existing file.

Parameters:
style - Style to save
Throws:
TransformerException
IOException

filterSLDVisibleOnly

public static MemoryFeatureCollection filterSLDVisibleOnly(FeatureCollection fc,
                                                           Style style,
                                                           Double scaleDenominator)
SLD Rules können die Paramter MinScaleDenominator und MaxScaleDenominator enthalten. Dadurch können Elemente für manche Zoom-Stufen deaktiviert werden. Kommentar: "Sichtbarkeit" bezieht es nicht darauf, ob die Elemente auf dem Kartenausschnitt sichtbar sind, sondern um die SLD Regeln, welche das Feature evt. nur Scalenabhängig zeichnen.
SK 19.6.2009:Bei einem PolygonSymbolizer zählt nicht der Rand, sondern nur ob eine Füllung vorhanden ist! Man kann dann zwar leider nicht auf ein Rand eines Polygons ohne Fill klicken, aber dafür kann man durch die ungefüllte Fläche klicken.

Parameters:
fc - Die zu filternde FeatureCollection. Diese wird nicht verändert.
style - Der Style, mit dem die Features gerendert werden (z.b. layer.getStyle() )
scaleDenominator - Der aktuelle ScaleDenomitor für den die Sichtbarkeit ermittelt wird.
Returns:
Eine FeatureCollection in welcher nur die Features enthalten sind, welche bei aktuellen Scale mit dem übergebenen Style gerendert werden. TODO Was ist mit raster?!
See Also:
RendererUtilities.calculateOGCScale

getTextSymbolizer

public static TextSymbolizer getTextSymbolizer(Style style,
                                               Feature f)
Parameters:
style - A Style to search for the first TextSymbolizer that will be used for the given Feature.
Returns:
null or the first TextSymbolizer found in the style that applies to the Feature.

getTextSymbolizers

public static List<TextSymbolizer> getTextSymbolizers(Style style)
Parameters:
style - A Style to search for all TextSymbolizers . No guarantee, that any one of them will ever be used for any feature (think about filters).
Returns:
List or all TextSymbolizers found in the Style.

getTextSymbolizers

public static List<TextSymbolizer> getTextSymbolizers(Symbolizer[] symbolizers)
Parameters:
symbolizers - List of Symbolizers to search for all TextSymbolizers . No guarantee, that any one of them will ever be used for any feature (think about filters).
Returns:
List or all TextSymbolizers found in the given symbolizers.

clone

public static Style clone(Style style)
Clones a Style by converting it to XML and reading it back in.

Parameters:
style - the Style to be copied.

clone

public static Symbolizer clone(Symbolizer sym)

clone

public static Graphic clone(Graphic graphic)
Clons a Graphic element

Parameters:
graphicFill -
Returns:

createBrewerPalette

public static BrewerPalette createBrewerPalette(String name,
                                                Color[] colors)
                                         throws IOException
Creates a new BrewerPalette with only one scheme (which includes all colors). The suitablity of the palette is set to "unknown" for all viewer types.

Parameters:
name - name for the palette (also the description is set to this value)
colors - colors for the palette
Throws:
IOException

createSelectionStyle

public static Style createSelectionStyle(Object geoObject)
Parameters:
geoObject - GridCoverage2D, AbstractGridCoverage2DReader, FeatureCollection, GeometryAttributeType or FeatureSource
Returns:
a Style that is suitable to identify features of the given type as selected items.

createStyleSimple

public static Style createStyleSimple(Object geoObject,
                                      Color color,
                                      Color color2)

createLegendPanel

public static Box createLegendPanel(FeatureTypeStyle[] featureTypeStyles,
                                    FeatureType featureType)
Creates a Box that shows a legend for a list of FeatureTypeStyles and a targeted featureType

Parameters:
featureType - If this a legend for Point, Polygon or Line?
featureTypeStyles - The Styles to presen in this legend

replaceSymbolizerColor

public static void replaceSymbolizerColor(Symbolizer symb,
                                          Color oldColor,
                                          Color newColor)
Replaces the "main" color in a given Symbolizer element


replaceLineSymbolizerColor

public static void replaceLineSymbolizerColor(LineSymbolizer ps,
                                              Color oldColor,
                                              Color newColor)
Replaces the "main" color in a given LineSymbolizer element


replacePointSymbolizerColor

public static void replacePointSymbolizerColor(PointSymbolizer ps,
                                               Color oldColor,
                                               Color newColor)
Replaces the "main" color in a given PointSymbolizer element


replacePolygonSymbolizerColor

public static void replacePolygonSymbolizerColor(PolygonSymbolizer ps,
                                                 Color oldColor,
                                                 Color newColor)
Replaces the "main" color in a given PolygonSymbolizer element

Parameters:
oldColor -
newColor -
ps -

replaceStrokeColor

public static void replaceStrokeColor(Stroke stroke,
                                      Color oldColor,
                                      Color newColor)
Replaces the "main" color in a given Stroke element

Parameters:
stroke -
oldColor -
newColor -

replaceFillColor

public static void replaceFillColor(Fill fill,
                                    Color oldColor,
                                    Color newColor)
Replaces the "main" color in a given Fill element

Parameters:
fill -
oldColor -
newColor -

replaceGraphicColor

public static void replaceGraphicColor(Graphic graphic,
                                       Color oldColor,
                                       Color newColor)
Replaces the "main" color in a given Graphic element


getGraphicColor

public static Color getGraphicColor(Graphic graphic)
Parameters:
graphic - If null returns null
Returns:
the Color used in the Graphic or null, if an ExternalGraphic is used.

getStrokeColor

public static Color getStrokeColor(Stroke stroke)
Returns:
the first Color used in a Stroke.

getFillColor

public static Color getFillColor(Fill fill)
Returns:
the first Color used in a Fill.

getSymbolizerColor

public static Color getSymbolizerColor(Symbolizer symb)
Returns:
the first Color used in a Symbolizer.

getLineSymbolizerColor

public static Color getLineSymbolizerColor(LineSymbolizer ps)
Returns:
the first Color used in a LineSymbolizer.

getPolygonSymbolizerColor

public static Color getPolygonSymbolizerColor(PolygonSymbolizer ps)
Returns:
the first Color used in a PolygonSymbolizer.

getPointSymbolizerColor

public static Color getPointSymbolizerColor(PointSymbolizer ps)
Returns:
the first Color used in a PointSymbolizer.

copyAllValues

public static void copyAllValues(TextSymbolizer from,
                                 TextSymbolizer to)
Copies all Values from one TextSymbolizer to another TextSymbolizer

Parameters:
from - TextSymbolizer source
to - TextSymbolizer target. May not be null.