[Schmitzm-commits] r1435 - in trunk/schmitzm-gt/src/test/java/de/schmitzm/geotools: . styling

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Jan 27 13:30:43 CET 2011


Author: alfonx
Date: 2011-01-27 13:30:43 +0100 (Thu, 27 Jan 2011)
New Revision: 1435

Added:
   trunk/schmitzm-gt/src/test/java/de/schmitzm/geotools/styling/
   trunk/schmitzm-gt/src/test/java/de/schmitzm/geotools/styling/StylingUtilTest.java
Log:


Added: trunk/schmitzm-gt/src/test/java/de/schmitzm/geotools/styling/StylingUtilTest.java
===================================================================
--- trunk/schmitzm-gt/src/test/java/de/schmitzm/geotools/styling/StylingUtilTest.java	2011-01-27 12:29:11 UTC (rev 1434)
+++ trunk/schmitzm-gt/src/test/java/de/schmitzm/geotools/styling/StylingUtilTest.java	2011-01-27 12:30:43 UTC (rev 1435)
@@ -0,0 +1,196 @@
+package de.schmitzm.geotools.styling;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Graphics2D;
+import java.awt.GraphicsEnvironment;
+import java.awt.Rectangle;
+import java.awt.RenderingHints;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+
+import javax.swing.ImageIcon;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.xml.transform.TransformerException;
+
+import org.geotools.data.FeatureSource;
+import org.geotools.feature.FeatureCollection;
+import org.geotools.geometry.jts.ReferencedEnvelope;
+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.PointSymbolizer;
+import org.geotools.styling.PolygonSymbolizer;
+import org.geotools.styling.RasterSymbolizer;
+import org.geotools.styling.Style;
+import org.geotools.styling.StyleBuilder;
+import org.junit.Test;
+import org.opengis.feature.simple.SimpleFeature;
+import org.opengis.feature.simple.SimpleFeatureType;
+
+import de.schmitzm.geotools.JTSUtil;
+import de.schmitzm.geotools.feature.FeatureUtil.GeometryForm;
+import de.schmitzm.geotools.styling.StylingUtil.SelectionStylesTypes;
+import de.schmitzm.geotools.testing.GTTestingUtil;
+import de.schmitzm.io.IOUtil;
+import de.schmitzm.testing.TestingClass;
+import de.schmitzm.testing.TestingUtil;
+
+public class StylingUtilTest extends TestingClass {
+
+	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 hade NPEs here.
+		StylingUtil.correctPropertyNames(style, null);
+
+		assertNotNull(style);
+	}
+
+	@Test
+	public void testSelectionStyles() throws Throwable {
+
+		FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = GTTestingUtil.TestDatasetsVector.kreise
+				.getFeatureCollection();
+
+		JPanel jPanel = new JPanel();
+
+		for (SelectionStylesTypes st : SelectionStylesTypes.values()) {
+			Style style = StylingUtil.createSelectionStyle(testFeatures, st);
+
+			DefaultMapContext mc = new DefaultMapContext();
+			mc.addLayer(new DefaultMapLayer(testFeatures, style));
+
+			StreamingRenderer sr = new StreamingRenderer();
+			sr.setContext(mc);
+
+			// DIe Bounds werden vom selected Feature genommen
+			ReferencedEnvelope bounds = testFeatures.getBounds();
+			Double imageW = 300.;
+			Double imageH = imageW * bounds.getHeight() / bounds.getWidth();
+
+			if (imageH > 200.) {
+				imageH = 200.;
+				imageW = imageH * bounds.getWidth() / bounds.getHeight();
+			}
+
+			BufferedImage img = new BufferedImage(imageW.intValue(),
+					imageH.intValue(), BufferedImage.TYPE_INT_ARGB);
+			Graphics2D gr = (Graphics2D) img.getGraphics();
+
+			gr.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
+					RenderingHints.VALUE_INTERPOLATION_BICUBIC);
+			gr.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
+					RenderingHints.VALUE_ANTIALIAS_ON);
+			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));
+
+			gr.dispose();
+
+			jPanel.add(new JLabel(new ImageIcon(img, st.toString())));
+		}
+		TestingUtil.testGui(jPanel, "Different selection styles");
+
+	}
+
+	@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.);
+		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());
+	}
+
+	@Test
+	public void testSldEncoding() throws IOException {
+
+		Style style = StylingUtil.createDefaultStyle(GeometryForm.POLYGON);
+
+		assertTrue(StylingUtil.validates(style));
+
+		File tf = File.createTempFile("junit", ".sld");
+		StylingUtil.saveStyleToSld(style, tf);
+		assertTrue(tf.exists());
+
+		String ss = IOUtil.readFileAsString(tf);
+		assertTrue("SLD is not written in UTF-8 encoding",
+				ss.contains("encoding=\"UTF-8"));
+	}
+
+	@Test
+	public void testSldToStringUsesUTF8() throws TransformerException {
+		Style createStyle = StylingUtil.STYLE_BUILDER.createStyle();
+		String sldToString = StylingUtil.sldToString(createStyle);
+		assertTrue(sldToString.length() > 100);
+		assertTrue(sldToString.contains("UTF-8"));
+	}
+
+	@Test
+	public void testCorrectGeometryPropertynameNull() {
+		PointSymbolizer ps = StylingUtil.STYLE_BUILDER.createPointSymbolizer();
+		assertNull(ps.getGeometryPropertyName());
+		StylingUtil.correctGeometryPropertyname(null, ps);
+		assertNull(ps.getGeometryPropertyName());
+	}
+
+	@Test
+	public void testCorrectGeometryPropertynamePolygon() throws IOException {
+		PolygonSymbolizer ps = StylingUtil.STYLE_BUILDER
+				.createPolygonSymbolizer();
+		FeatureSource<SimpleFeatureType, SimpleFeature> fs = GTTestingUtil.TestDatasetsVector.polygonSnow
+				.getFeatureSource();
+		assertNull(ps.getGeometryPropertyName());
+		StylingUtil.correctGeometryPropertyname(fs.getSchema(), ps);
+		assertEquals("the_geom", ps.getGeometryPropertyName());
+	}
+
+	@Test
+	public void testCopyColorMapEntry() {
+		ColorMapEntry cme = StylingUtil.createColorMapEntry("aLabel", 102.,
+				Color.RED, .8);
+
+		ColorMapEntry cme2 = StylingUtil.copy(cme);
+
+		assertEquals(cme.getLabel(), cme2.getLabel());
+		assertEquals(cme.getQuantity(), cme2.getQuantity());
+		assertEquals(cme.getOpacity(), cme2.getOpacity());
+		assertEquals(cme.getColor(), cme2.getColor());
+	}
+
+}
\ No newline at end of file


Property changes on: trunk/schmitzm-gt/src/test/java/de/schmitzm/geotools/styling/StylingUtilTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id URL
Name: svn:eol-style
   + native



More information about the Schmitzm-commits mailing list