skrueger.geotools
Class StyledLayerUtil

java.lang.Object
  extended by skrueger.geotools.StyledLayerUtil

public class StyledLayerUtil
extends Object

This class provides static helper methods for dealing with StyledLayerInterface stuff.

Version:
1.0
Author:
Martin Schmitz (University of Bonn/Germany)

Field Summary
static String AMLURI
          URL for Atlas XML schema
static String ELEM_NAME_AMD
          Name of the XML Element for the attribute meta data map
static String ELEM_NAME_ATTRIBUTE
          Name of the XML Element for an attribute meta data map entry
static String ELEM_NAME_RASTERLEGEND
          Name of the XML Element for an raster legend data entry
static String ELEM_NAME_RLD
          Name of the XML Element for the raster legend data
static String ELEM_NAME_TRANSLATION
          Name of the XML Element for a translation
 
Constructor Summary
StyledLayerUtil()
           
 
Method Summary
static Element createAttributeMetaDataElement(AttributeMetaData amd)
          Creates an JDOM Element for the given AttributeMetaData object.
static Element createAttributeMetaDataMapElement(Map<Integer,AttributeMetaData> amdMap)
          Creates an JDOM Element for the given AttributeMetaData map.
static MapLayer createMapLayer(Object object)
          Creates a Geotools MapLayer from an object.
static MapLayer createMapLayer(Object object, Style forcedStyle)
          Creates a Geotools MapLayer from an object.
static Element createRasterLegendDataElement(RasterLegendData rld)
          Creates an JDOM Element for the given RasterLegendData map.
static StyledLayerInterface<?> createStyledLayer(Object object, String title)
          Creates an default instance of StyledLayerInterface for a Geotools object (GridCoverage2D, FeatureCollection) with a default style.
static StyledLayerInterface<?> createStyledLayer(Object object, String title, StyledLayerStyle style)
          Creates an default instance of StyledLayerInterface for a Geotools object (GridCoverage2D, FeatureCollection) with a given style.
static Element createTranslationElement(String tagname, Translation translation)
          Creates an JDOM Element for the given Translation.
static RasterLegendData generateRasterLegendData(ColorMap colorMap, boolean paintGaps, Integer digits)
          Creates RasterLegendData from a ColorMap.
static RasterLegendData generateRasterLegendData(Style style, boolean paintGaps, Integer digits)
          Creates RasterLegendData from the ColorMap of a style.
static StyledLayerStyle<Map<Integer,AttributeMetaData>> getStyledLayerStyle(StyledFeatureCollectionInterface styledFC)
          Returns the style and attribute meta data of a StyledFeatureCollectionInterface as a StyledLayerStyle.
static StyledLayerStyle<RasterLegendData> getStyledLayerStyle(StyledGridCoverageInterface styledGC)
          Returns the style and raster meta data of a StyledGridCoverageInterface as a StyledLayerStyle.
static StyledLayerStyle<?> getStyledLayerStyle(StyledLayerInterface styledObject)
          Returns the style a StyledLayerInterface as a StyledLayerStyle.
static SortedMap<Integer,AttributeMetaData> getVisibleAttributeMetaData(Map<Integer,AttributeMetaData> amdMap, boolean visible)
          Return only the visible or invisible entries of an AttributeMetaData-Map.
static Map<Integer,AttributeMetaData> loadAttributeMetaDataMap(URL documentUrl)
          Loads a AttributeMetaData object from an URL.
static RasterLegendData loadRasterLegendData(URL documentUrl)
          Loads a RasterLegendData object from an URL.
static StyledLayerStyle<Map<Integer,AttributeMetaData>> loadStyledFeatureStyle(URL geoObjectURL)
          Loads a SLD-Style from a .sld file and AttributeMetaData-Map from a .amd file for a given geo-object (feature) source.
static StyledLayerStyle<Map<Integer,AttributeMetaData>> loadStyledFeatureStyle(URL geoObjectURL, String sldExt, String rldExt)
          Loads a SLD-Style and a AttributeMetaData-Map for a given geo-object (feature) source.
static StyledLayerStyle<RasterLegendData> loadStyledRasterStyle(URL geoObjectURL)
          Loads a SLD-Style from a .sld file and Raster-LegendData from a .rld file for a given geo-object (raster) source.
