[Schmitzm-commits] r1045 - in trunk: src/schmitzm/geotools/styling src_junit/schmitzm/geotools/styling

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


Author: alfonx
Date: 2010-09-22 13:55:59 +0200 (Wed, 22 Sep 2010)
New Revision: 1045

Modified:
   trunk/src/schmitzm/geotools/styling/StylingUtil.java
   trunk/src_junit/schmitzm/geotools/styling/StylingUtilTest.java
Log:
Added support to correct some RasterSymbolizer pitfalls to StylingUtil.correctPorpertynames

Modified: trunk/src/schmitzm/geotools/styling/StylingUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/styling/StylingUtil.java	2010-09-22 11:49:54 UTC (rev 1044)
+++ trunk/src/schmitzm/geotools/styling/StylingUtil.java	2010-09-22 11:55:59 UTC (rev 1045)
@@ -2492,25 +2492,6 @@
 	}
 	
 	/**
-	 * Corrct RasterStyle specific pitfalls.<br/>
-	 *  1. check the getGeometryPropertyName<br/>
-	 *  2. check colormaps are in correct order 
-	 */
-	public Style correctRasterStyle(Style style) {
-		DuplicatingStyleVisitor dsv = new DuplicatingStyleVisitor() {
-			@Override
-			public void visit(ColorMap cm) {
-				// TODO
-			};
-		};
-		
-		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
 	 * all referenced AttributeNames and checks them against the schema.
@@ -2525,16 +2506,20 @@
 
 		DuplicatingStyleVisitor dsv = new DuplicatingStyleVisitor() {
 			public void visit(RasterSymbolizer sym) {
-				if (!sym.getGeometryPropertyName().equals("geom")) {
+//				if (!sym.getGeometryPropertyName().equals("geom")) {
 //					LOGGER
 //							.debug("Corrected one RasterSymbolizer with GeometryPropertyName '"
 //									+ sym.getGeometryPropertyName()
 //									+ "' to 'geom'.");
-					sym.setGeometryPropertyName("geom");
-				}
+					sym.setGeometryPropertyName(null);
+//				}
 				super.visit(sym);
 			};
 			
+			@Override
+			public void visit(ColorMap cm) {
+				super.visit(sortColorMap(cm));
+			};
 
 			@Override
 			public void visit(LineSymbolizer sym) {

Modified: trunk/src_junit/schmitzm/geotools/styling/StylingUtilTest.java
===================================================================
--- trunk/src_junit/schmitzm/geotools/styling/StylingUtilTest.java	2010-09-22 11:49:54 UTC (rev 1044)
+++ trunk/src_junit/schmitzm/geotools/styling/StylingUtilTest.java	2010-09-22 11:55:59 UTC (rev 1045)
@@ -1,5 +1,6 @@
 package schmitzm.geotools.styling;
 
+import java.awt.Color;
 import java.awt.Dimension;
 import java.awt.Graphics2D;
 import java.awt.GraphicsEnvironment;
@@ -18,6 +19,8 @@
 import org.geotools.map.DefaultMapContext;
 import org.geotools.map.DefaultMapLayer;
 import org.geotools.renderer.lite.StreamingRenderer;
+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;
@@ -25,6 +28,8 @@
 import org.opengis.feature.simple.SimpleFeature;
 import org.opengis.feature.simple.SimpleFeatureType;
 
+import com.sun.media.jai.rmi.RasterState;
+
 import schmitzm.geotools.JTSUtil;
 import schmitzm.geotools.styling.StylingUtil.SelectionStylesTypes;
 import schmitzm.swing.TestingUtil;
@@ -32,20 +37,19 @@
 public class StylingUtilTest extends TestCase {
 
 	boolean INTERACTIVE = !GraphicsEnvironment.isHeadless();
-	
 
 	@Test
 	public void testCorrectPropertyNamesWithRasterSymbolizer() {
-		
+
 		StyleBuilder sb = StylingUtil.STYLE_BUILDER;
 		RasterSymbolizer rs = sb.createRasterSymbolizer();
 		Style style = sb.createStyle(rs);
-		
+
 		assertNotNull(style);
-		
-		// Once we NPEs here.
+
+		// Once we hade NPEs here.
 		StylingUtil.correctPropertyNames(style, null);
-		
+
 		assertNotNull(style);
 	}
 
@@ -54,7 +58,7 @@
 
 		FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil2
 				.getTestFeatures();
-		
+
 		JPanel jPanel = new JPanel();
 
 		for (SelectionStylesTypes st : SelectionStylesTypes.values()) {
@@ -65,7 +69,7 @@
 
 			StreamingRenderer sr = new StreamingRenderer();
 			sr.setContext(mc);
-			
+
 			// DIe Bounds werden vom selected Feature genommen
 			ReferencedEnvelope bounds = testFeatures.getBounds();
 			Double imageW = 300.;
@@ -76,8 +80,8 @@
 				imageW = imageH * bounds.getWidth() / bounds.getHeight();
 			}
 
-			BufferedImage img = new BufferedImage(imageW.intValue(), imageH
-					.intValue(), BufferedImage.TYPE_INT_ARGB);
+			BufferedImage img = new BufferedImage(imageW.intValue(),
+					imageH.intValue(), BufferedImage.TYPE_INT_ARGB);
 			Graphics2D gr = (Graphics2D) img.getGraphics();
 
 			gr.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
@@ -87,9 +91,11 @@
 			gr.setRenderingHint(RenderingHints.KEY_RENDERING,
 					RenderingHints.VALUE_RENDER_QUALITY);
 
-			sr.paint(gr, new Rectangle(new Dimension(imageW
-					.intValue(), imageH.intValue())), JTSUtil
-					.expandEnvelope(testFeatures.getBounds(), .1));
+			sr.paint(
+					gr,
+					new Rectangle(new Dimension(imageW.intValue(), imageH
+							.intValue())), JTSUtil.expandEnvelope(
+							testFeatures.getBounds(), .1));
 
 			gr.dispose();
 
@@ -99,4 +105,23 @@
 
 	}
 
+	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.);
+		Style brokenStyle = StylingUtil.STYLE_BUILDER.createStyle(rS);
+
+		Style correctRasterStyle = StylingUtil.correctPropertyNames(brokenStyle, null);
+
+		RasterSymbolizer rs = (RasterSymbolizer) correctRasterStyle
+				.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());
+	}
+
 }



More information about the Schmitzm-commits mailing list