[Schmitzm-commits] r88 - trunk/src/schmitzm/geotools/styling
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Thu Apr 23 21:40:18 CEST 2009
Author: alfonx
Date: 2009-04-23 21:40:16 +0200 (Thu, 23 Apr 2009)
New Revision: 88
Modified:
trunk/src/schmitzm/geotools/styling/StylingUtil.java
Log:
* SORRY! I did make real changes in StyingUtil, but sadly (bad habit?!) auto-formatted the source. mea culpa
Modified: trunk/src/schmitzm/geotools/styling/StylingUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/styling/StylingUtil.java 2009-04-23 19:39:13 UTC (rev 87)
+++ trunk/src/schmitzm/geotools/styling/StylingUtil.java 2009-04-23 19:40:16 UTC (rev 88)
@@ -23,6 +23,7 @@
import java.lang.reflect.Array;
import java.net.URL;
import java.nio.charset.Charset;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -87,480 +88,550 @@
/**
* Diese Klasse enthaelt Hilfsfunktionen zum GeoTools-Styling
- *
- * @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)
* @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Krüger</a>
- *
+ *
* @version 1.1
*/
public class StylingUtil {
- private static final Logger LOGGER = Logger.getLogger(StylingUtil.class);
- /** Transparente Farbe */
- public static final Color TRANSPARENT_COLOR = new Color(0,0,0,0);
+ private static final Logger LOGGER = Logger.getLogger(StylingUtil.class);
+ /** Transparente Farbe */
+ public static final Color TRANSPARENT_COLOR = new Color(0, 0, 0, 0);
- /** Standard-Instanz eines {@link StyleBuilder}. */
- public static final StyleBuilder STYLE_BUILDER = new StyleBuilder();
- /** Standard-Instanz eines {@link StyleBuilder}.
- * @deprecated wurde ersetzt durch {@link #STYLE_BUILDER} */
- public static final StyleBuilder builder = STYLE_BUILDER;
+ /** Standard-Instanz eines {@link StyleBuilder}. */
+ public static final StyleBuilder STYLE_BUILDER = new StyleBuilder();
+ /**
+ * Standard-Instanz eines {@link StyleBuilder}.
+ *
+ * @deprecated wurde ersetzt durch {@link #STYLE_BUILDER}
+ */
+ public static final StyleBuilder builder = STYLE_BUILDER;
- /** Standard-Instanz einer {@link StyleFactory} */
- public static final StyleFactory STYLE_FACTORY = CommonFactoryFinder.getStyleFactory( new Hints( new HashMap()));
- /** Standard-Instanz einer {@link StyleFactory}
- * @deprecated wurde ersetzt durch {@link #STYLE_FACTORY} */
- public static final StyleFactory styleFactory = STYLE_FACTORY;
+ /** Standard-Instanz einer {@link StyleFactory} */
+ public static final StyleFactory STYLE_FACTORY = CommonFactoryFinder
+ .getStyleFactory(new Hints(new HashMap()));
+ /**
+ * Standard-Instanz einer {@link StyleFactory}
+ *
+ * @deprecated wurde ersetzt durch {@link #STYLE_FACTORY}
+ */
+ public static final StyleFactory styleFactory = STYLE_FACTORY;
- /**
- * Erstellt einen Default-Style fuer ein Geo-Objekt.
- * @param object {@link GridCoverage2D}, {@link org.geotools.coverage.grid.io.AbstractGridCoverage2DReader} oder
- * {@link FeatureCollection}
- * @return {@code null} falls kein Style generiert werden kann
- *
- */
- public static Style createDefaultStyle(Object object) {
- Style style = STYLE_FACTORY.createStyle(); //SK.. nicer default than null !
+ /**
+ * Erstellt einen Default-Style fuer ein Geo-Objekt.
+ *
+ * @param object
+ * {@link GridCoverage2D},
+ * {@link org.geotools.coverage.grid.io.AbstractGridCoverage2DReader}
+ * oder {@link FeatureCollection}
+ * @return {@code null} falls kein Style generiert werden kann
+ *
+ */
+ public static Style createDefaultStyle(Object object) {
+ Style style = STYLE_FACTORY.createStyle(); // SK.. nicer default than
+ // null !
- if ( object instanceof GridCoverage2D || object instanceof org.geotools.coverage.grid.io.AbstractGridCoverage2DReader )
- style = GridUtil.createDefaultStyle();
+ if (object instanceof GridCoverage2D
+ || object instanceof org.geotools.coverage.grid.io.AbstractGridCoverage2DReader)
+ style = GridUtil.createDefaultStyle();
- if ( object instanceof FeatureCollection )
- style = FeatureUtil.createDefaultStyle( (FeatureCollection)object );
+ if (object instanceof FeatureCollection)
+ style = FeatureUtil.createDefaultStyle((FeatureCollection) object);
- // SK.cb
- if (object instanceof GeometryAttributeType)
- style = FeatureUtil.createDefaultStyle( (GeometryAttributeType)object );
+ // SK.cb
+ if (object instanceof GeometryAttributeType)
+ style = FeatureUtil
+ .createDefaultStyle((GeometryAttributeType) object);
- if (object instanceof FeatureSource)
- style = FeatureUtil.createDefaultStyle( ((FeatureSource)object).getSchema().getDefaultGeometry() );
- // SK.ce
+ if (object instanceof FeatureSource)
+ style = FeatureUtil.createDefaultStyle(((FeatureSource) object)
+ .getSchema().getDefaultGeometry());
+ // SK.ce
- return style;
- }
+ return style;
+ }
- /**
- * Erzeugt eine {@link Category} fuer die NoData-Werte transparent dargestellt
- * werden.
- * @param geoValue Geo-Wert, der NoData repraesentiert
- */
- public static Category createNoDataCategory(double geoValue) {
- return createNoDataCategory(0, geoValue);
- }
+ /**
+ * Erzeugt eine {@link Category} fuer die NoData-Werte transparent
+ * dargestellt werden.
+ *
+ * @param geoValue
+ * Geo-Wert, der NoData repraesentiert
+ */
+ public static Category createNoDataCategory(double geoValue) {
+ return createNoDataCategory(0, geoValue);
+ }
- /**
- * Erzeugt eine {@link Category} fuer die NoData-Werte transparent dargestellt
- * werden.
- * @param value Sample-Wert der Category
- * @param geoValue Geo-Wert, der NoData repraesentiert
- */
- public static Category createNoDataCategory(int value, double geoValue) {
- return new Category(
- Vocabulary.formatInternational(VocabularyKeys.NODATA),
- new Color[] { new Color(0,0,0,0) },
- new NumberRange(value, value),
- new NumberRange(geoValue, geoValue)
- );
- }
+ /**
+ * Erzeugt eine {@link Category} fuer die NoData-Werte transparent
+ * dargestellt werden.
+ *
+ * @param value
+ * Sample-Wert der Category
+ * @param geoValue
+ * Geo-Wert, der NoData repraesentiert
+ */
+ public static Category createNoDataCategory(int value, double geoValue) {
+ return new Category(Vocabulary
+ .formatInternational(VocabularyKeys.NODATA),
+ new Color[] { new Color(0, 0, 0, 0) }, new NumberRange(value,
+ value), new NumberRange(geoValue, geoValue));
+ }
- /**
- * Erzeugt eine {@link GridSampleDimension} aus einer {@link ColorMap}.
- * @param name Name fuer die {@link GridSampleDimension}
- * @param colorMap fuer jeden Eintrag der {@link ColorMap} wird eine
- * {@link Category} erzeugt
- * @param noDataValues Werte fuer die zusaetzliche {@link Category Categorys}
- * erstellt werden, welche die transparent dargestellt
- * werden (wenn {@code null} wird keine zusaetzliche
- * {@link Category} erstellt)
- * @param unit Einheit der Werte in der {@link GridSampleDimension}
- * (kann {@code null} sein)
- */
- public static GridSampleDimension createDiscreteGridSampleDimension(String name, ColorMap colorMap, double[] noDataValues, Unit unit) {
- if ( colorMap.getColorMapEntries().length == 0 )
- return null;
+ /**
+ * Erzeugt eine {@link GridSampleDimension} aus einer {@link ColorMap}.
+ *
+ * @param name
+ * Name fuer die {@link GridSampleDimension}
+ * @param colorMap
+ * fuer jeden Eintrag der {@link ColorMap} wird eine
+ * {@link Category} erzeugt
+ * @param noDataValues
+ * Werte fuer die zusaetzliche {@link Category Categorys}
+ * erstellt werden, welche die transparent dargestellt werden
+ * (wenn {@code null} wird keine zusaetzliche {@link Category}
+ * erstellt)
+ * @param unit
+ * Einheit der Werte in der {@link GridSampleDimension} (kann
+ * {@code null} sein)
+ */
+ public static GridSampleDimension createDiscreteGridSampleDimension(
+ String name, ColorMap colorMap, double[] noDataValues, Unit unit) {
+ if (colorMap.getColorMapEntries().length == 0)
+ return null;
- SortedMap<Integer,Category> categories = new TreeMap<Integer,Category>();
- if ( noDataValues == null )
- noDataValues = new double[0];
+ SortedMap<Integer, Category> categories = new TreeMap<Integer, Category>();
+ if (noDataValues == null)
+ noDataValues = new double[0];
- // Create a (discrete) Category for each ColorMapEntry
- int colorMapMin = Integer.MAX_VALUE;
- int colorMapMax = Integer.MIN_VALUE;
- for (ColorMapEntry cme : colorMap.getColorMapEntries()) {
- String label = cme.getLabel();
- Color color = getColorFromColorMapEntry(cme);
- double value = getQuantityFromColorMapEntry(cme);
- int intValue = (int)Math.round(value);
- colorMapMin = Math.min(colorMapMin, intValue);
- colorMapMax = Math.max(colorMapMax, intValue);
-// if ( label == null || label.trim().equals("") )
-// label = String.valueOf(intValue);
- if ( label == null )
- label = "";
- categories.put(intValue, new Category(
- label,
- new Color[] {color},
- new NumberRange(intValue, intValue),
- new NumberRange(intValue, intValue)
- ));
- }
+ // Create a (discrete) Category for each ColorMapEntry
+ int colorMapMin = Integer.MAX_VALUE;
+ int colorMapMax = Integer.MIN_VALUE;
+ for (ColorMapEntry cme : colorMap.getColorMapEntries()) {
+ String label = cme.getLabel();
+ Color color = getColorFromColorMapEntry(cme);
+ double value = getQuantityFromColorMapEntry(cme);
+ int intValue = (int) Math.round(value);
+ colorMapMin = Math.min(colorMapMin, intValue);
+ colorMapMax = Math.max(colorMapMax, intValue);
+ // if ( label == null || label.trim().equals("") )
+ // label = String.valueOf(intValue);
+ if (label == null)
+ label = "";
+ categories.put(intValue, new Category(label, new Color[] { color },
+ new NumberRange(intValue, intValue), new NumberRange(
+ intValue, intValue)));
+ }
+ // If NoData-Value is set, create an additional Category
+ for (double noDataValue : noDataValues) {
+ int value = categories.lastKey() + 10; // value not already used
+ categories.put(value, createNoDataCategory(value, noDataValue));
+ colorMapMin = Math.min(colorMapMin, (int) noDataValue);
+ colorMapMax = Math.max(colorMapMax, (int) noDataValue);
+ }
- // If NoData-Value is set, create an additional Category
- for (double noDataValue : noDataValues ) {
- int value = categories.lastKey() + 10; // value not already used
- categories.put(value, createNoDataCategory(value, noDataValue));
- colorMapMin = Math.min(colorMapMin, (int)noDataValue);
- colorMapMax = Math.max(colorMapMax, (int)noDataValue);
- }
+ // Declare "all" values smaller/greater the color map values
+ // automatically as NoData
+ // int colorMapRange = colorMapMax - colorMapMin;
+ // double lowerStart = colorMapMin - 10000*colorMapRange;
+ // double higherEnd = colorMapMax + 10000*colorMapRange;
+ final int lowerStart = Integer.MIN_VALUE;
+ final int higherEnd = Integer.MAX_VALUE;
+ categories.put(colorMapMax + 10, new Category("_autoNoData1_",
+ new Color[] { new Color(0, 0, 0, 0) }, new NumberRange(
+ colorMapMax + 1, colorMapMax + 2), new NumberRange(
+ colorMapMax + 1, higherEnd)));
+ if (colorMapMin < colorMapMax)
+ categories.put(colorMapMin - 10, new Category(
+ "_autoNoData2_",
+ new Color[] { new Color(0, 0, 0, 0) },
+ // new NumberRange(colorMapMin-2, colorMapMin-1), //
+ // logischer, aber klappt nicht!?
+ new NumberRange(colorMapMax + 3, colorMapMax + 4),
+ new NumberRange(lowerStart, colorMapMin - 1)));
- // Declare "all" values smaller/greater the color map values
- // automatically as NoData
- //int colorMapRange = colorMapMax - colorMapMin;
- //double lowerStart = colorMapMin - 10000*colorMapRange;
- //double higherEnd = colorMapMax + 10000*colorMapRange;
- final int lowerStart = Integer.MIN_VALUE;
- final int higherEnd = Integer.MAX_VALUE;
- categories.put(colorMapMax+10, new Category(
- "_autoNoData1_",
- new Color[] { new Color(0,0,0,0) },
- new NumberRange(colorMapMax+1, colorMapMax+2),
- new NumberRange(colorMapMax+1, higherEnd)
- ));
- if ( colorMapMin < colorMapMax )
- categories.put(colorMapMin-10, new Category(
- "_autoNoData2_",
- new Color[] { new Color(0,0,0,0) },
- //new NumberRange(colorMapMin-2, colorMapMin-1), // logischer, aber klappt nicht!?
- new NumberRange(colorMapMax+3, colorMapMax+4),
- new NumberRange(lowerStart, colorMapMin-1)
- ));
+ // Create the GridSampleDimension
+ GridSampleDimension gsd = new GridSampleDimension(name, categories
+ .values().toArray(new Category[0]), unit).geophysics(true);
+ for (Category c : (List<Category>) gsd.getCategories())
+ LOGGER.debug(c.toString());
+ return gsd;
+ }
- // Create the GridSampleDimension
- GridSampleDimension gsd = new GridSampleDimension(
- name,
- categories.values().toArray(new Category[0]),
- unit
- ).geophysics(true);
+ /**
+ * Liefert die Farbpalette zu einem Style, wenn der Style aus einem
+ * {@link RasterSymbolizer} erzeugt wurde.
+ *
+ * @param style
+ * Style Wenn <code>null</code>, dann wird style auf
+ * {@link GridUtil}.createDefaultStyle() gesetzt
+ * @return <code>null</code> wenn der Style nicht auf einem
+ * {@link RasterSymbolizer} basiert.
+ */
+ public static ColorMap getColorMapFromStyle(Style style) {
- for ( Category c : (List<Category>)gsd.getCategories() )
- LOGGER.debug( c.toString() );
+ if (style == null)
+ style = GridUtil.createDefaultStyle();
- return gsd;
- }
+ FeatureTypeStyle[] fts = style.getFeatureTypeStyles();
+ if (fts == null || fts.length == 0)
+ return null;
+ Rule[] rule = fts[0].getRules();
+ if (rule == null || rule.length == 0)
+ return null;
+ Symbolizer[] symb = rule[0].getSymbolizers();
+ if (symb == null || symb.length == 0
+ || !(symb[0] instanceof RasterSymbolizer))
+ return null;
+ return ((RasterSymbolizer) symb[0]).getColorMap();
- /**
- * Liefert die Farbpalette zu einem Style, wenn der Style aus einem
- * {@link RasterSymbolizer} erzeugt wurde.
- * @param style Style Wenn <code>null</code>, dann wird style auf {@link GridUtil}.createDefaultStyle() gesetzt
- * @return <code>null</code> wenn der Style nicht auf einem {@link RasterSymbolizer}
- * basiert.
- */
- public static ColorMap getColorMapFromStyle(Style style) {
+ }
- if (style == null)
- style = GridUtil.createDefaultStyle();
+ /**
+ * Ermittelt fuer einen Wert den {@link ColorMapEntry} aus einer
+ * {@link ColorMap}.
+ *
+ * @param value
+ * Wert
+ * @return {@code null}, wenn in der {@link ColorMap} kein expliziter
+ * Eintrag fuer den Wert hinterlegt ist
+ */
+ public static ColorMapEntry findColorMapEntry(ColorMap colorMap,
+ double value) {
+ for (ColorMapEntry entry : colorMap.getColorMapEntries())
+ if (value == getQuantityFromColorMapEntry(entry))
+ return entry;
+ return null;
+ }
- FeatureTypeStyle[] fts = style.getFeatureTypeStyles();
- if ( fts == null || fts.length == 0 )
- return null;
- Rule[] rule = fts[0].getRules();
- if ( rule == null || rule.length == 0 )
- return null;
- Symbolizer[] symb = rule[0].getSymbolizers();
- if ( symb == null || symb.length == 0 || !(symb[0] instanceof RasterSymbolizer) )
- return null;
- return ((RasterSymbolizer)symb[0]).getColorMap();
+ /**
+ * Kopiert eine {@link ColorMap}.
+ *
+ * @return <code>null</code> wenn die uebergebene ColorMap <code>null</code>
+ * ist
+ */
+ public static ColorMap cloneColorMap(ColorMap colorMap) {
+ if (colorMap == null)
+ return null;
+ ColorMapEntry[] entry = colorMap.getColorMapEntries();
+ ColorMap newColorMap = new ColorMapImpl();
+ newColorMap.setType(colorMap.getType()); // Hat noch keinen Effekt in
+ // 2.3.2, aber dennoch, SK
+ for (int i = 0; i < entry.length; i++)
+ newColorMap.addColorMapEntry(cloneColorMapEntry(entry[i]));
+ return newColorMap;
+ }
- }
+ /**
+ * Prueft, ob zwei {@link ColorMap}-Instanzen gleich sind.
+ *
+ * @param cm1
+ * eine Farbpalette
+ * @param cm2
+ * eine andere Farbpalette
+ */
+ public static boolean colorMapsEqual(ColorMap cm1, ColorMap cm2) {
+ if (cm1 == null ^ cm2 == null)
+ return false;
+ if (cm1 == cm2)
+ return true;
- /**
- * Ermittelt fuer einen Wert den {@link ColorMapEntry} aus einer
- * {@link ColorMap}.
- * @param value Wert
- * @return {@code null}, wenn in der {@link ColorMap} kein expliziter
- * Eintrag fuer den Wert hinterlegt ist
- */
- public static ColorMapEntry findColorMapEntry(ColorMap colorMap, double value) {
- for (ColorMapEntry entry : colorMap.getColorMapEntries())
- if ( value == getQuantityFromColorMapEntry(entry) )
- return entry;
- return null;
- }
+ ColorMapEntry[] cme1 = cm1.getColorMapEntries();
+ ColorMapEntry[] cme2 = cm2.getColorMapEntries();
+ if (cme1.length != cme2.length)
+ return false;
- /**
- * Kopiert eine {@link ColorMap}.
- * @return <code>null</code> wenn die uebergebene ColorMap <code>null</code>
- * ist
- */
- public static ColorMap cloneColorMap(ColorMap colorMap) {
- if ( colorMap == null )
- return null;
- ColorMapEntry[] entry = colorMap.getColorMapEntries();
- ColorMap newColorMap = new ColorMapImpl();
- newColorMap.setType( colorMap.getType() ); // Hat noch keinen Effekt in 2.3.2, aber dennoch, SK
- for (int i=0; i<entry.length; i++)
- newColorMap.addColorMapEntry( cloneColorMapEntry(entry[i]) );
- return newColorMap;
- }
+ // Farbpaletten-Eintraege muessen gleich sein und in gleicher
+ // Reihenfolge vorliegen!
+ for (int i = 0; i < cme1.length; i++)
+ if (!colorMapEntriesEqual(cme1[i], cme2[i]))
+ return false;
+ return true;
+ }
- /**
- * Prueft, ob zwei {@link ColorMap}-Instanzen gleich sind.
- * @param cm1 eine Farbpalette
- * @param cm2 eine andere Farbpalette
- */
- public static boolean colorMapsEqual(ColorMap cm1, ColorMap cm2) {
- if ( cm1 == null ^ cm2 == null )
- return false;
- if ( cm1 == cm2 )
- return true;
+ /**
+ * Prueft, ob zwei {@link 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.
+ *
+ * @param cme1
+ * ein Farbpaletten-Eintrag
+ * @param cme2
+ * ein anderer Farbpaletten-Eintrag
+ */
+ public static boolean colorMapEntriesEqual(ColorMapEntry cme1,
+ ColorMapEntry cme2) {
+ if (cme1 == null ^ cme2 == null)
+ return false;
+ if (cme1 == cme2)
+ return true;
- ColorMapEntry[] cme1 = cm1.getColorMapEntries();
- ColorMapEntry[] cme2 = cm2.getColorMapEntries();
- if ( cme1.length != cme2.length )
- return false;
+ // Label auf Gleichheit testen
+ if (cme1.getLabel() == null ^ cme2.getLabel() == null || cme1 != null
+ && !cme1.getLabel().equals(cme2.getLabel()))
+ return false;
+ // Farbe auf Gleichheit testen
+ Color col1 = getColorFromColorMapEntry(cme1);
+ Color col2 = getColorFromColorMapEntry(cme2);
+ if (col1 == null ^ col2 == null || col1 != null && !col1.equals(col2))
+ return false;
+ // Wert auf Gleichheit testen
+ Double quan1 = getQuantityFromColorMapEntry(cme1);
+ Double quan2 = getQuantityFromColorMapEntry(cme2);
+ if (quan1 == null ^ quan2 == null || quan1 != null
+ && !quan1.equals(quan2))
+ return false;
+ // Transparenz auf Gleichheit testen
+ Double op1 = getOpacityFromColorMapEntry(cme1);
+ Double op2 = getOpacityFromColorMapEntry(cme2);
+ if (op1 == null ^ op2 == null || op1 != null && !op1.equals(op2))
+ return false;
- // Farbpaletten-Eintraege muessen gleich sein und in gleicher
- // Reihenfolge vorliegen!
- for (int i=0; i<cme1.length; i++)
- if ( !colorMapEntriesEqual(cme1[i],cme2[i]) )
- return false;
- return true;
- }
+ return true;
+ }
- /**
- * Prueft, ob zwei {@link 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.
- * @param cme1 ein Farbpaletten-Eintrag
- * @param cme2 ein anderer Farbpaletten-Eintrag
- */
- public static boolean colorMapEntriesEqual(ColorMapEntry cme1, ColorMapEntry cme2) {
- if ( cme1 == null ^ cme2 == null )
- return false;
- if ( cme1 == cme2 )
- return true;
+ /**
+ * Erzeugt einen {@link ColorMapEntry}.
+ *
+ * @param label
+ * Label fuer den Farbpaletten-Eintrag
+ * @param quantity
+ * Wert fuer den Farbpaletten-Eintrag
+ * @param color
+ * Farbe fuer den Farbpaletten-Eintrag
+ * @param opacity
+ * Transparenz fuer die Farbe des Farbpaletten-Eintrag
+ */
+ public static ColorMapEntry createColorMapEntry(String label,
+ Double quantity, Color color, double opacity) {
+ ColorMapEntry newEntry = new ColorMapEntryImpl();
+ try {
+ newEntry.setLabel(label);
+ newEntry.setColor(STYLE_BUILDER.colorExpression(color));
+ newEntry.setOpacity(STYLE_BUILDER.literalExpression(opacity));
+ newEntry.setQuantity(STYLE_BUILDER.literalExpression(quantity));
+ } catch (Exception err) {
+ }
+ return newEntry;
+ }
- // Label auf Gleichheit testen
- if ( cme1.getLabel() == null ^ cme2.getLabel() == null ||
- cme1 != null && !cme1.getLabel().equals( cme2.getLabel() ) )
- return false;
- // Farbe auf Gleichheit testen
- Color col1 = getColorFromColorMapEntry(cme1);
- Color col2 = getColorFromColorMapEntry(cme2);
- if ( col1 == null ^ col2 == null ||
- col1 != null && !col1.equals( col2 ) )
- return false;
- // Wert auf Gleichheit testen
- Double quan1 = getQuantityFromColorMapEntry(cme1);
- Double quan2 = getQuantityFromColorMapEntry(cme2);
- if ( quan1 == null ^ quan2 == null ||
- quan1 != null && !quan1.equals( quan2 ) )
- return false;
- // Transparenz auf Gleichheit testen
- Double op1 = getOpacityFromColorMapEntry(cme1);
- Double op2 = getOpacityFromColorMapEntry(cme2);
- if ( op1 == null ^ op2 == null ||
- op1 != null && !op1.equals( op2 ) )
- return false;
+ /**
+ * Kopiert einen {@link ColorMapEntry}.
+ *
+ * @return <code>null</code> wenn der uebergebene ColorMapEntry
+ * <code>null</code> ist
+ */
+ public static ColorMapEntry cloneColorMapEntry(ColorMapEntry colorMapEntry) {
+ if (colorMapEntry == null)
+ return null;
- return true;
- }
+ return createColorMapEntry(colorMapEntry.getLabel(),
+ getQuantityFromColorMapEntry(colorMapEntry),
+ getColorFromColorMapEntry(colorMapEntry),
+ getOpacityFromColorMapEntry(colorMapEntry));
+ }
+ /**
+ * Liefert den Wert eines Farbpaletten-Eintrag.
+ *
+ * @param expression
+ * Expression, die einen String oder einen Double liefert
+ * @return {@code null}, wenn <code>null</code> uebergeben wird
+ */
+ public static Double getQuantityFromExpression(Expression expression) {
+ // gt2-2.3.4:
+ // if ( expression == null || expression.getValue(null) == null )
+ // return null
+ // Object exprValue = evaluate.getValue(null);
+ // gt2-2.3.4:
+ if (expression == null || expression.evaluate(null) == null)
+ return null;
+ Object exprValue = expression.evaluate(null);
- /**
- * Erzeugt einen {@link ColorMapEntry}.
- * @param label Label fuer den Farbpaletten-Eintrag
- * @param quantity Wert fuer den Farbpaletten-Eintrag
- * @param color Farbe fuer den Farbpaletten-Eintrag
- * @param opacity Transparenz fuer die Farbe des Farbpaletten-Eintrag
- */
- public static ColorMapEntry createColorMapEntry(String label, Double quantity, Color color, double opacity) {
- ColorMapEntry newEntry = new ColorMapEntryImpl();
- try {
- newEntry.setLabel( label );
- newEntry.setColor( STYLE_BUILDER.colorExpression( color ) );
- newEntry.setOpacity( STYLE_BUILDER.literalExpression( opacity ) );
- newEntry.setQuantity( STYLE_BUILDER.literalExpression( quantity ) );
- } catch (Exception err) {
- }
- return newEntry;
- }
+ return (exprValue instanceof String) ? Double
+ .valueOf((String) exprValue) : ((Number) exprValue)
+ .doubleValue();
+ }
- /**
- * Kopiert einen {@link ColorMapEntry}.
- * @return <code>null</code> wenn der uebergebene ColorMapEntry <code>null</code>
- * ist
- */
- public static ColorMapEntry cloneColorMapEntry(ColorMapEntry colorMapEntry) {
- if ( colorMapEntry == null )
- return null;
+ /**
+ * Liefert den Wert eines Farbpaletten-Eintrag.
+ *
+ * @param entry
+ * Farbpaletten-Eintrag
+ * @return {@code null}, wenn <code>null</code> uebergeben wird
+ */
+ public static Double getQuantityFromColorMapEntry(ColorMapEntry entry) {
+ if (entry == null)
+ return null;
+ return getQuantityFromExpression(entry.getQuantity());
+ }
- return createColorMapEntry(
- colorMapEntry.getLabel(),
- getQuantityFromColorMapEntry(colorMapEntry),
- getColorFromColorMapEntry(colorMapEntry),
- getOpacityFromColorMapEntry(colorMapEntry)
- );
- }
+ /**
+ * Setzt den Wert eines Farbpaletten-Eintrag.
+ *
+ * @param entry
+ * Farbpaletten-Eintrag
+ * @param quantity
+ * neuer Wert
+ */
+ public static void setQuantityForColorMapEntry(ColorMapEntry entry,
+ double quantity) {
+ if (entry != null)
+ entry.setQuantity(STYLE_BUILDER.literalExpression(quantity));
+ }
- /**
- * Liefert den Wert eines Farbpaletten-Eintrag.
- * @param expression Expression, die einen String oder einen Double liefert
- * @return {@code null}, wenn <code>null</code> uebergeben wird
- */
- public static Double getQuantityFromExpression(Expression expression) {
-// gt2-2.3.4:
-// if ( expression == null || expression.getValue(null) == null )
-// return null
-// Object exprValue = evaluate.getValue(null);
-// gt2-2.3.4:
- if ( expression == null || expression.evaluate(null) == null )
- return null;
- Object exprValue = expression.evaluate(null);
+ /**
+ * Liefert die Transparenz eines Farbpaletten-Eintrag.
+ *
+ * @param expression
+ * Expression, die einen String oder einen Double liefert
+ * @return 1.0, wenn <code>null</code> uebergeben wird
+ */
+ public static Double getOpacityFromExpression(Expression expression) {
+ // gt2-2.3.4:
+ // if ( expression == null || expression.getValue(null) == null )
+ // return 1.0
+ // Object exprValue = evaluate.getValue(null);
+ // gt2-2.3.4:
+ if (expression == null || expression.evaluate(null) == null)
+ return 1.0;
+ Object exprValue = expression.evaluate(null);
- return (exprValue instanceof String) ? Double.valueOf( (String) exprValue) : ((Number)exprValue).doubleValue();
- }
+ return (exprValue instanceof String) ? Double
+ .valueOf((String) exprValue) : ((Number) exprValue)
+ .doubleValue();
+ }
- /**
- * Liefert den Wert eines Farbpaletten-Eintrag.
- * @param entry Farbpaletten-Eintrag
- * @return {@code null}, wenn <code>null</code> uebergeben wird
- */
- public static Double getQuantityFromColorMapEntry(ColorMapEntry entry) {
- if ( entry == null )
- return null;
- return getQuantityFromExpression(entry.getQuantity());
- }
+ /**
+ * Liefert die Transparenz eines Farbpaletten-Eintrag.
+ *
+ * @param entry
+ * Farbpaletten-Eintrag
+ * @return 1.0, wenn <code>null</code> uebergeben wird
+ */
+ public static Double getOpacityFromColorMapEntry(ColorMapEntry entry) {
+ if (entry == null)
+ return 1.0;
+ return getOpacityFromExpression(entry.getOpacity());
+ }
- /**
- * Setzt den Wert eines Farbpaletten-Eintrag.
- * @param entry Farbpaletten-Eintrag
- * @param quantity neuer Wert
- */
- public static void setQuantityForColorMapEntry(ColorMapEntry entry, double quantity) {
- if ( entry != null )
- entry.setQuantity( STYLE_BUILDER.literalExpression( quantity ) );
- }
+ /**
+ * Setzt die Transparenz eines Farbpaletten-Eintrag.
+ *
+ * @param entry
+ * Farbpaletten-Eintrag
+ * @param opacity
+ * Transparenzwert
+ */
+ public static void setOpacityForColorMapEntry(ColorMapEntry entry,
+ double opacity) {
+ if (entry != null)
+ entry.setOpacity(STYLE_BUILDER.literalExpression(opacity));
+ }
- /**
- * Liefert die Transparenz eines Farbpaletten-Eintrag.
- * @param expression Expression, die einen String oder einen Double liefert
- * @return 1.0, wenn <code>null</code> uebergeben wird
- */
- public static Double getOpacityFromExpression(Expression expression) {
-// gt2-2.3.4:
-// if ( expression == null || expression.getValue(null) == null )
-// return 1.0
-// Object exprValue = evaluate.getValue(null);
-// gt2-2.3.4:
- if ( expression == null || expression.evaluate(null) == null )
- return 1.0;
- Object exprValue = expression.evaluate(null);
+ /**
+ * Liefert die Farbe eines Farbpaletten-Eintrag.
+ *
+ * @param expression
+ * Expression, die einen String liefert
+ * @param opacity
+ * Transparenz der Farbe
+ */
+ public static Color getColorFromExpression(Expression expression,
+ Double opacity) {
+ if (expression == null)
+ return null;
- return (exprValue instanceof String) ? Double.valueOf( (String) exprValue) : ((Number)exprValue).doubleValue();
- }
+ return Color.decode((String) expression.evaluate(null));
- /**
- * Liefert die Transparenz eines Farbpaletten-Eintrag.
- * @param entry Farbpaletten-Eintrag
- * @return 1.0, wenn <code>null</code> uebergeben wird
- */
- public static Double getOpacityFromColorMapEntry(ColorMapEntry entry) {
- if ( entry == null )
- return 1.0;
- return getOpacityFromExpression(entry.getOpacity());
- }
+ // // int colorInt = Integer.decode( (String)
+ // expression.getValue(null)); // gt2-2.3.4
+ // int colorInt = Integer.decode( (String) expression.evaluate(null));
+ // // gt2-2-4-2
+ //
+ // return new Color(
+ // (colorInt >> 16) & 0xFF,
+ // (colorInt >> 8) & 0xFF,
+ // colorInt & 0xFF,
+ // new Double(Math.ceil(255.0 * opacity.floatValue())).intValue()
+ // );
+ }
- /**
- * Setzt die Transparenz eines Farbpaletten-Eintrag.
- * @param entry Farbpaletten-Eintrag
- * @param opacity Transparenzwert
- */
- public static void setOpacityForColorMapEntry(ColorMapEntry entry, double opacity) {
- if ( entry != null )
- entry.setOpacity( STYLE_BUILDER.literalExpression( opacity ) );
- }
+ /**
+ * Liefert die Farbe eines Farbpaletten-Eintrag.
+ *
+ * @param entry
+ * Farbpaletten-Eintrag
+ */
+ public static Color getColorFromColorMapEntry(ColorMapEntry entry) {
+ // if ( entry == null || entry.getColor() == null ||
+ // entry.getColor().getValue(null) == null ) // gt2-2.3.4
+ if (entry == null || entry.getColor() == null
+ || entry.getColor().evaluate(null) == null) // gt2-2-4-2
+ return null;
- /**
- * Liefert die Farbe eines Farbpaletten-Eintrag.
- * @param expression Expression, die einen String liefert
- * @param opacity Transparenz der Farbe
- */
- public static Color getColorFromExpression(Expression expression, Double opacity) {
- if ( expression == null )
- return null;
+ // Transparenz
+ Double opacity = getOpacityFromColorMapEntry(entry);
+ // Farbe
+ return getColorFromExpression(entry.getColor(), opacity);
+ }
- return Color.decode( (String) expression.evaluate(null) );
+ /**
+ * Setzt die Farbe eines Farbpaletten-Eintrag.
+ *
+ * @param entry
+ * Farbpaletten-Eintrag
+ * @param color
+ * eine Farbe
+ */
+ public static void setColorForColorMapEntry(ColorMapEntry entry, Color color) {
+ if (entry != null)
+ entry.setColor(STYLE_BUILDER.colorExpression(color));
+ }
-//// int colorInt = Integer.decode( (String) expression.getValue(null)); // gt2-2.3.4
-// int colorInt = Integer.decode( (String) expression.evaluate(null)); // gt2-2-4-2
-//
-// return new Color(
-// (colorInt >> 16) & 0xFF,
-// (colorInt >> 8) & 0xFF,
-// colorInt & 0xFF,
-// new Double(Math.ceil(255.0 * opacity.floatValue())).intValue()
-// );
- }
+ /**
+ * Erzeugt einen {@link Style} aus einem {@linkplain Element JDOM-Element},
+ * des eine SLD-Definition enthaelt
+ *
+ * @param element
+ * Element mit SLD-Definition
+ */
+ public static Style createStyleFromSLD(Element element) {
+ String xmlDefinition = new XMLOutputter().outputString(element);
+ Style[] style = loadSLD(new ByteArrayInputStream(xmlDefinition
+ .getBytes()));
+ return style == null || style.length == 0 ? null : style[0];
+ }
- /**
- * Liefert die Farbe eines Farbpaletten-Eintrag.
- * @param entry Farbpaletten-Eintrag
- */
- public static Color getColorFromColorMapEntry(ColorMapEntry entry) {
-// if ( entry == null || entry.getColor() == null || entry.getColor().getValue(null) == null ) // gt2-2.3.4
- if ( entry == null || entry.getColor() == null || entry.getColor().evaluate(null) == null ) // gt2-2-4-2
- return null;
-
- // Transparenz
- Double opacity = getOpacityFromColorMapEntry(entry);
- // Farbe
- return getColorFromExpression(entry.getColor(), opacity);
- }
-
- /**
- * Setzt die Farbe eines Farbpaletten-Eintrag.
- * @param entry Farbpaletten-Eintrag
- * @param color eine Farbe
- */
- public static void setColorForColorMapEntry(ColorMapEntry entry, Color color) {
- if ( entry != null )
- entry.setColor( STYLE_BUILDER.colorExpression( color ) );
- }
-
- /**
- * Erzeugt einen {@link Style} aus einem {@linkplain Element JDOM-Element},
- * des eine SLD-Definition enthaelt
- * @param element Element mit SLD-Definition
- */
- public static Style createStyleFromSLD(Element element) {
- String xmlDefinition = new XMLOutputter().outputString(element);
- Style[] style = loadSLD( new ByteArrayInputStream(xmlDefinition.getBytes()) );
- return style == null || style.length == 0 ? null : style[0];
- }
-
-
-
-
/**
* Creates a {@link Style} for a {@link Grid} layer from a {@link ColorMap}
- *
+ *
* @param colorMap
* If null, then defaultStyle for Grid will be used
* @param name
* The name to give to the Style. null will result in name=
- * {@link GridUtil#UNNAMED_RASTER_STYLE_NAME} or GridUtil#DEFAULT_RASTER_STYLE_NAME} (if no colorMap is given).
- *
+ * {@link GridUtil#UNNAMED_RASTER_STYLE_NAME} or
+ * GridUtil#DEFAULT_RASTER_STYLE_NAME} (if no colorMap is given).
+ *
* @param title
- * The Title to give to the Style. null will result in title=
- * {@link GridUtil#UNTITLED_RASTER_STYLE_TITLE} or {@link GridUtil#DEFAULT_RASTER_STYLE_TITLE} (if no colorMap is given)
- *
- * @return Always a {@link Style} that you can be applyed to a {@link GridCoverage}.
- *
- * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Krüger</a>
+ * The Title to give to the Style. null will result in title=
+ * {@link GridUtil#UNTITLED_RASTER_STYLE_TITLE} or
+ * {@link GridUtil#DEFAULT_RASTER_STYLE_TITLE} (if no colorMap is
+ * given)
+ *
+ * @return Always a {@link Style} that you can be applyed to a
+ * {@link GridCoverage}.
+ *
+ * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
+ * Krüger</a>
*/
- public static Style createStyleFromColorMap(ColorMap colorMap, String name, String title) {
+ public static Style createStyleFromColorMap(ColorMap colorMap, String name,
+ String title) {
if (colorMap == null)
return GridUtil.createDefaultStyle();
@@ -593,52 +664,53 @@
return style;
}
-
/**
- * Removes all label information from the {@link ColorMapEntry}s of the given {@link ColorMap}
- *
- * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Krüger</a>
+ * Removes all label information from the {@link ColorMapEntry}s of the
+ * given {@link ColorMap}
+ *
+ * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
+ * Krüger</a>
*/
public static ColorMap clearColorMapLabels(ColorMap colorMap) {
- for (ColorMapEntry cme : colorMap.getColorMapEntries()){
+ for (ColorMapEntry cme : colorMap.getColorMapEntries()) {
cme.setLabel(null);
}
return colorMap;
}
-
/**
* Creates a {@link Style} for a {@link Grid} layer from a {@link ColorMap}
* Title will be set to {@link GridUtil#UNTITLED_RASTER_STYLE_TITLE}
- *
+ *
* @param colorMap
* If null, then defaultStyle for Grid will be used
* @param name
* The name to give to the Style. null will result in name
* {@link GridUtil#UNTITLED_RASTER_STYLE_TITLE}
- *
+ *
* @return Always a Style that you can apply to a {@link GridCoverage}.
- * Style has name {@link GridUtil#DEFAULT_RASTER_STYLE_NAME} if no colormap
- * was provided.
- *
- *
- * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Krüger</a>
+ * Style has name {@link GridUtil#DEFAULT_RASTER_STYLE_NAME} if no
+ * colormap was provided.
+ *
+ *
+ * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
+ * Krüger</a>
*/
public static Style createStyleFromColorMap(ColorMap colorMap, String name) {
return createStyleFromColorMap(colorMap, name, null);
}
-
-
-
/**
* Loads {@link Style}s from a SLD {@link InputStream}
-
- * @param url {@link URL} to read the SLD from
- *
- * @return An {@link Array} of {@link Style}s, can be length==0 if no UserStyles in SLD file. null if file not exists
- *
- * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Krüger</a>
+ *
+ * @param url
+ * {@link URL} to read the SLD from
+ *
+ * @return An {@link Array} of {@link Style}s, can be length==0 if no
+ * UserStyles in SLD file. null if file not exists
+ *
+ * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
+ * Krüger</a>
*/
public static Style[] loadSLD(URL url) {
// LOGGER.debug("Loading styles from URL...");
@@ -649,15 +721,17 @@
}
}
-
/**
* Loads {@link Style}s from a SLD {@link InputStream}
-
- * @param inputStream {@link InputStream} to read the SLD from
- *
- * @return An {@link Array} of {@link Style}s, can be length==0. null if file not exists
- *
- * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Krüger</a>
+ *
+ * @param inputStream
+ * {@link InputStream} to read the SLD from
+ *
+ * @return An {@link Array} of {@link Style}s, can be length==0. null if
+ * file not exists
+ *
+ * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
+ * Krüger</a>
*/
public static Style[] loadSLD(InputStream inputStream) {
final InputStream inputStream2 = inputStream;
@@ -668,12 +742,13 @@
LOGGER.debug("Loading styles from inputStream...");
SLDParser stylereader;
- stylereader = new SLDParser( StylingUtil.STYLE_FACTORY);
- stylereader.setInput( inputStream);
+ stylereader = new SLDParser(StylingUtil.STYLE_FACTORY);
+ stylereader.setInput(inputStream);
Style[] styles = stylereader.readXML();
if (styles[0] == null) {
- LOGGER.warn(" ... no Styles recognized in inputStream. Will return empty styles[] array!");
+ LOGGER
+ .warn(" ... no Styles recognized in inputStream. Will return empty styles[] array!");
} else {
LOGGER.debug(" ... loaded " + styles.length
+ " styles from inputStream, first style's name= "
@@ -684,16 +759,19 @@
return styles;
}
-
/**
- * Loads {@link Style}s from a SLD {@link InputStream} without setting a {@link Charset}
-
- * @param inputStream {@link InputStream} to read the SLD from
- *
- * @return An {@link Array} of {@link Style}s, can be length==0. null if file not exists
- *
- * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Krüger</a>
- *
+ * Loads {@link Style}s from a SLD {@link InputStream} without setting a
+ * {@link Charset}
+ *
+ * @param inputStream
+ * {@link InputStream} to read the SLD from
+ *
+ * @return An {@link Array} of {@link Style}s, can be length==0. null if
+ * file not exists
+ *
+ * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
+ * Krüger</a>
+ *
* @deprecated
*/
public static Style[] loadSLDOld(InputStream inputStream) {
@@ -707,7 +785,7 @@
LOGGER.debug("Loading styles from inputStream...");
SLDParser stylereader;
- stylereader = new SLDParser( StylingUtil.STYLE_FACTORY, inputStream2);
+ stylereader = new SLDParser(StylingUtil.STYLE_FACTORY, inputStream2);
Style[] styles = stylereader.readXML();
if (styles[0] == null) {
@@ -723,69 +801,75 @@
return styles;
}
-
/**
* Loads {@link Style}s from a SLD {@link File}
- *
- * @param sldFile {@link File} to read the SLD from
- *
+ *
+ * @param sldFile
+ * {@link File} to read the SLD from
+ *
* @return An {@link Array} of {@link Style}s, can be length==0
- *
- * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Krüger</a>
+ *
+ * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
+ * Krüger</a>
*/
public static Style[] loadSLD(File sldFile) throws FileNotFoundException {
LOGGER.debug("Loading styles from File...");
- final Style[] loadedSLD = loadSLD( new FileInputStream( sldFile ) );
+ final Style[] loadedSLD = loadSLD(new FileInputStream(sldFile));
- // TODO Maybe check if names and titles should be set to default values...
+ // TODO Maybe check if names and titles should be set to default
+ // values...
return loadedSLD;
}
/**
* Saves the {@link Style} to OGC SLD. Overwrites any existing file.
- *
+ *
* @param style
* {@link Style} to save
- * @param charset The charset to use for the XML, e.g. <?xml version="1.0" encoding="ISO-8859-1"?>. If null, ISO-8859-1 is used.
- *
+ * @param charset
+ * The charset to use for the XML, e.g. <?xml version="1.0"
+ * encoding="ISO-8859-1"?>. If null, ISO-8859-1 is used.
+ *
* @throws TransformerException
* @throws IOException
- *
- * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Krüger</a>
+ *
+ * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
+ * Krüger</a>
*/
- public static final void saveStyleToSLD(Style style, File exportFile, Charset charset)
- throws TransformerException, IOException {
+ public static final void saveStyleToSLD(Style style, File exportFile,
+ Charset charset) throws TransformerException, IOException {
Writer w = null;
final SLDTransformer aTransformer = new SLDTransformer();
if (charset != null) {
- aTransformer.setEncoding( charset );
+ aTransformer.setEncoding(charset);
}
aTransformer.setIndentation(2);
final String xml = aTransformer.transform(style);
w = new FileWriter(exportFile);
w.write(xml);
w.close();
- LOGGER.info("Saved a Style to " + exportFile+" with charset "+ aTransformer.getEncoding().name());
+ LOGGER.info("Saved a Style to " + exportFile + " with charset "
+ + aTransformer.getEncoding().name());
}
-
/**
* Saves the {@link Style} to OGC SLD using ISO-8859-1 as charset.
* Overwrites any existing file.
- *
+ *
* @param style
* {@link Style} to save
- *
+ *
* @throws TransformerException
* @throws IOException
- *
- * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Krüger</a>
+ *
+ * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
+ * Krüger</a>
*/
public static final void saveStyleToSLD(Style style, File exportFile)
throws TransformerException, IOException {
- saveStyleToSLD(style, exportFile, Charset.forName("ISO-8859-1") );
+ saveStyleToSLD(style, exportFile, Charset.forName("ISO-8859-1"));
}
/**
@@ -822,14 +906,14 @@
public static MemoryFeatureCollection filterSLDVisibleOnly(
final FeatureCollection fc, final Style style,
final Double scaleDenominator) {
-
+
// Eine im Speicher gehaltene FeatureCollection der sichtbaren
MemoryFeatureCollection fcVisible = new MemoryFeatureCollection(fc
.getFeatureType());
-
+
// Prüfen aller Features in der Collection
Iterator<Feature> fcIt = fc.iterator();
-
+
try {
while (fcIt.hasNext()) {
@@ -899,120 +983,177 @@
LOGGER.error(e);
/**
* SK: 14.Apri 2009. It happened a few time to that fcIt.hasNext
- * suddenly threw an exception for the "africa countries.shp": Exception
- * in thread "AWT-EventQueue-0" java.lang.IllegalStateException:
- * ShapeType changed illegally from Polygon to Undefined at
- * org.geotools.
+ * suddenly threw an exception for the "africa countries.shp":
+ * Exception in thread "AWT-EventQueue-0"
+ * java.lang.IllegalStateException: ShapeType changed illegally from
+ * Polygon to Undefined at org.geotools.
* data.shapefile.shp.ShapefileReader.nextRecord(ShapefileReader
* .java:452) at org.geotools.data.shapefile.indexed.
* IndexedShapefileDataStore$Reader
* .next(IndexedShapefileDataStore.java:1272) at
- * org.geotools.data.FIDFeatureReader.next(FIDFeatureReader.java:92) at
- * org
- * .geotools.data.FilteringFeatureReader.hasNext(FilteringFeatureReader
- * .java:125) at org.geotools.data.store.FeatureReaderIterator.hasNext(
+ * org.geotools.data.FIDFeatureReader.next(FIDFeatureReader.java:92)
+ * at org .geotools.data.FilteringFeatureReader.hasNext(
+ * FilteringFeatureReader .java:125) at
+ * org.geotools.data.store.FeatureReaderIterator.hasNext(
* FeatureReaderIterator.java:44) at
* schmitzm.geotools.feature.FeatureUtil
* .filterSLDVisibleOnly(FeatureUtil.java:216) *
*
*/
}
-
+
// LOGGER.info("filterSLDVisibleOnly removed "+ (fc.size() -
// fcVisible.size()) + " features.");
-
+
return fcVisible;
}
/**
- * @param style A {@link Style} to search for the first {@link TextSymbolizer}
+ * @param style
+ * A {@link Style} to search for the first {@link TextSymbolizer}
+ * that will be used for the given {@link Feature}.
*
* @author Stefan A. Krüger
*
- * @return <code>null</code> or the first {@link TextSymbolizer} found in the style.
+ * @return <code>null</code> or the first {@link TextSymbolizer} found in
+ * the style that applies to the {@link Feature}.
*/
- public static TextSymbolizer getTextSymbolizer(Style style) {
+ public static TextSymbolizer getTextSymbolizer(final Style style,
+ final Feature f) {
+ if (f == null) return null;
try {
if (style != null) {
-
- for (FeatureTypeStyle fts : style.getFeatureTypeStyles()){
- for (Rule r : fts.getRules()){
-
- for (Symbolizer symb : r.getSymbolizers()){
+
+ for (final FeatureTypeStyle fts : style.getFeatureTypeStyles()) {
+ for (final Rule r : fts.getRules()) {
+
+ final Filter filter = r.getFilter();
+//
+// System.out.println(f);
+// System.out.println(filter);
+// System.out.println();
+
+ if (filter != null && (!filter.evaluate(f))) {
+ continue;
+ }
+
+ for (final Symbolizer symb : r.getSymbolizers()) {
if (symb instanceof TextSymbolizer) {
- return (TextSymbolizer)symb;
+ return (TextSymbolizer) symb;
}
}
}
}
-
-
+
}
-
- } catch (Exception e) {
- System.err.println("");
+
+ } catch (final Exception e) {
+ e.printStackTrace();
+ System.err.println("error");
return null;
}
return null;
}
+ /**
+ * @param style
+ * A {@link Style} to search for all {@link TextSymbolizer}s . No
+ * guarantee, that any one of them will ever be used for any
+ * feature (think about filters).
+ *
+ * @author Stefan A. Krüger
+ *
+ * @return {@link List} or all {@link TextSymbolizer}s found in
+ * the {@link Style}.
+ */
+ public static List<TextSymbolizer> getTextSymbolizers(final Style style) {
+ List<TextSymbolizer> results = new ArrayList<TextSymbolizer>();
+ try {
+ if (style != null) {
-
+ for (final FeatureTypeStyle fts : style.getFeatureTypeStyles()) {
+ for (final Rule r : fts.getRules()) {
+ for (final Symbolizer symb : r.getSymbolizers()) {
+ if (symb instanceof TextSymbolizer) {
+ results.add((TextSymbolizer) symb);
+ }
+ }
-// /**
-// * Sorts a {@link ColorMap} by its quantity values. This is mentioned in the
-// * OGC SLD Definition, page 52:
-// * <p>
-// * Quote: For example, a DEM raster giving elevations in meters above sea
-// * level can be translated to a colored image with a ColorMap. The quantity
-// * attributes of a color-map are used for translating between numeric
-// * matrixes and color rasters and the ColorMap entries should be in order of
-// * increasing numeric quantity so that intermediate numeric values can be
-// * matched to a color (or be interpolated between two colors). Labels may be
-// * used for legends or may be used in the future to match character values.
-// * Not all systems can support opacity in colormaps. The default opacity is
-// * 1.0 (fully opaque). Defaults for quantity and label are system-dependent.
-// * </p>
-// *
-// * @param colorMap
-// * {@link ColorMap} to sort by the quantity-field of the
-// * {@link ColorMapEntry}s
-// * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Krüger</a>
-// */
-// public static void sort(RemovableColorMapImpl colorMap) {
-// ColorMapEntry[] colorMapEntries = colorMap.getColorMapEntries();
-// SortedMap<Double, ColorMapEntry> tmap = new TreeMap<Double, ColorMapEntry>();
-// // Add to a SortedMap
-// for (ColorMapEntry cme : colorMapEntries) {
-// tmap.put(getQuantityFromColorMapEntry(cme), cme);
-// colorMap.removeColorMapEntry(cme);
-// }
-// // Recreate ColorMap from sorted quantity values
-// for (ColorMapEntry cme : tmap.values()) {
-// colorMap.addColorMapEntry(cme);
-// }
-// }
+ }
+ }
+ }
-// /**
-// * Lets assume that every quantity value is maximally listed once in a
-// * {@link ColorMap}, then it makes some sense to use it as a key.
-// *
-// * @param quantityString
-// * quantitiy as String
-// * @return The first colorMap that has the same Quantity ( compared as
-// * Strings)
-// *
-// * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Krüger</a>
-// */
-// public static ColorMapEntry getColorMapEntryByQuantityString(
-// ColorMap colorMap, String quantityString) {
-// for (ColorMapEntry cme : colorMap.getColorMapEntries()) {
-// if (quantityString.equals(cme.getQuantity().toString()))
-// return cme;
-// }
-// return null;
-// }
+ } catch (final Exception e) {
+ System.err.println("error");
+ return results;
+ }
+ return results;
+ }
+
+ // /**
+ // * Sorts a {@link ColorMap} by its quantity values. This is mentioned in
+ // the
+ // * OGC SLD Definition, page 52:
+ // * <p>
+ // * Quote: For example, a DEM raster giving elevations in meters above sea
+ // * level can be translated to a colored image with a ColorMap. The
+ // quantity
+ // * attributes of a color-map are used for translating between numeric
+ // * matrixes and color rasters and the ColorMap entries should be in order
+ // of
+ // * increasing numeric quantity so that intermediate numeric values can be
+ // * matched to a color (or be interpolated between two colors). Labels may
+ // be
+ // * used for legends or may be used in the future to match character
+ // values.
+ // * Not all systems can support opacity in colormaps. The default opacity
+ // is
+ // * 1.0 (fully opaque). Defaults for quantity and label are
+ // system-dependent.
+ // * </p>
+ // *
+ // * @param colorMap
+ // * {@link ColorMap} to sort by the quantity-field of the
+ // * {@link ColorMapEntry}s
+ // * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
+ // Krüger</a>
+ // */
+ // public static void sort(RemovableColorMapImpl colorMap) {
+ // ColorMapEntry[] colorMapEntries = colorMap.getColorMapEntries();
+ // SortedMap<Double, ColorMapEntry> tmap = new TreeMap<Double,
+ // ColorMapEntry>();
+ // // Add to a SortedMap
+ // for (ColorMapEntry cme : colorMapEntries) {
+ // tmap.put(getQuantityFromColorMapEntry(cme), cme);
+ // colorMap.removeColorMapEntry(cme);
+ // }
+ // // Recreate ColorMap from sorted quantity values
+ // for (ColorMapEntry cme : tmap.values()) {
+ // colorMap.addColorMapEntry(cme);
+ // }
+ // }
+
+ // /**
+ // * Lets assume that every quantity value is maximally listed once in a
+ // * {@link ColorMap}, then it makes some sense to use it as a key.
+ // *
+ // * @param quantityString
+ // * quantitiy as String
+ // * @return The first colorMap that has the same Quantity ( compared as
+ // * Strings)
+ // *
+ // * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
+ // Krüger</a>
+ // */
+ // public static ColorMapEntry getColorMapEntryByQuantityString(
+ // ColorMap colorMap, String quantityString) {
+ // for (ColorMapEntry cme : colorMap.getColorMapEntries()) {
+ // if (quantityString.equals(cme.getQuantity().toString()))
+ // return cme;
+ // }
+ // return null;
+ // }
}
More information about the Schmitzm-commits
mailing list