static StyledLayerStyle<RasterLegendData> loadStyledRasterStyle(URL geoObjectURL, String sldExt, String rldExt)
          Loads a SLD-Style and Raster-LegendData for a given geo-object (raster) source.
static AttributeMetaData parseAttributeMetaData(Element element)
          Parses a AttributeMetaData object from an JDOM-Element.
static Map<Integer,AttributeMetaData> parseAttributeMetaDataMap(Element element)
          Parses a AttributeMetaData map from an JDOM-Element with <attribute>-childs.
static RasterLegendData parseRasterLegendData(Element element)
          Parses a RasterLegendData object from an JDOM-Element.
static Translation parseTranslation(Element element)
          Parses a Translation object from an JDOM-Element.
static void saveAttributeMetaDataMap(Map<Integer,AttributeMetaData> amdMap, URL documentUrl)
          Saves a AttributeMetaData-Map to an URL.
static void saveRasterLegendData(RasterLegendData rld, URL documentUrl)
          Saves a RasterLegendData to an URL.
static void saveStyledLayerStyle(StyledLayerStyle<?> style, URL geoObjectURL)
          Stores the SLD-Style to a .sld file and the meta data (RasterLegendData or AttributeMetaData) to a .rld or .amd file.
static
<T> void
saveStyledLayerStyle(StyledLayerStyle<T> style, URL geoObjectURL, String sldExt, String mdExt)
          Stores a SLD-Style and Raster-LegendData for a given geo-object (raster) source.
static void setStyledLayerStyle(StyledLayerInterface styledObject, StyledLayerStyle<?> style)
          Sets a style to StyledLayerInterface.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AMLURI

public static final String AMLURI
URL for Atlas XML schema

See Also:
Constant Field Values

ELEM_NAME_AMD

public static final String ELEM_NAME_AMD
Name of the XML Element for the attribute meta data map

See Also:
Constant Field Values

ELEM_NAME_RLD

public static final String ELEM_NAME_RLD
Name of the XML Element for the raster legend data

See Also:
Constant Field Values

ELEM_NAME_ATTRIBUTE

public static final String ELEM_NAME_ATTRIBUTE
Name of the XML Element for an attribute meta data map entry

See Also:
Constant Field Values

ELEM_NAME_RASTERLEGEND

public static final String ELEM_NAME_RASTERLEGEND
Name of the XML Element for an raster legend data entry

See Also:
Constant Field Values

ELEM_NAME_TRANSLATION

public static final String ELEM_NAME_TRANSLATION
Name of the XML Element for a translation

See Also:
Constant Field Values
Constructor Detail

StyledLayerUtil

public StyledLayerUtil()
Method Detail

createMapLayer

public static MapLayer createMapLayer(Object object)
                               throws Exception
Creates a Geotools MapLayer from an object. If the object is a StyledLayerInterface then its sytle is used. In case of direct Geotools objects (GridCoverage2D, AbstractGridCoverage2DReader, FeatureCollection) a default style is generated.

Parameters:
object - an Object
Throws:
Exception - if null is given as object or an error occurs during layer creation

createMapLayer

public static MapLayer createMapLayer(Object object,
                                      Style forcedStyle)
                               throws Exception
Creates a Geotools MapLayer from an object. If the object is a StyledLayerInterface then its sytle is used. In case of direct Geotools objects (GridCoverage2D, AbstractGridCoverage2DReader, FeatureCollection) a default style is generated.

Parameters:
object - an Object
forcedStyle - (SLD-)Style to force for the object
Throws:
Exception - if null is given as object or an error occurs during layer creation

createStyledLayer

public static StyledLayerInterface<?> createStyledLayer(Object object,
                                                        String title)
Creates an default instance of StyledLayerInterface for a Geotools object (GridCoverage2D, FeatureCollection) with a default style.

Parameters:
object - an Object
title - title for the object
Throws:
UnsupportedOperationException - if null is given as object or an error occurs during creation

createStyledLayer

public static StyledLayerInterface<?> createStyledLayer(Object object,
                                                        String title,
                                                        StyledLayerStyle style)
Creates an default instance of StyledLayerInterface for a Geotools object (GridCoverage2D, FeatureCollection) with a given style.

Parameters:
object - an Object
title - title for the object
style - style and meta data for the object
Throws:
UnsupportedOperationException - if null is given as object or an error occurs during creation

getVisibleAttributeMetaData

