[Schmitzm-commits] r1678 - in trunk: schmitzm-adresses/src/test/java/de/schmitzm/adresses schmitzm-gt/src/main/java/de/schmitzm/geotools/styling
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Wed Aug 17 17:20:24 CEST 2011
Author: alfonx
Date: 2011-08-17 17:20:23 +0200 (Wed, 17 Aug 2011)
New Revision: 1678
Modified:
trunk/schmitzm-adresses/src/test/java/de/schmitzm/adresses/AddrStringUtilTest.java
trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledLayerUtil.java
Log:
raster legende bei multiband fixed?
Modified: trunk/schmitzm-adresses/src/test/java/de/schmitzm/adresses/AddrStringUtilTest.java
===================================================================
--- trunk/schmitzm-adresses/src/test/java/de/schmitzm/adresses/AddrStringUtilTest.java 2011-08-16 12:39:51 UTC (rev 1677)
+++ trunk/schmitzm-adresses/src/test/java/de/schmitzm/adresses/AddrStringUtilTest.java 2011-08-17 15:20:23 UTC (rev 1678)
@@ -24,7 +24,7 @@
checkHausnummern("1-", "1");
checkHausnummern("3/4", "3", "4");
- checkHausnummern("3/4", "3", "4");
+
checkHausnummern(" 2, 2 a, 4,", "2", "2a", "4");
checkHausnummern("22 - 23", "22", "23");
Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledLayerUtil.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledLayerUtil.java 2011-08-16 12:39:51 UTC (rev 1677)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledLayerUtil.java 2011-08-17 15:20:23 UTC (rev 1678)
@@ -111,24 +111,21 @@
import de.schmitzm.swing.SwingUtil;
/**
- * This class provides static helper methods for dealing with
- * {@link StyledLayerInterface} stuff.
+ * This class provides static helper methods for dealing with {@link StyledLayerInterface} stuff.
*
- * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
- * (University of Bonn/Germany)
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
* @version 1.0
*/
public class StyledLayerUtil {
- private static final Logger LOGGER = Logger.getLogger(StyledLayerUtil.class
- .getName());
+ private static final Logger LOGGER = Logger.getLogger(StyledLayerUtil.class.getName());
private static final SAXBuilder SAX_BUILDER = new SAXBuilder();
private static final XMLOutputter XML_OUTPUTTER = new XMLOutputter();
final public static String DONT_IMPORT_MARKER_STRING = "DONTIMPORT";
/**
- * Tries to load a style from the file denoted in {@link #getSldFile()}. If
- * the file doesn't exits, return <code>null</code>;
+ * Tries to load a style from the file denoted in {@link #getSldFile()}. If the file doesn't exits, return
+ * <code>null</code>;
*
* @return <code>true</code> is style was loaded
*/
@@ -146,8 +143,7 @@
}
/**
- * Is appended to the name of a rule, this rule shall not be shown in the
- * legend
+ * Is appended to the name of a rule, this rule shall not be shown in the legend
*/
public final static String HIDE_IN_LAYER_LEGEND_HINT = "HIDE_IN_LEGEND";
@@ -166,39 +162,32 @@
private static FilterFactory2 ff = FilterUtil.FILTER_FAC2;
/**
- * Creates a Geotools {@link MapLayer} from an object. If the object is a
- * {@link StyledLayerInterface} then its sytle is used. In case of direct
- * Geotools objects ({@link GridCoverage2D},
- * {@link AbstractGridCoverage2DReader}, {@link FeatureCollection}) a
- * default style is generated.
+ * Creates a Geotools {@link MapLayer} from an object. If the object is a {@link StyledLayerInterface} then its
+ * sytle is used. In case of direct Geotools objects ({@link GridCoverage2D}, {@link AbstractGridCoverage2DReader},
+ * {@link FeatureCollection}) a default style is generated.
*
* @param object
* an Object
* @exception Exception
- * if {@code null} is given as object or an error occurs
- * during layer creation
+ * if {@code null} is given as object or an error occurs during layer creation
*/
public static MapLayer createMapLayer(final Object object) throws Exception {
return createMapLayer(object, null);
}
/**
- * Creates a Geotools {@link MapLayer} from an object. If the object is a
- * {@link StyledLayerInterface} then its sytle is used. In case of direct
- * Geotools objects ({@link GridCoverage2D},
- * {@link AbstractGridCoverage2DReader}, {@link FeatureCollection}) a
- * default style is generated.
+ * Creates a Geotools {@link MapLayer} from an object. If the object is a {@link StyledLayerInterface} then its
+ * sytle is used. In case of direct Geotools objects ({@link GridCoverage2D}, {@link AbstractGridCoverage2DReader},
+ * {@link FeatureCollection}) a default style is generated.
*
* @param object
* an Object
* @param forcedStyle
* (SLD-)Style to force for the object
* @exception Exception
- * if {@code null} is given as object or an error occurs
- * during layer creation
+ * if {@code null} is given as object or an error occurs during layer creation
*/
- public static MapLayer createMapLayer(Object object, final Style forcedStyle)
- throws Exception {
+ public static MapLayer createMapLayer(Object object, final Style forcedStyle) throws Exception {
MapLayer layer = null;
Style style = null;
if (object instanceof StyledLayerInterface) {
@@ -213,40 +202,34 @@
if (object instanceof GridCoverage2D)
layer = new DefaultMapLayer((GridCoverage2D) object, style);
if (object instanceof AbstractGridCoverage2DReader)
- layer = new DefaultMapLayer((AbstractGridCoverage2DReader) object,
- style);
+ layer = new DefaultMapLayer((AbstractGridCoverage2DReader) object, style);
if (object instanceof FeatureCollection)
layer = new DefaultMapLayer((FeatureCollection) object, style);
if (layer == null)
- throw new Exception("Can not create MapLayer from "
- + (object == null ? "null" : object.getClass()));
+ throw new Exception("Can not create MapLayer from " + (object == null ? "null" : object.getClass()));
return layer;
}
/**
- * Creates an default instance of {@link StyledLayerInterface} for a
- * Geotools object ({@link GridCoverage2D}, {@link FeatureCollection}) with
- * a default style.
+ * Creates an default instance of {@link StyledLayerInterface} for a Geotools object ({@link GridCoverage2D},
+ * {@link FeatureCollection}) with a default style.
*
* @param object
* an Object
* @param title
* title for the object
* @exception UnsupportedOperationException
- * if {@code null} is given as object or an error occurs
- * during creation
+ * if {@code null} is given as object or an error occurs during creation
*/
- public static StyledLayerInterface<?> createStyledLayer(
- final Object object, final String title) {
+ public static StyledLayerInterface<?> createStyledLayer(final Object object, final String title) {
return createStyledLayer(object, title, null);
}
/**
- * Creates an default instance of {@link StyledLayerInterface} for a
- * Geotools object ({@link GridCoverage2D}, {@link FeatureCollection}) with
- * a given style.
+ * Creates an default instance of {@link StyledLayerInterface} for a Geotools object ({@link GridCoverage2D},
+ * {@link FeatureCollection}) with a given style.
*
* @param object
* an Object
@@ -255,30 +238,24 @@
* @param style
* style and meta data for the object
* @exception UnsupportedOperationException
- * if {@code null} is given as object or an error occurs
- * during creation
+ * if {@code null} is given as object or an error occurs during creation
*/
- public static StyledLayerInterface<?> createStyledLayer(
- final Object object, final String title,
+ public static StyledLayerInterface<?> createStyledLayer(final Object object, final String title,
final StyledLayerStyle style) {
StyledLayerInterface<?> styledLayer = null;
final String id = (title != null) ? title : "defaultID";
if (object instanceof GridCoverage2D)
- styledLayer = new StyledGridCoverage((GridCoverage2D) object, id,
- title, style);
+ styledLayer = new StyledGridCoverage((GridCoverage2D) object, id, title, style);
else if (object instanceof AbstractGridCoverage2DReader)
- styledLayer = new StyledGridCoverageReader(
- (AbstractGridCoverage2DReader) object, id, title, style);
+ styledLayer = new StyledGridCoverageReader((AbstractGridCoverage2DReader) object, id, title, style);
else if (object instanceof FeatureCollection)
- styledLayer = new StyledFeatureCollection(
- (FeatureCollection) object, id, title, style);
+ styledLayer = new StyledFeatureCollection((FeatureCollection) object, id, title, style);
if (styledLayer == null)
- throw new UnsupportedOperationException(
- "Can not create StyledLayerInterface object from "
- + (object == null ? "null" : object.getClass()));
+ throw new UnsupportedOperationException("Can not create StyledLayerInterface object from "
+ + (object == null ? "null" : object.getClass()));
return styledLayer;
}
@@ -289,15 +266,12 @@
* @param amdMap
* AttributeMetaData-Map
* @param visible
- * indicated whether the visible or invisible entries are
- * returned
+ * indicated whether the visible or invisible entries are returned
*
- * TODO replace with
- * {@link AttributeMetadataMap#sortedValuesVisibleOnly()}
+ * TODO replace with {@link AttributeMetadataMap#sortedValuesVisibleOnly()}
*/
public static AttributeMetadataMap<? extends AttributeMetadataInterface> getVisibleAttributeMetaData(
- final AttributeMetadataMap<? extends AttributeMetadataInterface> amdMap,
- final boolean visible) {
+ final AttributeMetadataMap<? extends AttributeMetadataInterface> amdMap, final boolean visible) {
final AttributeMetadataMap<AttributeMetadataInterface> filteredMap = (AttributeMetadataMap<AttributeMetadataInterface>) amdMap
.clone();
@@ -313,25 +287,21 @@
}
/**
- * Parses a {@link AttributeMetadataImpl} object from an JDOM-
- * {@link Element}. This method works like {@link
+ * Parses a {@link AttributeMetadataImpl} object from an JDOM- {@link Element}. This method works like {@link
* AMLImport#parseDataAttribute(org.w3c.dom.Node}, but for JDOM.
*
- * TODO 20.11.2009, SK: There are some new attribute weight, functiona,
- * functionX and nodata in AttributeMetaData that should be parsed/exported
- * too. but this method is only used by ISDSS, which is not supporting that
- * stuff anyways.
+ * TODO 20.11.2009, SK: There are some new attribute weight, functiona, functionX and nodata in AttributeMetaData
+ * that should be parsed/exported too. but this method is only used by ISDSS, which is not supporting that stuff
+ * anyways.
*
* @param element
* {@link Element} to parse
*/
- public static AttributeMetadataImpl parseAttributeMetaData(
- final Element element) {
+ public static AttributeMetadataImpl parseAttributeMetaData(final Element element) {
final String namespace = element.getAttributeValue("namespace");
final String localname = element.getAttributeValue("localname");
final NameImpl aName = new NameImpl(namespace, localname);
- final Boolean visible = Boolean.valueOf(element
- .getAttributeValue("visible"));
+ final Boolean visible = Boolean.valueOf(element.getAttributeValue("visible"));
final String unit = element.getAttributeValue("unit");
Translation name = new Translation();
@@ -349,22 +319,17 @@
}
/**
- * Parses a {@link AttributeMetadataImpl} map from an JDOM-{@link Element}
- * with {@code <attribute>}-childs.
+ * Parses a {@link AttributeMetadataImpl} map from an JDOM-{@link Element} with {@code <attribute>}-childs.
*
* @param element
* {@link Element} to parse
*
- * TODO Since GP 1.3 the {@link AttributeMetadataImpl} class has
- * more attributes which are not used by Xulu/ISDSS. GP
- * exports/imports the AMD via AMLExporter and AMLImporter
- * classes. (SK, 3.2.2010) *
+ * TODO Since GP 1.3 the {@link AttributeMetadataImpl} class has more attributes which are not used by
+ * Xulu/ISDSS. GP exports/imports the AMD via AMLExporter and AMLImporter classes. (SK, 3.2.2010) *
*/
- public static AttributeMetadataMap parseAttributeMetaDataMap(
- final Element element) {
+ public static AttributeMetadataMap parseAttributeMetaDataMap(final Element element) {
final AttributeMetadataMap metaData = new AttributeMetadataImplMap();
- final List<Element> attributesElements = element
- .getChildren(ELEM_NAME_ATTRIBUTE);
+ final List<Element> attributesElements = element.getChildren(ELEM_NAME_ATTRIBUTE);
for (final Element attibuteElement : attributesElements) {
final AttributeMetadataImpl attrMetaData = parseAttributeMetaData(attibuteElement);
metaData.put(attrMetaData.getName(), attrMetaData);
@@ -379,29 +344,23 @@
* {@link URL} to parse
* @see #parseAttributeMetaData(Element)
*/
- public static AttributeMetadataMap loadAttributeMetaDataMap(
- final URL documentUrl) throws Exception {
+ public static AttributeMetadataMap loadAttributeMetaDataMap(final URL documentUrl) throws Exception {
final Document document = SAX_BUILDER.build(documentUrl);
return parseAttributeMetaDataMap(document.getRootElement());
}
/**
- * Creates an JDOM {@link Element} for the given
- * {@link AttributeMetadataImpl} object.
+ * Creates an JDOM {@link Element} for the given {@link AttributeMetadataImpl} object.
*
* @param amd
* meta data for one attribute
*
- * TODO Since GP 1.3 the {@link AttributeMetadataImpl} class has
- * more attributes which are not used by Xulu/ISDSS. GP
- * exports/imports the AMD via AMLExporter and AMLImporter
- * classes. (SK, 3.2.2010)
+ * TODO Since GP 1.3 the {@link AttributeMetadataImpl} class has more attributes which are not used by
+ * Xulu/ISDSS. GP exports/imports the AMD via AMLExporter and AMLImporter classes. (SK, 3.2.2010)
*/
- public static Element createAttributeMetaDataElement(
- final AttributeMetadataInterface amd) {
+ public static Element createAttributeMetaDataElement(final AttributeMetadataInterface amd) {
final Element element = new Element(ELEM_NAME_ATTRIBUTE, AMLURI);
- element.setAttribute("namespace",
- String.valueOf(amd.getName().getNamespaceURI()));
+ element.setAttribute("namespace", String.valueOf(amd.getName().getNamespaceURI()));
element.setAttribute("localname", String.valueOf(amd.getLocalName()));
element.setAttribute("visible", String.valueOf(amd.isVisible()));
element.setAttribute("unit", amd.getUnit());
@@ -413,8 +372,7 @@
}
/**
- * Creates an JDOM {@link Element} for the given
- * {@link AttributeMetadataImpl} map.
+ * Creates an JDOM {@link Element} for the given {@link AttributeMetadataImpl} map.
*
* @param amdMap
* map of attribute meta data
@@ -435,8 +393,7 @@
* @param documentUrl
* {@link URL} to store the XML
*/
- public static void saveAttributeMetaDataMap(
- final AttributeMetadataMap amdMap, final URL documentUrl)
+ public static void saveAttributeMetaDataMap(final AttributeMetadataMap amdMap, final URL documentUrl)
throws Exception {
// Create XML-Document
final FileWriter out = new FileWriter(new File(documentUrl.toURI()));
@@ -446,8 +403,7 @@
}
/**
- * Parses a {@link RasterLegendData} object from an JDOM-{@link Element}.
- * This method works like {@link
+ * Parses a {@link RasterLegendData} object from an JDOM-{@link Element}. This method works like {@link
* AMLImport#parseRasterLegendData(org.w3c.dom.Node}, but for JDOM.
*
* @param element
@@ -455,8 +411,7 @@
*/
public static RasterLegendData parseRasterLegendData(final Element element) {
- final boolean paintGaps = Boolean.valueOf(element
- .getAttributeValue("paintGaps"));
+ final boolean paintGaps = Boolean.valueOf(element.getAttributeValue("paintGaps"));
final RasterLegendData rld = new RasterLegendData(paintGaps);
@@ -467,12 +422,10 @@
continue;
if (name.equals(ELEM_NAME_RASTERLEGEND)) {
- final String valueAttr = childElement
- .getAttributeValue("value");
+ final String valueAttr = childElement.getAttributeValue("value");
if (valueAttr == null)
- throw new UnsupportedOperationException(
- "Attribute 'value' missing for definition of <"
- + ELEM_NAME_RASTERLEGEND + ">");
+ throw new UnsupportedOperationException("Attribute 'value' missing for definition of <"
+ + ELEM_NAME_RASTERLEGEND + ">");
final double value = Double.valueOf(valueAttr);
// first and only item should be the label
@@ -480,8 +433,7 @@
// id label element is missing, the translation is searched
// directly
// as childs of the rasterLegendItem element
- final Translation label = parseTranslation(labelElement != null ? labelElement
- : childElement);
+ final Translation label = parseTranslation(labelElement != null ? labelElement : childElement);
rld.put(value, label);
}
}
@@ -496,21 +448,18 @@
* {@link URL} to parse
* @see #parseAttributeMetaData(Element)
*/
- public static RasterLegendData loadRasterLegendData(final URL documentUrl)
- throws Exception {
+ public static RasterLegendData loadRasterLegendData(final URL documentUrl) throws Exception {
final Document document = SAX_BUILDER.build(documentUrl);
return parseRasterLegendData(document.getRootElement());
}
/**
- * Creates an JDOM {@link Element} for the given {@link RasterLegendData}
- * map.
+ * Creates an JDOM {@link Element} for the given {@link RasterLegendData} map.
*
* @param rld
* raster legend data
*/
- public static Element createRasterLegendDataElement(
- final RasterLegendData rld) {
+ public static Element createRasterLegendDataElement(final RasterLegendData rld) {
final Element element = new Element(ELEM_NAME_RLD, AMLURI);
element.setAttribute("paintGaps", rld.isPaintGaps().toString());
for (final Double key : rld.getSortedKeys()) {
@@ -530,15 +479,13 @@
* @param paintGaps
* indicated whether gaps are painted between the legend items
* @param 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)
+ * 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)
*/
- public static RasterLegendData generateRasterLegendData(
- final ColorMap colorMap, final boolean paintGaps,
+ public static RasterLegendData generateRasterLegendData(final ColorMap colorMap, final boolean paintGaps,
final Integer digits) {
- final DecimalFormat decFormat = digits != null ? new DecimalFormat(
- SwingUtil.getNumberFormatPattern(digits)) : null;
+ final DecimalFormat decFormat = digits != null ? new DecimalFormat(SwingUtil.getNumberFormatPattern(digits))
+ : null;
final RasterLegendData rld = new RasterLegendData(paintGaps);
int idx = 0;
@@ -552,8 +499,7 @@
// To make the last class limit INCLUSIVE, AtlasStylerRaster repeats
// the last CME with the same quantity (=value). This CME can then
// be ignored.
- if (cmes.get(cmes.size() - 1).getQuantity()
- .equals(cmes.get(cmes.size() - 2).getQuantity())) {
+ if (cmes.get(cmes.size() - 1).getQuantity().equals(cmes.get(cmes.size() - 2).getQuantity())) {
// Simply remove the last CME in that case
cmes.remove(cmes.size() - 1);
}
@@ -561,8 +507,7 @@
for (final ColorMapEntry cme : cmes) {
- if (idx == cmes.size() - 1
- && colorMap.getType() != ColorMap.TYPE_VALUES) {
+ if (idx == cmes.size() - 1 && colorMap.getType() != ColorMap.TYPE_VALUES) {
// Ignore the last CME label if not in VALUES mode
continue;
}
@@ -591,16 +536,14 @@
* @param paintGaps
* indicated whether gaps are painted between the legend items
* @param 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)
+ * 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)
*/
- public static RasterLegendData generateRasterLegendData(final Style style,
- final boolean paintGaps, final Integer digits) {
+ public static RasterLegendData generateRasterLegendData(final Style style, final boolean paintGaps,
+ final Integer digits) {
final ColorMap colorMap = StylingUtil.getColorMapFromStyle(style);
if (colorMap == null)
- throw new IllegalArgumentException(
- "Color map can not be determined from style!");
+ throw new IllegalArgumentException("Color map can not be determined from style!");
return generateRasterLegendData(colorMap, paintGaps, digits);
}
@@ -612,8 +555,7 @@
* @param documentUrl
* {@link URL} to store the XML
*/
- public static void saveRasterLegendData(final RasterLegendData rld,
- final URL documentUrl) throws Exception {
+ public static void saveRasterLegendData(final RasterLegendData rld, final URL documentUrl) throws Exception {
// Create XML-Document
final FileWriter out = new FileWriter(new File(documentUrl.toURI()));
XML_OUTPUTTER.output(createRasterLegendDataElement(rld), out);
@@ -622,9 +564,8 @@
}
/**
- * Parses a {@link Translation} object from an JDOM-{@link Element}. This
- * method works like {@link AMLImport#parseTranslation(org.w3c.dom.Node},
- * but for JDOM.
+ * Parses a {@link Translation} object from an JDOM-{@link Element}. This method works like {@link
+ * AMLImport#parseTranslation(org.w3c.dom.Node}, but for JDOM.
*
* @param element
* {@link Element} to parse
@@ -635,8 +576,7 @@
if (element == null)
return trans;
- for (final Element translationElement : (List<Element>) element
- .getChildren()) {
+ for (final Element translationElement : (List<Element>) element.getChildren()) {
final String name = translationElement.getName();
if (name == null)
continue;
@@ -672,18 +612,15 @@
* @param translation
* Translation to store in the Element
*/
- public final static Element createTranslationElement(final String tagname,
- final Translation translation) {
+ public final static Element createTranslationElement(final String tagname, final Translation translation) {
final Element element = new Element(tagname, AMLURI);
if (translation == null)
- throw new UnsupportedOperationException(
- "Translation element can not be created from null!");
+ throw new UnsupportedOperationException("Translation element can not be created from null!");
// If only a default translation is set, the <translation
// lang="..">..</tranlation>
// part is not used
- if (translation.keySet().size() == 1
- && translation.get(Translation.DEFAULT_KEY) != null) {
+ if (translation.keySet().size() == 1 && translation.get(Translation.DEFAULT_KEY) != null) {
element.addContent(translation.get(Translation.DEFAULT_KEY));
return element;
}
@@ -691,8 +628,7 @@
// add a <translation lang="..">..</tranlation> part to the element for
// all languages
for (final String lang : translation.keySet()) {
- final Element translationElement = new Element(
- ELEM_NAME_TRANSLATION, AMLURI);
+ final Element translationElement = new Element(ELEM_NAME_TRANSLATION, AMLURI);
translationElement.setAttribute("lang", lang);
String translationString = translation.get(lang);
if (translationString == null)
@@ -712,19 +648,14 @@
* @param style
* a Style
*/
- public static void setStyledLayerStyle(
- final StyledLayerInterface styledObject,
- final StyledLayerStyle<?> style) {
+ public static void setStyledLayerStyle(final StyledLayerInterface styledObject, final StyledLayerStyle<?> style) {
// set SLD style
styledObject.setStyle(style.getGeoObjectStyle());
// set meta data
if (styledObject instanceof StyledGridCoverageInterface
- && (style.getMetaData() instanceof RasterLegendData || style
- .getMetaData() == null)) {
- final RasterLegendData sourceRld = (RasterLegendData) style
- .getMetaData();
- final RasterLegendData destRld = ((StyledGridCoverageInterface) styledObject)
- .getLegendMetaData();
+ && (style.getMetaData() instanceof RasterLegendData || style.getMetaData() == null)) {
+ final RasterLegendData sourceRld = (RasterLegendData) style.getMetaData();
+ final RasterLegendData destRld = ((StyledGridCoverageInterface) styledObject).getLegendMetaData();
if (destRld != null && sourceRld != null) {
destRld.setPaintGaps(sourceRld.isPaintGaps());
destRld.clear();
@@ -734,8 +665,7 @@
}
if (styledObject instanceof StyledFeatureCollectionInterface
&& (style.getMetaData() instanceof Map || style.getMetaData() == null)) {
- final AttributeMetadataMap sourceAmd = (AttributeMetadataMap) style
- .getMetaData();
+ final AttributeMetadataMap sourceAmd = (AttributeMetadataMap) style.getMetaData();
final AttributeMetadataMap destAmd = ((StyledFeatureCollectionInterface) styledObject)
.getAttributeMetaDataMap();
if (destAmd != null && sourceAmd != null) {
@@ -745,68 +675,53 @@
return;
}
- throw new UnsupportedOperationException(
- "Style is not compatible to object: "
- + (style.getMetaData() == null ? null : style
- .getMetaData().getClass().getSimpleName())
- + " <-> "
- + (styledObject == null ? null : styledObject
- .getClass().getSimpleName()));
+ throw new UnsupportedOperationException("Style is not compatible to object: "
+ + (style.getMetaData() == null ? null : style.getMetaData().getClass().getSimpleName()) + " <-> "
+ + (styledObject == null ? null : styledObject.getClass().getSimpleName()));
}
/**
- * Returns the style a {@link StyledLayerInterface} as a
- * {@link StyledLayerStyle}.
+ * Returns the style a {@link StyledLayerInterface} as a {@link StyledLayerStyle}.
*
* @param styledObject
* a styled object
- * @return {@code StyledLayerStyle<RasterLegendData>} for
- * {@link StyledGridCoverageInterface} or
- * {@code StyledLayerStyle<Map<Integer,AttributeMetaData>>} for
- * {@link StyledFeatureCollectionInterface}
+ * @return {@code StyledLayerStyle<RasterLegendData>} for {@link StyledGridCoverageInterface} or
+ * {@code StyledLayerStyle<Map<Integer,AttributeMetaData>>} for {@link StyledFeatureCollectionInterface}
*/
- public static StyledLayerStyle<?> getStyledLayerStyle(
- final StyledLayerInterface styledObject) {
+ public static StyledLayerStyle<?> getStyledLayerStyle(final StyledLayerInterface styledObject) {
if (styledObject instanceof StyledGridCoverageInterface)
return getStyledLayerStyle((StyledGridCoverageInterface) styledObject);
if (styledObject instanceof StyledFeatureCollectionInterface)
return getStyledLayerStyle((StyledFeatureCollectionInterface) styledObject);
- throw new UnsupportedOperationException(
- "Unknown type of StyledLayerInterface: "
- + (styledObject == null ? null : styledObject
- .getClass().getSimpleName()));
+ throw new UnsupportedOperationException("Unknown type of StyledLayerInterface: "
+ + (styledObject == null ? null : styledObject.getClass().getSimpleName()));
}
/**
- * Returns the style and raster meta data of a
- * {@link StyledGridCoverageInterface} as a {@link StyledLayerStyle}.
+ * Returns the style and raster meta data of a {@link StyledGridCoverageInterface} as a {@link StyledLayerStyle}.
*
* @param styledGC
* a styled grid coverage
*/
- public static StyledLayerStyle<RasterLegendData> getStyledLayerStyle(
- final StyledGridCoverageInterface styledGC) {
- return new StyledLayerStyle<RasterLegendData>(styledGC.getStyle(),
- styledGC.getLegendMetaData());
+ public static StyledLayerStyle<RasterLegendData> getStyledLayerStyle(final StyledGridCoverageInterface styledGC) {
+ return new StyledLayerStyle<RasterLegendData>(styledGC.getStyle(), styledGC.getLegendMetaData());
}
/**
- * Returns the style and attribute meta data of a
- * {@link StyledFeatureCollectionInterface} as a {@link StyledLayerStyle}.
+ * Returns the style and attribute meta data of a {@link StyledFeatureCollectionInterface} as a
+ * {@link StyledLayerStyle}.
*
* @param styledFC
* a styled feature collection
*/
public static StyledLayerStyle<AttributeMetadataMap> getStyledLayerStyle(
final StyledFeatureCollectionInterface styledFC) {
- return new StyledLayerStyle<AttributeMetadataMap>(styledFC.getStyle(),
- styledFC.getAttributeMetaDataMap());
+ return new StyledLayerStyle<AttributeMetadataMap>(styledFC.getStyle(), styledFC.getAttributeMetaDataMap());
}
/**
- * Loads a {@linkplain Style SLD-Style} and {@linkplain RasterLegendData
- * Raster-LegendData} for a given geo-object (raster) source. The SLD file
- * must be present. A missing raster legend-data file is tolerated.
+ * Loads a {@linkplain Style SLD-Style} and {@linkplain RasterLegendData Raster-LegendData} for a given geo-object
+ * (raster) source. The SLD file must be present. A missing raster legend-data file is tolerated.
*
* @param geoObjectURL
* URL of the (already read) raster object
@@ -816,13 +731,12 @@
* file extention for the raster legend-data file
* @return {@code null} in case of any error
*/
- public static StyledLayerStyle<RasterLegendData> loadStyledRasterStyle(
- final URL geoObjectURL, final String sldExt, final String rldExt) {
+ public static StyledLayerStyle<RasterLegendData> loadStyledRasterStyle(final URL geoObjectURL, final String sldExt,
+ final String rldExt) {
RasterLegendData metaData = null;
Style sldStyle = null;
try {
- final Style[] styles = StylingUtil.loadSLD(IOUtil.changeUrlExt(
- geoObjectURL, sldExt));
+ final Style[] styles = StylingUtil.loadSLD(IOUtil.changeUrlExt(geoObjectURL, sldExt));
// SLD must be present
if (styles == null || styles.length == 0)
return null;
@@ -834,8 +748,7 @@
}
try {
- metaData = StyledLayerUtil.loadRasterLegendData(IOUtil
- .changeUrlExt(geoObjectURL, rldExt));
+ metaData = StyledLayerUtil.loadRasterLegendData(IOUtil.changeUrlExt(geoObjectURL, rldExt));
} catch (final FileNotFoundException err) {
// ignore missing raster legend data
} catch (final Exception err) {
@@ -847,10 +760,9 @@
}
/**
- * Loads a {@linkplain Style SLD-Style} from a {@code .sld} file and
- * {@linkplain RasterLegendData Raster-LegendData} from a {@code .rld} file
- * for a given geo-object (raster) source. The SLD file must be present. A
- * missing raster legend-data file is tolerated.
+ * Loads a {@linkplain Style SLD-Style} from a {@code .sld} file and {@linkplain RasterLegendData Raster-LegendData}
+ * from a {@code .rld} file for a given geo-object (raster) source. The SLD file must be present. A missing raster
+ * legend-data file is tolerated.
*
* @param geoObjectURL
* URL of the (already read) raster object
@@ -860,16 +772,13 @@
* file extention for the raster legend-data file
* @return {@code null} in case of any error
*/
- public static StyledLayerStyle<RasterLegendData> loadStyledRasterStyle(
- final URL geoObjectURL) {
+ public static StyledLayerStyle<RasterLegendData> loadStyledRasterStyle(final URL geoObjectURL) {
return loadStyledRasterStyle(geoObjectURL, "sld", "rld");
}
/**
- * Loads a {@linkplain Style SLD-Style} and a
- * {@linkplain AttributeMetadataImpl AttributeMetaData-Map} for a given
- * geo-object (feature) source. The SLD file must be present. A missing
- * attribute meta-data file is tolerated.
+ * Loads a {@linkplain Style SLD-Style} and a {@linkplain AttributeMetadataImpl AttributeMetaData-Map} for a given
+ * geo-object (feature) source. The SLD file must be present. A missing attribute meta-data file is tolerated.
*
* @param geoObjectURL
* URL of the (already read) feature object
@@ -879,13 +788,12 @@
* file extention for the raster legend-data file
* @return {@code null} in case of any error
*/
- public static StyledLayerStyle<AttributeMetadataMap> loadStyledFeatureStyle(
- final URL geoObjectURL, final String sldExt, final String rldExt) {
+ public static StyledLayerStyle<AttributeMetadataMap> loadStyledFeatureStyle(final URL geoObjectURL,
+ final String sldExt, final String rldExt) {
AttributeMetadataMap metaData = null;
Style sldStyle = null;
try {
- final Style[] styles = StylingUtil.loadSLD(IOUtil.changeUrlExt(
- geoObjectURL, sldExt));
+ final Style[] styles = StylingUtil.loadSLD(IOUtil.changeUrlExt(geoObjectURL, sldExt));
// SLD must be present
if (styles == null || styles.length == 0)
return null;
@@ -897,8 +805,7 @@
}
try {
- metaData = StyledLayerUtil.loadAttributeMetaDataMap(IOUtil
- .changeUrlExt(geoObjectURL, rldExt));
+ metaData = StyledLayerUtil.loadAttributeMetaDataMap(IOUtil.changeUrlExt(geoObjectURL, rldExt));
} catch (final FileNotFoundException err) {
// ignore missing attribute meta data
} catch (final Exception err) {
@@ -911,10 +818,9 @@
}
/**
- * Loads a {@linkplain Style SLD-Style} from a {@code .sld} file and
- * {@linkplain AttributeMetadataImpl AttributeMetaData-Map} from a
- * {@code .amd} file for a given geo-object (feature) source. The SLD file
- * must be present. A missing attribute meta-data file is tolerated.
+ * Loads a {@linkplain Style SLD-Style} from a {@code .sld} file and {@linkplain AttributeMetadataImpl
+ * AttributeMetaData-Map} from a {@code .amd} file for a given geo-object (feature) source. The SLD file must be
+ * present. A missing attribute meta-data file is tolerated.
*
* @param geoObjectURL
* URL of the (already read) feature object
@@ -924,14 +830,13 @@
* file extention for the raster legend-data file
* @return {@code null} in case of any error
*/
- public static StyledLayerStyle<AttributeMetadataMap> loadStyledFeatureStyle(
- final URL geoObjectURL) {
+ public static StyledLayerStyle<AttributeMetadataMap> loadStyledFeatureStyle(final URL geoObjectURL) {
return loadStyledFeatureStyle(geoObjectURL, "sld", "amd");
}
/**
- * Stores a {@linkplain Style SLD-Style} and {@linkplain RasterLegendData
- * Raster-LegendData} for a given geo-object (raster) source.
+ * Stores a {@linkplain Style SLD-Style} and {@linkplain RasterLegendData Raster-LegendData} for a given geo-object
+ * (raster) source.
*
* @param style
* style to save
@@ -942,47 +847,40 @@
* @param mdExt
* file extention for the meta-data file
*/
- public static <T> void saveStyledLayerStyle(
- final StyledLayerStyle<T> style, final URL geoObjectURL,
+ public static <T> void saveStyledLayerStyle(final StyledLayerStyle<T> style, final URL geoObjectURL,
final String sldExt, final String mdExt) throws Exception {
// Store the SLD
final Style sldStyle = style.getGeoObjectStyle();
if (sldStyle != null) {
- StylingUtil.saveStyleToSld(sldStyle, IOUtil.changeFileExt(new File(
- geoObjectURL.toURI()), sldExt));
+ StylingUtil.saveStyleToSld(sldStyle, IOUtil.changeFileExt(new File(geoObjectURL.toURI()), sldExt));
}
// Store the meta data
final T metaData = style.getMetaData();
if (metaData != null) {
if (metaData instanceof RasterLegendData) {
- saveRasterLegendData((RasterLegendData) metaData,
- IOUtil.changeUrlExt(geoObjectURL, mdExt));
+ saveRasterLegendData((RasterLegendData) metaData, IOUtil.changeUrlExt(geoObjectURL, mdExt));
// } else if ( metaData instanceof
// Map<Integer,AttributeMetaData> ) { // LEIDER NICHT
// KOMPILIERBAR!!
} else if (metaData instanceof Map) {
- saveAttributeMetaDataMap((AttributeMetadataMap) metaData,
- IOUtil.changeUrlExt(geoObjectURL, mdExt));
+ saveAttributeMetaDataMap((AttributeMetadataMap) metaData, IOUtil.changeUrlExt(geoObjectURL, mdExt));
} else
- throw new UnsupportedOperationException(
- "Export for meta data not yet supported: "
- + metaData.getClass().getSimpleName());
+ throw new UnsupportedOperationException("Export for meta data not yet supported: "
+ + metaData.getClass().getSimpleName());
}
}
/**
- * Stores the {@linkplain Style SLD-Style} to a {@code .sld} file and the
- * meta data ({@link RasterLegendData} or {@link AttributeMetadataImpl}) to
- * a {@code .rld} or {@code .amd} file. for a given geo-object source.
+ * Stores the {@linkplain Style SLD-Style} to a {@code .sld} file and the meta data ({@link RasterLegendData} or
+ * {@link AttributeMetadataImpl}) to a {@code .rld} or {@code .amd} file. for a given geo-object source.
*
* @param style
* style to save
* @param geoObjectURL
* URL of the (already read) raster object
*/
- public static void saveStyledLayerStyle(final StyledLayerStyle<?> style,
- final URL geoObjectURL) throws Exception {
+ public static void saveStyledLayerStyle(final StyledLayerStyle<?> style, final URL geoObjectURL) throws Exception {
if (style.getMetaData() instanceof RasterLegendData)
saveStyledLayerStyle(style, geoObjectURL, "sld", "rld");
else
@@ -990,26 +888,23 @@
}
/**
- * Creates a {@link JPanel} that shows a legend for a list of
- * {@link FeatureTypeStyle}s and a targeted featureType
+ * Creates a {@link JPanel} that shows a legend for a list of {@link FeatureTypeStyle}s and a targeted featureType
*
* @param style
* The Style to presented in this legend
* @param featureType
* If this a legend for Point, Polygon or Line? Or ANY or NONE?
* @param scaleDenominator
- * <code>null</code> of a Scale Denominator to determine whether
- * a Rule is actually visible in that scale.
+ * <code>null</code> of a Scale Denominator to determine whether a Rule is actually visible in that
+ * scale.
*
* @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
*/
- public static JPanel createLegendSwingPanel(Style style,
- final SimpleFeatureType featureType, final int iconWidth,
+ public static JPanel createLegendSwingPanel(Style style, final SimpleFeatureType featureType, final int iconWidth,
final int iconHeight, Double scaleDenominator) {
if (featureType == null) {
- ExceptionDialog.show(new IllegalStateException(
- "featureType is null!"));
+ ExceptionDialog.show(new IllegalStateException("featureType is null!"));
return new JPanel();
}
@@ -1035,23 +930,16 @@
for (final Rule rule : rules) {
/*
- * The MinScaleDenominator and MaxScaleDenominator elements of a
- * Rule define the range of map-rendering scales for which the
- * rule should be applied. The schema is: <xsd:element
- * name="MinScaleDenominator" type="xsd:double"/> <xsd:element
- * name="MaxScaleDenominator" type="xsd:double"/> The values
- * used are actually the scale denominators relative to a
- * “standardized rendering pixel size” (below). For example, an
- * element-content value of “10000000” means a scale of
- * 1:10-million. Scientific notation is also allowed here (and
- * for all non-integer numbers in SE), so a more convenient
- * value of “10e6” could also be used for the element content
- * for this example. The MinScaleDenominator and
- * MaxScaleDenominator elements, as their names suggest, are
- * simply the minimum and maximum ranges of scale (denominators)
- * of maps for which a rule should apply. The minimum scale is
- * inclusive and the maximum scale is exclusive. So, for
- * example, the following scale range:
+ * The MinScaleDenominator and MaxScaleDenominator elements of a Rule define the range of map-rendering
+ * scales for which the rule should be applied. The schema is: <xsd:element name="MinScaleDenominator"
+ * type="xsd:double"/> <xsd:element name="MaxScaleDenominator" type="xsd:double"/> The values used are
+ * actually the scale denominators relative to a “standardized rendering pixel size” (below). For
+ * example, an element-content value of “10000000” means a scale of 1:10-million. Scientific notation is
+ * also allowed here (and for all non-integer numbers in SE), so a more convenient value of “10e6” could
+ * also be used for the element content for this example. The MinScaleDenominator and
+ * MaxScaleDenominator elements, as their names suggest, are simply the minimum and maximum ranges of
+ * scale (denominators) of maps for which a rule should apply. The minimum scale is inclusive and the
+ * maximum scale is exclusive. So, for example, the following scale range:
*/
if (scaleDenominator != null && scaleDenominator != 0.0
&& scaleDenominator < rule.getMinScaleDenominator())
@@ -1061,21 +949,17 @@
continue;
// Check if this RULE shall actually appear in the legend
- if (rule.getName() != null
- && rule.getName().contains(HIDE_IN_LAYER_LEGEND_HINT))
+ if (rule.getName() != null && rule.getName().contains(HIDE_IN_LAYER_LEGEND_HINT))
continue;
/**
- * Let's not create a hbox for Rules that only contain
- * TextSymbolizers
+ * Let's not create a hbox for Rules that only contain TextSymbolizers
*/
- if (StylingUtil.getTextSymbolizers(rule.getSymbolizers())
- .size() == rule.getSymbolizers().length)
+ if (StylingUtil.getTextSymbolizers(rule.getSymbolizers()).size() == rule.getSymbolizers().length)
continue;
- final BufferedImage imageForRule = LegendIconFeatureRenderer
- .getInstance().createImageForRule(rule, featureType,
- new Dimension(iconWidth, iconHeight));
+ final BufferedImage imageForRule = LegendIconFeatureRenderer.getInstance().createImageForRule(rule,
+ featureType, new Dimension(iconWidth, iconHeight));
final ImageIcon legendIcon = new ImageIcon(imageForRule);
@@ -1086,8 +970,7 @@
// hbox.add(Box.createHorizontalStrut(3));
final Translation labelT = new Translation();
- labelT.fromOneLine(GTUtil.descriptionTitle(rule
- .getDescription()));
+ labelT.fromOneLine(GTUtil.descriptionTitle(rule.getDescription()));
final JLabel classTitleLabel = new JLabel(labelT.toString());
panel.add(classTitleLabel, "sgx2");
@@ -1099,18 +982,16 @@
}
/**
- * Creates a {@link JComponent} that contains a legend for a given
- * {@link StyledRasterInterface} and a given {@link Style}.
+ * Creates a {@link JComponent} that contains a legend for a given {@link StyledRasterInterface} and a given
+ * {@link Style}.
*
* @param style
- * if <code>null</code>, the default {@link Style} is extracetd
- * from the {@link StyledRasterInterface}
+ * if <code>null</code>, the default {@link Style} is extracetd from the {@link StyledRasterInterface}
* @param scaleDenominator
- * <code>null</code> of a Scale Denominator to determine whether
- * a Rule is actually visible in that scale.
+ * <code>null</code> of a Scale Denominator to determine whether a Rule is actually visible in that
+ * scale.
*/
- public static JPanel createLegendSwingPanel(
- final StyledRasterInterface<?> styledRaster, Style style,
+ public static JPanel createLegendSwingPanel(final StyledRasterInterface<?> styledRaster, Style style,
final int iconWidth, final int iconHeight, Double scaleDenominator) {
// If no style is given, we use the default style for this layer
@@ -1121,23 +1002,25 @@
* Determine whether a Style is responsible for the coloring
*/
ColorModel colorModel = null;
- if (!isStyleable(styledRaster)
- || (isStyleable(styledRaster) && style == null)) {
+ if (!isStyleable(styledRaster) || (isStyleable(styledRaster) && style == null)) {
colorModel = getColorModel(styledRaster);
}
+
+ RasterLegendData rasterLegendData = styledRaster.getLegendMetaData();
+ try {
+ rasterLegendData = generateRasterLegendData(style, false, null);
+ } catch (Exception e) {
+ // Keine Colormap?
+ return new JPanel();
+ }
- final RasterLegendData rasterLegendData = styledRaster
- .getLegendMetaData();
- final List<Double> legendRasterValues = rasterLegendData
- .getSortedKeys();
- final Map<Double, GridCoverage2D> sampleRasters = rasterLegendData
- .createSampleRasters();
+ final List<Double> legendRasterValues = rasterLegendData.getSortedKeys();
+ final Map<Double, GridCoverage2D> sampleRasters = rasterLegendData.createSampleRasters();
final JPanel panel = new JPanel(new MigLayout("wrap 2, gapy 0"));
- for (Double iteratorValue : legendRasterValues) {
+ for (Double rValue : legendRasterValues) {
- Double rValue = iteratorValue;
final Translation labelT = rasterLegendData.get(rValue);
// EMpty labels will not appear in a raster legend
@@ -1155,8 +1038,7 @@
// ****************************************************************************
// Create the actual icon
// ****************************************************************************
- final BufferedImage buffImage = new BufferedImage(iconWidth,
- iconHeight, BufferedImage.TYPE_INT_ARGB);
+ final BufferedImage buffImage = new BufferedImage(iconWidth, iconHeight, BufferedImage.TYPE_INT_ARGB);
final Graphics2D graphics = buffImage.createGraphics();
@@ -1192,8 +1074,7 @@
graphics.setColor(color);
graphics.fillRect(0, 0, iconWidth, iconHeight);
} catch (final Exception e) {
- LOGGER.info(
- "Dann nehmen wir halt den GridCoverageRenderer", e);
+ LOGGER.info("Dann nehmen wir halt den GridCoverageRenderer", e);
colorModel = null;
}
} else {
@@ -1207,21 +1088,17 @@
final GridCoverage2D sampleCov = sampleRasters.get(rValue);
GridCoverageRenderer renderer;
try {
- renderer = new GridCoverageRenderer(
- sampleCov.getCoordinateReferenceSystem(),
- JTSUtil.createEnvelope(sampleCov.getEnvelope()),
- new Rectangle(iconWidth, iconHeight),
+ renderer = new GridCoverageRenderer(sampleCov.getCoordinateReferenceSystem(),
+ JTSUtil.createEnvelope(sampleCov.getEnvelope()), new Rectangle(iconWidth, iconHeight),
(AffineTransform) null);
} catch (final Exception e1) {
- throw new RuntimeException(
- "Creating a GridCoverageRenderer failed:", e1);
+ throw new RuntimeException("Creating a GridCoverageRenderer failed:", e1);
}
/**
* Iterate over all FeatureTypeStyles.
*/
- final List<RasterSymbolizer> rSymbols = StylingUtil
- .getRasterSymbolizers(style);
+ final List<RasterSymbolizer> rSymbols = StylingUtil.getRasterSymbolizers(style);
for (final RasterSymbolizer symbolizer : rSymbols) {
try {
@@ -1230,17 +1107,13 @@
// er nur ein spezielles Band von mehreren darstellt,
// dann muss diese ChannelSelectino hier aufgehoiben
// werden, da die samleConverages nur ein Band haben.
- symbolizer
- .setChannelSelection(StylingUtil.STYLE_FACTORY
- .createChannelSelection(new SelectedChannelType[] { StylingUtil.STYLE_FACTORY
- .createSelectedChannelType(
- "1",
- (ContrastEnhancement) null) }));
+ symbolizer.setChannelSelection(StylingUtil.STYLE_FACTORY
+ .createChannelSelection(new SelectedChannelType[] { StylingUtil.STYLE_FACTORY
+ .createSelectedChannelType("1", (ContrastEnhancement) null) }));
renderer.paint(graphics, sampleCov, symbolizer);
} catch (final Exception ee) {
- LOGGER.error("Unable to paint " + symbolizer
- + " into the legend image", ee);
+ LOGGER.error("Unable to paint " + symbolizer + " into the legend image", ee);
}
}
}
@@ -1249,14 +1122,11 @@
panel.add(iconLabel, "sgx1");
final JLabel classTitleLabel = new JLabel(labelT.toString());
- panel.add(classTitleLabel, "sgx2"
- + (rasterLegendData.isPaintGaps() ? ", gapy 0:0:0 5:5:5"
- : ""));
+ panel.add(classTitleLabel, "sgx2" + (rasterLegendData.isPaintGaps() ? ", gapy 0:0:0 5:5:5" : ""));
classTitleLabel.setLabelFor(iconLabel);
if (rasterLegendData.isPaintGaps()) {
- iconLabel
- .setBorder(BorderFactory.createLineBorder(Color.black));
+ iconLabel.setBorder(BorderFactory.createLineBorder(Color.black));
}
}
@@ -1265,15 +1135,13 @@
}
/**
- * Creates a {@link JComponent} that contains a legend for a given
- * {@link StyledRasterInterface} and a given {@link Style}.
+ * Creates a {@link JComponent} that contains a legend for a given {@link StyledRasterInterface} and a given
+ * {@link Style}.
*
* @param style
- * if <code>null</code>, the default {@link Style} is extracetd
- * from the {@link StyledRasterInterface}
+ * if <code>null</code>, the default {@link Style} is extracetd from the {@link StyledRasterInterface}
*/
- public static JPanel OLDcreateLegendSwingPanel(
- final StyledRasterInterface<?> styledRaster, Style style,
+ public static JPanel OLDcreateLegendSwingPanel(final StyledRasterInterface<?> styledRaster, Style style,
final int iconWidth, final int iconHeight) {
// If no style is given, we use the default style for this layer
@@ -1284,17 +1152,13 @@
* Determine whether a Style is responsible for the coloring
*/
ColorModel colorModel = null;
- if (!isStyleable(styledRaster)
- || (isStyleable(styledRaster) && style == null)) {
+ if (!isStyleable(styledRaster) || (isStyleable(styledRaster) && style == null)) {
colorModel = getColorModel(styledRaster);
}
- final RasterLegendData rasterLegendData = styledRaster
- .getLegendMetaData();
- final List<Double> legendRasterValues = rasterLegendData
- .getSortedKeys();
- final Map<Double, GridCoverage2D> sampleRasters = rasterLegendData
- .createSampleRasters();
+ final RasterLegendData rasterLegendData = styledRaster.getLegendMetaData();
+ final List<Double> legendRasterValues = rasterLegendData.getSortedKeys();
+ final Map<Double, GridCoverage2D> sampleRasters = rasterLegendData.createSampleRasters();
final JPanel panel = new JPanel(new MigLayout("wrap 2, gapy 0"));
@@ -1315,8 +1179,7 @@
// ****************************************************************************
// Create the actual icon
// ****************************************************************************
- final BufferedImage buffImage = new BufferedImage(iconWidth,
- iconHeight, BufferedImage.TYPE_INT_ARGB);
+ final BufferedImage buffImage = new BufferedImage(iconWidth, iconHeight, BufferedImage.TYPE_INT_ARGB);
final Graphics2D graphics = buffImage.createGraphics();
@@ -1352,8 +1215,7 @@
graphics.setColor(color);
graphics.fillRect(0, 0, iconWidth, iconHeight);
} catch (final Exception e) {
- LOGGER.info(
- "Dann nehmen wir halt den GridCoverageRenderer", e);
+ LOGGER.info("Dann nehmen wir halt den GridCoverageRenderer", e);
colorModel = null;
}
} else {
@@ -1367,28 +1229,23 @@
final GridCoverage2D sampleCov = sampleRasters.get(rValue);
GridCoverageRenderer renderer;
try {
- renderer = new GridCoverageRenderer(
- sampleCov.getCoordinateReferenceSystem(),
- JTSUtil.createEnvelope(sampleCov.getEnvelope()),
- new Rectangle(iconWidth, iconHeight),
+ renderer = new GridCoverageRenderer(sampleCov.getCoordinateReferenceSystem(),
+ JTSUtil.createEnvelope(sampleCov.getEnvelope()), new Rectangle(iconWidth, iconHeight),
(AffineTransform) null);
} catch (final Exception e1) {
- throw new RuntimeException(
- "Creating a GridCoverageRenderer failed:", e1);
+ throw new RuntimeException("Creating a GridCoverageRenderer failed:", e1);
}
/**
* Iterate over all FeatureTypeStyles.
*/
- final List<RasterSymbolizer> rSymbols = StylingUtil
- .getRasterSymbolizers(style);
+ final List<RasterSymbolizer> rSymbols = StylingUtil.getRasterSymbolizers(style);
for (final RasterSymbolizer symbolizer : rSymbols) {
try {
renderer.paint(graphics, sampleCov, symbolizer);
} catch (final Exception ee) {
- LOGGER.error("Unable to paint " + symbolizer
- + " into the legend image", ee);
+ LOGGER.error("Unable to paint " + symbolizer + " into the legend image", ee);
}
}
}
@@ -1397,14 +1254,11 @@
panel.add(iconLabel, "sgx1");
final JLabel classTitleLabel = new JLabel(labelT.toString());
- panel.add(classTitleLabel, "sgx2"
- + (rasterLegendData.isPaintGaps() ? ", gapy 0:0:0 5:5:5"
- : ""));
+ panel.add(classTitleLabel, "sgx2" + (rasterLegendData.isPaintGaps() ? ", gapy 0:0:0 5:5:5" : ""));
classTitleLabel.setLabelFor(iconLabel);
if (rasterLegendData.isPaintGaps()) {
- iconLabel
- .setBorder(BorderFactory.createLineBorder(Color.black));
+ iconLabel.setBorder(BorderFactory.createLineBorder(Color.black));
}
}
@@ -1413,12 +1267,11 @@
}
/**
- * Extracts the {@link ColorModel} of any {@link StyledRasterInterface}. May
- * return <code>null</code> if the geoobject can not be accessed.
+ * Extracts the {@link ColorModel} of any {@link StyledRasterInterface}. May return <code>null</code> if the
+ * geoobject can not be accessed.
*/
@SuppressWarnings("unchecked")
- public static ColorModel getColorModel(
- final StyledRasterInterface<?> styledGrid) {
+ public static ColorModel getColorModel(final StyledRasterInterface<?> styledGrid) {
ColorModel colorModel = null;
try {
final Object geoObject = styledGrid.getGeoObject();
@@ -1427,21 +1280,18 @@
colorModel = cov.getRenderedImage().getColorModel();
} else if (styledGrid instanceof StyledGridCoverageReaderInterface) {
- final Parameter readGG = new Parameter(
- AbstractGridFormat.READ_GRIDGEOMETRY2D);
+ final Parameter readGG = new Parameter(AbstractGridFormat.READ_GRIDGEOMETRY2D);
- final ReferencedEnvelope mapExtend = new ReferencedEnvelope(
- styledGrid.getEnvelope(), styledGrid.getCrs());
+ final ReferencedEnvelope mapExtend = new ReferencedEnvelope(styledGrid.getEnvelope(),
+ styledGrid.getCrs());
- readGG.setValue(new GridGeometry2D(new GeneralGridEnvelope(
- new Rectangle(0, 0, 1, 1)), mapExtend));
+ readGG.setValue(new GridGeometry2D(new GeneralGridEnvelope(new Rectangle(0, 0, 1, 1)), mapExtend));
AbstractGridCoverage2DReader aReader;
if (geoObject instanceof FeatureCollection) {
final FeatureCollection<SimpleFeatureType, SimpleFeature> rFc = (FeatureCollection<SimpleFeatureType, SimpleFeature>) geoObject;
- aReader = (AbstractGridCoverage2DReader) FeatureUtil
- .getWrappedGeoObject(rFc);
+ aReader = (AbstractGridCoverage2DReader) FeatureUtil.getWrappedGeoObject(rFc);
} else if (geoObject instanceof AbstractGridCoverage2DReader) {
aReader = (AbstractGridCoverage2DReader) geoObject;
@@ -1450,8 +1300,7 @@
throw new RuntimeException("need a reader...");
//
- final GridCoverage2D cov = aReader
- .read(new GeneralParameterValue[] { readGG });
+ final GridCoverage2D cov = aReader.read(new GeneralParameterValue[] { readGG });
colorModel = cov.getRenderedImage().getColorModel();
}
} catch (final Exception e) {
@@ -1462,13 +1311,11 @@
}
/**
- * @return <code>true</code> if a {@link RasterSymbolizer} can be applied
- * and will have an effect. Some rasters (e.g. GeoTIFF) can come
- * with their own {@link ColorModel} and will ignore any
- * {@link RasterSymbolizer} = SLD.
+ * @return <code>true</code> if a {@link RasterSymbolizer} can be applied and will have an effect. Some rasters
+ * (e.g. GeoTIFF) can come with their own {@link ColorModel} and will ignore any {@link RasterSymbolizer} =
+ * SLD.
*/
- public static boolean isStyleable(
- final StyledRasterInterface<?> styledRaster) {
+ public static boolean isStyleable(final StyledRasterInterface<?> styledRaster) {
final ColorModel colorModel = getColorModel(styledRaster);
// LOGGER.info("The colormodel of " + styledRaster.getTitle() + " is "
@@ -1486,34 +1333,26 @@
}
/**
- * Set the given Style as the Style of the {@link MapLayer}, unless the
- * styles are the same (not comparing selection stuff). If the
- * {@link MapLayer}s {@link Style} is changed, the selection FTS is kept.<br/>
- * Remember {@link MapLayer#setStyle(Style)} triggers an event leading to a
- * repaint, so only use it when needed.
+ * Set the given Style as the Style of the {@link MapLayer}, unless the styles are the same (not comparing selection
+ * stuff). If the {@link MapLayer}s {@link Style} is changed, the selection FTS is kept.<br/>
+ * Remember {@link MapLayer#setStyle(Style)} triggers an event leading to a repaint, so only use it when needed.
*
- * @return <code>true</code> if the {@link MapLayer}'s {@link Style} has
- * been changed.
+ * @return <code>true</code> if the {@link MapLayer}'s {@link Style} has been changed.
*/
- public static boolean updateMapLayerStyleIfChangedAndKeepSelection(
- MapLayer mapLayer, Style style2) {
+ public static boolean updateMapLayerStyleIfChangedAndKeepSelection(MapLayer mapLayer, Style style2) {
- Style mapLayerStyleCleaned = StylingUtil
- .removeSelectionFeatureTypeStyle(mapLayer.getStyle());
+ Style mapLayerStyleCleaned = StylingUtil.removeSelectionFeatureTypeStyle(mapLayer.getStyle());
- Style newStyleCleaned = StylingUtil
- .removeSelectionFeatureTypeStyle(style2);
+ Style newStyleCleaned = StylingUtil.removeSelectionFeatureTypeStyle(style2);
if (StylingUtil.isStyleDifferent(mapLayerStyleCleaned, newStyleCleaned)) {
// They are different when compared without SELECTION FTS!
// Now let's copy any SELECTION FTS to the now style
- FeatureTypeStyle selectionFeatureTypeStyle = StylingUtil
- .getSelectionFeatureTypeStyle(mapLayer.getStyle());
+ FeatureTypeStyle selectionFeatureTypeStyle = StylingUtil.getSelectionFeatureTypeStyle(mapLayer.getStyle());
if (selectionFeatureTypeStyle != null) {
- newStyleCleaned.featureTypeStyles().add(
- selectionFeatureTypeStyle);
+ newStyleCleaned.featureTypeStyles().add(selectionFeatureTypeStyle);
// newStyleCleaned is not so clean anymore... We just alled a
// selcetion FTS
}
@@ -1528,18 +1367,15 @@
}
/**
- * After loading an atlas, the AttribteMetaData contains whatever is written
- * in the XML. But the DBF may have changed! This method checks an
- * {@link AttributeMetadataMap} against a schema and also corrects
- * upperCase/lowerCase problems. It will also remove any geometry column
- * attribute metadata.
+ * After loading an atlas, the AttribteMetaData contains whatever is written in the XML. But the DBF may have
+ * changed! This method checks an {@link AttributeMetadataMap} against a schema and also corrects
+ * upperCase/lowerCase problems. It will also remove any geometry column attribute metadata.
*/
/**
- * After loading an atlas, the AttribteMetaData contains whatever is written
- * in the XML. But the DBF may have changed!
+ * After loading an atlas, the AttribteMetaData contains whatever is written in the XML. But the DBF may have
+ * changed!
*/
- public static void checkAttribMetaData(
- AttributeMetadataMap<AttributeMetadataImpl> attributeMetaDataMap,
+ public static void checkAttribMetaData(AttributeMetadataMap<AttributeMetadataImpl> attributeMetaDataMap,
SimpleFeatureType schema) {
if (schema == null)
@@ -1552,11 +1388,9 @@
for (AttributeMetadataInterface atm : attributeMetaDataMap.values()) {
- AttributeDescriptor foundDescr = schema
- .getDescriptor(atm.getName());
+ AttributeDescriptor foundDescr = schema.getDescriptor(atm.getName());
if (foundDescr == null) {
- NameImpl bestMatch = FeatureUtil.findBestMatchingAttribute(
- schema, atm.getLocalName());
+ NameImpl bestMatch = FeatureUtil.findBestMatchingAttribute(schema, atm.getLocalName());
if (bestMatch == null)
willRemove.add(atm.getName());
else
@@ -1579,39 +1413,33 @@
if (ad instanceof GeometryDescriptor)
continue;
if (!attributeMetaDataMap.containsKey(ad.getName())) {
- attributeMetaDataMap.put(new NameImpl(ad.getName()
- .getNamespaceURI(), ad.getName().getLocalPart()),
- new AttributeMetadataImpl(ad, schema
- .getAttributeDescriptors().indexOf(ad),
+ attributeMetaDataMap.put(new NameImpl(ad.getName().getNamespaceURI(), ad.getName().getLocalPart()),
+ new AttributeMetadataImpl(ad, schema.getAttributeDescriptors().indexOf(ad),
attributeMetaDataMap.getLanguages()));
}
}
}
/**
- * Checks every attribute name in the {@link AttributeMetadataMap} for its
- * binding type. It the type is textual, add the mrpty string as a NODATA
- * value.
+ * Checks every attribute name in the {@link AttributeMetadataMap} for its binding type. It the type is textual, add
+ * the mrpty string as a NODATA value.
*
* @param attributeMetaDataMap
* @param schema
*/
public static void addEmptyStringToAllTextualAttributes(
- AttributeMetadataMap<? extends AttributeMetadataInterface> attributeMetaDataMap,
- SimpleFeatureType schema) {
+ AttributeMetadataMap<? extends AttributeMetadataInterface> attributeMetaDataMap, SimpleFeatureType schema) {
for (Name name : attributeMetaDataMap.keySet()) {
- if (String.class.isAssignableFrom(schema.getDescriptor(name)
- .getType().getBinding())) {
+ if (String.class.isAssignableFrom(schema.getDescriptor(name).getType().getBinding())) {
attributeMetaDataMap.get(name).getNodataValues().add("");
}
}
}
/**
- * @return a nicely formatted String containing all NODATA values of any
- * {@link AttributeMetadataInterface} object. Strings are quoted so
- * that any empty {@link String} can be seen.
+ * @return a nicely formatted String containing all NODATA values of any {@link AttributeMetadataInterface} object.
+ * Strings are quoted so that any empty {@link String} can be seen.
*/
public static String formatNoDataValues(Set<Object> nodataValuesList) {
String nicelyFormatted = "";
@@ -1628,20 +1456,17 @@
nicelyFormatted += ",";
}
// Remove the extra comma
- nicelyFormatted = nicelyFormatted.substring(0,
- nicelyFormatted.length() - 1);
+ nicelyFormatted = nicelyFormatted.substring(0, nicelyFormatted.length() - 1);
}
}
return nicelyFormatted;
}
/**
- * Creates a new {@link AttributeMetadataMap} with instances of
- * {@link AttributeMetadataInterface} for every non-geometry attribute.
- * Default NODATA values (like "" for String) are set.
+ * Creates a new {@link AttributeMetadataMap} with instances of {@link AttributeMetadataInterface} for every
+ * non-geometry attribute. Default NODATA values (like "" for String) are set.
*/
- public static AttributeMetadataMap<AttributeMetadataImpl> createDefaultAttributeMetadataMap(
- SimpleFeatureType schema) {
+ public static AttributeMetadataMap<AttributeMetadataImpl> createDefaultAttributeMetadataMap(SimpleFeatureType schema) {
AttributeMetadataImplMap attMap = new AttributeMetadataImplMap();
for (int i = 0; i < schema.getAttributeCount(); i++) {
@@ -1654,9 +1479,8 @@
// TODO AttributeMetadataAS would be nicer, which would not work
// with Translations ;-)
- AttributeMetadataImpl attMetaData = new AttributeMetadataImpl(
- new NameImpl(attDesc.getName().getNamespaceURI(), attDesc
- .getName().getLocalPart()), attMap.getLanguages());
+ AttributeMetadataImpl attMetaData = new AttributeMetadataImpl(new NameImpl(attDesc.getName()
+ .getNamespaceURI(), attDesc.getName().getLocalPart()), attMap.getLanguages());
if (String.class.isAssignableFrom(attDesc.getType().getBinding())) {
// For Strings we add the "" as NODATA values
@@ -1669,30 +1493,25 @@
}
/**
- * Returns <code>true</code> is changing the zoom from oldScaleDenominator
- * to newScaleDenominator would result in a another styling.
+ * Returns <code>true</code> is changing the zoom from oldScaleDenominator to newScaleDenominator would result in a
+ * another styling.
*
* TODO This is not evaluating the AtlasStlyer diabled classes Filters yet!
*/
- public static boolean hasScalechangeAnyEffect(Style style,
- double oldScaleDenominator, double newScaleDenominator) {
+ public static boolean hasScalechangeAnyEffect(Style style, double oldScaleDenominator, double newScaleDenominator) {
for (FeatureTypeStyle fts : style.featureTypeStyles()) {
for (Rule r : fts.rules()) {
double minScale = r.getMinScaleDenominator();
double maxScale = r.getMaxScaleDenominator();
- if (oldScaleDenominator < minScale
- && newScaleDenominator >= minScale)
+ if (oldScaleDenominator < minScale && newScaleDenominator >= minScale)
return true;
- if (oldScaleDenominator >= minScale
- && newScaleDenominator < minScale)
+ if (oldScaleDenominator >= minScale && newScaleDenominator < minScale)
return true;
- if (oldScaleDenominator < maxScale
- && newScaleDenominator >= maxScale)
+ if (oldScaleDenominator < maxScale && newScaleDenominator >= maxScale)
return true;
- if (oldScaleDenominator >= maxScale
- && newScaleDenominator < maxScale)
+ if (oldScaleDenominator >= maxScale && newScaleDenominator < maxScale)
return true;
}
}
More information about the Schmitzm-commits
mailing list