[Schmitzm-commits] r1412 - in trunk/schmitzm-gt/src/test/java/de: appl schmitzm schmitzm/geotools schmitzm/geotools/testing

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed Jan 26 21:33:06 CET 2011


Author: alfonx
Date: 2011-01-26 21:33:06 +0100 (Wed, 26 Jan 2011)
New Revision: 1412

Added:
   trunk/schmitzm-gt/src/test/java/de/schmitzm/geotools/
   trunk/schmitzm-gt/src/test/java/de/schmitzm/geotools/testing/
   trunk/schmitzm-gt/src/test/java/de/schmitzm/geotools/testing/GTTestingUtil.java
Removed:
   trunk/schmitzm-gt/src/test/java/de/appl/util/
   trunk/schmitzm-gt/src/test/java/de/schmitzm/data/
Log:


Added: trunk/schmitzm-gt/src/test/java/de/schmitzm/geotools/testing/GTTestingUtil.java
===================================================================
--- trunk/schmitzm-gt/src/test/java/de/schmitzm/geotools/testing/GTTestingUtil.java	2011-01-26 20:32:43 UTC (rev 1411)
+++ trunk/schmitzm-gt/src/test/java/de/schmitzm/geotools/testing/GTTestingUtil.java	2011-01-26 20:33:06 UTC (rev 1412)
@@ -0,0 +1,265 @@
+package de.schmitzm.geotools.testing;
+
+import java.awt.Graphics2D;
+import java.awt.Rectangle;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.nio.charset.Charset;
+
+import org.geotools.coverage.grid.GridCoverage2D;
+import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader;
+import org.geotools.data.DataStore;
+import org.geotools.data.DataUtilities;
+import org.geotools.data.FeatureSource;
+import org.geotools.data.shapefile.ShapefileDataStore;
+import org.geotools.feature.FeatureCollection;
+import org.geotools.gce.arcgrid.ArcGridReader;
+import org.geotools.gce.geotiff.GeoTiffReader;
+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.Style;
+import org.junit.Ignore;
+import org.opengis.feature.simple.SimpleFeature;
+import org.opengis.feature.simple.SimpleFeatureType;
+
+import de.schmitzm.geotools.StyledFS;
+import de.schmitzm.geotools.StyledGridCoverageReader;
+import de.schmitzm.geotools.io.GeoImportUtil;
+import de.schmitzm.geotools.styling.StylingUtil;
+import de.schmitzm.io.IOUtil;
+import de.schmitzm.testing.TestingUtil;
+
+/**
+ * Helpers to test Swing applications in general. <br/>
+ * If not set to @Ignore, HUDSON will complain
+ * "java.lang.Exception: No runnable methods"
+ */
+ at Ignore
+public class GTTestingUtil extends TestingUtil{
+
+	/**
+	 * List of available vector test datasets
+	 */
+	public static enum TestDatasetsVector {
+
+		/**
+		 * This Shapefile has been created with arabic characters in the dbf
+		 * header aka. attribute names
+		 */
+		arabicInHeader(
+				"/schmitzm/geotools/feature/arabicShapefiles/arabicwitharabicinheader.shp"),
+		/**
+		 * Enhält Daten, welche den KECK Daten ähnlich sind
+		 */
+		kreise(
+				"/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart.shp"),
+		/**
+		 * A Shapefile with world borders
+		 */
+		countryShp("/shapes/shp countries/country.shp"),
+		/**
+		 * A tiny Shapefile with an .sld that contains a QuantilesClassification
+		 * with manually adapted colors
+		 */
+		polygonSnow("/shapes/polygonSnowShape/polygonLayerSnow.shp"),
+
+		/**
+		 * A tiny Shapefile with an .sld that contains a QuantilesClassification
+		 * with manually adapted colors
+		 */
+		lineBrokenQuix("/shapes/lineBrokenQix/Deu_Fluesse.shp");
+
+		private final String resLoc;
+
+		private TestDatasetsVector(String resLoc) {
+			this.resLoc = resLoc;
+		}
+
+		public String getResLoc() {
+			return resLoc;
+		}
+
+		public URL getUrl() {
+			return TestingUtil.class.getResource(getResLoc());
+		}
+
+		public FeatureSource<SimpleFeatureType, SimpleFeature> getFeatureSource()
+				throws IOException {
+			DataStore ds = getDataStore();
+			return ds.getFeatureSource(ds.getTypeNames()[0]);
+		}
+
+		public DataStore getDataStore() throws IOException {
+			DataStore ds = GeoImportUtil.readDataStoreFromShape(getUrl(), null);
+			return ds;
+		}
+
+		public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollection()
+				throws IOException {
+			return getFeatureSource().getFeatures();
+		}
+
+		public StyledFS getStyledFS() throws IOException {
+			return new StyledFS(getFeatureSource());
+		}
+	}
+
+	/**
+	 * List of available vector test datasets
+	 */
+	public static enum TestDatasetsRaster {
+		geotiffWithSld("/rasters/rasterGeotiffWithSLD/geotiffwithsld.tif"), geotiffRGBWithoutSLD(
+				"/rasters/rasterGeotiffRGBWithoutSLD/geotiff_rgb_ohnesld.tif"), arcAscii(
+				"/rasters/rasterASCIIWithSLDTransparency/asciiWithSldTransparency.asc");
+
+		private final String resLoc;
+
+		private TestDatasetsRaster(String resLoc) {
+			this.resLoc = resLoc;
+		}
+
+		public String getResLoc() {
+			return resLoc;
+		}
+
+		public URL getUrl() {
+			return TestingUtil.class.getResource(getResLoc());
+		}
+
+		public AbstractGridCoverage2DReader getReader() throws IOException {
+			if (resLoc.endsWith("tif"))
+				return new GeoTiffReader(getUrl());
+			else if (resLoc.endsWith("asc"))
+				return new ArcGridReader(getUrl());
+			return null;
+		}
+
+		public GridCoverage2D getCoverage() throws Exception {
+			if (resLoc.endsWith("tif"))
+				return GeoImportUtil.readGridFromGeoTiff(DataUtilities
+						.urlToFile(getUrl()));
+			else if (resLoc.endsWith("asc"))
+				return GeoImportUtil.readGridFromArcInfoASCII(DataUtilities
+						.urlToFile(getUrl()));
+			return null;
+
+		}
+
+		public StyledGridCoverageReader getStyled() throws IOException {
+			return new StyledGridCoverageReader(getReader());
+		}
+
+		public Style getSldStyle() {
+			return StylingUtil.loadSLD(DataUtilities.changeUrlExt(getUrl(),
+					"sld"))[0];
+		}
+	}
+
+	/**
+	 * Takes a URL to a shapefile, that may be inside a jar. The retuned UTL
+	 * points to a version of the shapefile copied to the tmp dir.
+	 * 
+	 * @throws IOException
+	 * @throws URISyntaxException
+	 */
+	public static URL copyShapefileToTemp(URL urlToShape) throws IOException,
+			URISyntaxException {
+		File tempDir = new File(IOUtil.getTempDir(), "shape"
+				+ (System.currentTimeMillis()));
+		tempDir.mkdir();
+
+		/**
+		 * SHP file!
+		 */
+		final URL shpURL = IOUtil.changeUrlExt(urlToShape, "shp");
+		String fileName = shpURL.getPath();
+		if (shpURL.getPath().lastIndexOf("/") > 0)
+			fileName = shpURL.getPath().substring(
+					shpURL.getPath().lastIndexOf("/"));
+
+		IOUtil.copyUrl(shpURL, tempDir, false);
+
+		final URL shxURL = IOUtil.changeUrlExt(urlToShape, "shx");
+		IOUtil.copyUrl(shxURL, tempDir, false);
+
+		final URL grxURL = IOUtil.changeUrlExt(urlToShape, "grx");
+		IOUtil.copyURLNoException(grxURL, tempDir, false);
+
+		final URL fixURL = IOUtil.changeUrlExt(urlToShape, "fix");
+		IOUtil.copyURLNoException(fixURL, tempDir, false);
+
+		final URL qixURL = IOUtil.changeUrlExt(urlToShape, "qix");
+		IOUtil.copyURLNoException(qixURL, tempDir, false);
+
+		final URL xmlURL = IOUtil.changeUrlExt(urlToShape, "shp.xml");
+		IOUtil.copyURLNoException(xmlURL, tempDir, false);
+
+		final URL dbfURL = IOUtil.changeUrlExt(urlToShape, "dbf");
+		IOUtil.copyUrl(dbfURL, tempDir, false);
+
+		/**
+		 * Optionally copy a .cpg file that describes the
+		 */
+		final URL cpgURL = IOUtil.changeUrlExt(urlToShape, "cpg");
+		IOUtil.copyURLNoException(cpgURL, tempDir, false);
+
+		return DataUtilities.fileToURL(new File(tempDir, fileName));
+	}
+
+	/**
+	 * Stellt Test-FeatureCollections zur Verfügung
+	 */
+	public static FeatureSource<SimpleFeatureType, SimpleFeature> getTestFeatureSource(
+			TestDatasetsVector dataset) throws IOException {
+		// Testdatenshape einlesen
+		// URL resourceUrl = dataset.getUrl();
+		//
+		// if (resourceUrl == null)
+		// throw new IllegalStateException(dataset + " wurde nicht gefunden!");
+
+		ShapefileDataStore store = (ShapefileDataStore) dataset.getDataStore();
+
+		if (dataset == TestDatasetsVector.arabicInHeader) {
+			// TODO overthink
+			store.setStringCharset(Charset.forName("windows-1256"));
+		}
+
+		FeatureSource<SimpleFeatureType, SimpleFeature> fs = store
+				.getFeatureSource();
+
+		if (fs == null)
+			throw new IllegalStateException(
+					"Testfeatures konnten nicht gelesen werden");
+
+		return fs;
+	}
+
+
+	public static BufferedImage visualize(DefaultMapLayer dml) throws Throwable {
+		DefaultMapContext mc = new DefaultMapContext(dml.getFeatureSource()
+				.getSchema().getCoordinateReferenceSystem());
+
+		mc.addLayer(dml);
+
+		StreamingRenderer sr = new StreamingRenderer();
+		sr.setContext(mc);
+
+		final BufferedImage bi = new BufferedImage(100, 100,
+				BufferedImage.TYPE_4BYTE_ABGR);
+		Graphics2D g2d = bi.createGraphics();
+		ReferencedEnvelope geoArea = new ReferencedEnvelope(dml
+				.getFeatureSource().getBounds());
+		sr.paint(g2d, new Rectangle(100, 100), geoArea);
+		g2d.dispose();
+
+		TestingUtil.testGui(bi, 1);
+
+		return bi;
+	}
+
+}


Property changes on: trunk/schmitzm-gt/src/test/java/de/schmitzm/geotools/testing/GTTestingUtil.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