[Schmitzm-commits] r1044 - in branches/2.2.x: src/schmitzm/geotools/styling src_junit/schmitzm/geotools/styling

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Sep 22 13:49:54 CEST 2010


Author: alfonx
Date: 2010-09-22 13:49:54 +0200 (Wed, 22 Sep 2010)
New Revision: 1044

Modified:
   branches/2.2.x/src/schmitzm/geotools/styling/StylingUtil.java
   branches/2.2.x/src_junit/schmitzm/geotools/styling/StylingUtilTest.java
Log:
Added correctRasterStyle to StylingUtil for ISDSS

Modified: branches/2.2.x/src/schmitzm/geotools/styling/StylingUtil.java
===================================================================
--- branches/2.2.x/src/schmitzm/geotools/styling/StylingUtil.java	2010-09-22 11:19:06 UTC (rev 1043)
+++ branches/2.2.x/src/schmitzm/geotools/styling/StylingUtil.java	2010-09-22 11:49:54 UTC (rev 1044)
@@ -2518,7 +2518,34 @@
 
 		return filterSLDVisibleOnly(fc, style, scaleDenominator);
 	}
+	
+	/**
+	 * Note: This method is merged into
+	 * {@link #correctPropertyNames(Style, SimpleFeatureType)} in trunk. Note
+	 * further, that on trunk correctPropertyNames is renamed to correctStyle
+	 * Correct RasterStyle specific pitfalls.<br/>
+	 * 1. setGeometryPropertyName(null); 2. check colormaps are in correct order
+	 */
+	public static Style correctRasterStyle(Style style) {
+		DuplicatingStyleVisitor dsv = new DuplicatingStyleVisitor() {
+			@Override
+			public void visit(ColorMap cm) {
+				super.visit(sortColorMap(cm));
+			};
 
+			@Override
+			public void visit(RasterSymbolizer sym) {
+				sym.setGeometryPropertyName(null);
+				super.visit(sym);
+			};
+		};
+
+		dsv.visit(style);
+
+		Style copiedCleanStyle = (Style) dsv.getCopy();
+		return copiedCleanStyle;
+	}
+
 	/**
 	 * Since GT2.6, the AttributeNames are case sensitive. Also the raster
 	 * Styles need GeometryProperty set to "geom" to work. This method checks

Modified: branches/2.2.x/src_junit/schmitzm/geotools/styling/StylingUtilTest.java
===================================================================
--- branches/2.2.x/src_junit/schmitzm/geotools/styling/StylingUtilTest.java	2010-09-22 11:19:06 UTC (rev 1043)
+++ branches/2.2.x/src_junit/schmitzm/geotools/styling/StylingUtilTest.java	2010-09-22 11:49:54 UTC (rev 1044)
@@ -1,9 +1,12 @@
 package schmitzm.geotools.styling;
 
+import java.awt.Color;
 import java.awt.GraphicsEnvironment;
 
 import junit.framework.TestCase;
 
+import org.geotools.styling.ColorMap;
+import org.geotools.styling.ColorMapEntry;
 import org.geotools.styling.RasterSymbolizer;
 import org.geotools.styling.Style;
 import org.geotools.styling.StyleBuilder;
@@ -30,4 +33,29 @@
 	}
 
 
+	@Test
+	public void testCorrectRasterStyle() {
+		ColorMap wrongOrderColormap = StylingUtil.STYLE_BUILDER.createColorMap(
+				new String[] { "3", "4", "1" }, new double[] { 3, 4, 1 },
+				new Color[] { Color.red, Color.black, Color.green },
+				ColorMap.TYPE_INTERVALS);
+		RasterSymbolizer rS = StylingUtil.STYLE_BUILDER.createRasterSymbolizer(
+				wrongOrderColormap, 1.);
+		assertEquals("geom", rS.getGeometryPropertyName());
+		Style brokenStyle = StylingUtil.STYLE_BUILDER.createStyle(rS);
+
+		// Clean!
+		Style correctedStyle = StylingUtil.correctRasterStyle(brokenStyle);
+
+		rS = (RasterSymbolizer) correctedStyle
+				.featureTypeStyles().get(0).rules().get(0).symbolizers().get(0);
+		
+		ColorMapEntry[] colorMapEntries = rS.getColorMap().getColorMapEntries();
+		assertEquals("1.0", colorMapEntries[0].getQuantity().toString());
+		assertEquals("3.0", colorMapEntries[1].getQuantity().toString());
+		assertEquals("4.0", colorMapEntries[2].getQuantity().toString());
+		
+		assertEquals(null, rS.getGeometryPropertyName());
+	}
+
 }



More information about the Schmitzm-commits mailing list