public static SortedMap<Integer,AttributeMetaData> getVisibleAttributeMetaData(Map<Integer,AttributeMetaData> amdMap,
                                                                               boolean visible)
Return only the visible or invisible entries of an AttributeMetaData-Map.

Parameters:
amdMap - AttributeMetaData-Map
visible - indicated whether the visible or invisible entries are returned

parseAttributeMetaData

public static AttributeMetaData parseAttributeMetaData(Element element)
Parses a AttributeMetaData object from an JDOM-Element. This method works like AMLImport#parseDataAttribute(org.w3c.dom.Node, but for JDOM.

Parameters:
element - Element to parse

parseAttributeMetaDataMap

public static Map<Integer,AttributeMetaData> parseAttributeMetaDataMap(Element element)
Parses a AttributeMetaData map from an JDOM-Element with <attribute>-childs.

Parameters:
element - Element to parse

loadAttributeMetaDataMap

public static Map<Integer,AttributeMetaData> loadAttributeMetaDataMap(URL documentUrl)
                                                               throws Exception
Loads a AttributeMetaData object from an URL.

Parameters:
documentUrl - URL to parse
Throws:
Exception
See Also:
parseAttributeMetaData(Element)

createAttributeMetaDataElement

public static Element createAttributeMetaDataElement(AttributeMetaData amd)
Creates an JDOM Element for the given AttributeMetaData object.

Parameters:
amd - meta data for one attribute

createAttributeMetaDataMapElement

public static Element createAttributeMetaDataMapElement(Map<Integer,AttributeMetaData> amdMap)
Creates an JDOM Element for the given AttributeMetaData map.

Parameters:
amdMap - map of attribute meta data

saveAttributeMetaDataMap

public static void saveAttributeMetaDataMap(Map<Integer,AttributeMetaData> amdMap,
                                            URL documentUrl)
                                     throws Exception
Saves a AttributeMetaData-Map to an URL.

Parameters:
amdMap - map of AttributeMetaData
documentUrl - URL to store the XML
Throws:
Exception

parseRasterLegendData

public static RasterLegendData parseRasterLegendData(Element element)
Parses a RasterLegendData object from an JDOM-Element. This method works like AMLImport#parseRasterLegendData(org.w3c.dom.Node, but for JDOM.

Parameters:
element - Element to parse

loadRasterLegendData

public static RasterLegendData loadRasterLegendData(URL documentUrl)
                                             throws Exception
Loads a RasterLegendData object from an URL.

Parameters:
documentUrl - URL to parse
Throws:
Exception
See Also:
parseAttributeMetaData(Element)

createRasterLegendDataElement

public static Element createRasterLegendDataElement(RasterLegendData rld)
Creates an JDOM Element for the given RasterLegendData map.

Parameters:
rld - raster legend data

generateRasterLegendData

public static RasterLegendData generateRasterLegendData(ColorMap colorMap,
                                                        boolean paintGaps,
                                                        Integer digits)
Creates RasterLegendData from a ColorMap.

Parameters:
colorMap - a color map
paintGaps - indicated whether gaps are painted between the legend items
digits - number of digits the grid value classes (and legend) are rounded to (null means no round; >= 0 means digits after comma; < 0 means digits before comma)

generateRasterLegendData

public static RasterLegendData generateRasterLegendData(Style style,
                                                        boolean paintGaps,
                                                        Integer digits)
Creates RasterLegendData from the ColorMap of a style.

Parameters:
style - a raster style (must contain a RasterSymbolizer)
paintGaps - indicated whether gaps are painted between the legend items
digits - number of digits the grid value classes (and legend) are rounded to (null means no round; >= 0 means digits after comma; < 0 means digits before comma)

saveRasterLegendData

public static void saveRasterLegendData(RasterLegendData rld,
                                        URL documentUrl)
                                 throws Exception
Saves a RasterLegendData to an URL.

Parameters:
rld - raster legend data
documentUrl - URL to store the XML
Throws:
Exception

parseTranslation

public static final Translation parseTranslation(Element element)
Parses a Translation object from an JDOM-Element. This method works like AMLImport#parseTranslation(org.w3c.dom.Node, but for JDOM.

Parameters:
element - Element to parse

createTranslationElement

public static final Element createTranslationElement(String tagname,
                                                     Translation translation)
Creates an JDOM Element for the given Translation.

Parameters:
tagname - Name of the Element
translation - Translation to store in the Element

setStyledLayerStyle

public static void setStyledLayerStyle(StyledLayerInterface styledObject,
                                       StyledLayerStyle<?> style)
Sets a style to StyledLayerInterface.

Parameters:
styledObject - a styled object
style - a Style

getStyledLayerStyle

public static StyledLayerStyle<?> getStyledLayerStyle(StyledLayerInterface styledObject)
Returns the style a StyledLayerInterface as a StyledLayerStyle.

Parameters:
styledObject - a styled object
Returns:
StyledLayerStyle<RasterLegendData> for StyledGridCoverageInterface or StyledLayerStyle<Map<Integer,AttributeMetaData>> for StyledFeatureCollectionInterface

getStyledLayerStyle

public static StyledLayerStyle<RasterLegendData> getStyledLayerStyle(StyledGridCoverageInterface styledGC)
Returns the style and raster meta data of a StyledGridCoverageInterface as a StyledLayerStyle.

Parameters:
styledGC - a styled grid coverage

getStyledLayerStyle

public static StyledLayerStyle<Map<Integer,AttributeMetaData>> getStyledLayerStyle(StyledFeatureCollectionInterface styledFC)
Returns the style and attribute meta data of a StyledFeatureCollectionInterface as a StyledLayerStyle.

Parameters:
styledFC - a styled feature collection

loadStyledRasterStyle

public static StyledLayerStyle<RasterLegendData> loadStyledRasterStyle(URL geoObjectURL,
                                                                       String sldExt,
                                                                       String rldExt)
Loads a SLD-Style and Raster-LegendData for a given geo-object (raster) source. The SLD file must be present. A missing raster legend-data file is tolerated.

Parameters:
geoObjectURL - URL of the (already read) raster object
sldExt - file extention for the SLD file
rldExt - file extention for the raster legend-data file
Returns:
null in case of any error

loadStyledRasterStyle

public static StyledLayerStyle<RasterLegendData> loadStyledRasterStyle(URL geoObjectURL)
Loads a SLD-Style from a .sld file and Raster-LegendData from a .rld file for a given geo-object (raster) source. The SLD file must be present. A missing raster legend-data file is tolerated.

Parameters:
geoObjectURL - URL of the (already read) raster object
sldExt - file extention for the SLD file
rldExt - file extention for the raster legend-data file
Returns:
null in case of any error

loadStyledFeatureStyle

public static StyledLayerStyle<Map<Integer,AttributeMetaData>> loadStyledFeatureStyle(URL geoObjectURL,
                                                                                      String sldExt,
                                                                                      String rldExt)
Loads a SLD-Style and a AttributeMetaData-Map for a given geo-object (feature) source. The SLD file must be present. A missing attribute meta-data file is tolerated.

Parameters:
geoObjectURL - URL of the (already read) feature object
sldExt - file extention for the SLD file
rldExt - file extention for the raster legend-data file
Returns:
null in case of any error

loadStyledFeatureStyle

public static StyledLayerStyle<Map<Integer,AttributeMetaData>> loadStyledFeatureStyle(URL geoObjectURL)
Loads a SLD-Style from a .sld file and AttributeMetaData-Map from a .amd file for a given geo-object (feature) source. The SLD file must be present. A missing attribute meta-data file is tolerated.

Parameters:
geoObjectURL - URL of the (already read) feature object
sldExt - file extention for the SLD file
rldExt - file extention for the raster legend-data file
Returns:
null in case of any error

saveStyledLayerStyle

public static <T> void saveStyledLayerStyle(StyledLayerStyle<T> style,
                                            URL geoObjectURL,
                                            String sldExt,
                                            String mdExt)
                                 throws Exception
Stores a SLD-Style and Raster-LegendData for a given geo-object (raster) source.

Parameters:
style - style to save
geoObjectURL - URL of the raster object
sldExt - file extention for the SLD file
mdExt - file extention for the meta-data file
Throws:
Exception

saveStyledLayerStyle

public static void saveStyledLayerStyle(StyledLayerStyle<?> style,
                                        URL geoObjectURL)
                                 throws Exception
Stores the SLD-Style to a .sld file and the meta data (RasterLegendData or AttributeMetaData) to a .rld or .amd file. for a given geo-object source.

Parameters:
style - style to save
geoObjectURL - URL of the (already read) raster object
Throws:
Exception