[Schmitzm-commits] r814 - in trunk: src/schmitzm/geotools/io src_junit/schmitzm src_junit/schmitzm/jfree src_junit/schmitzm/jfree/feature src_junit/schmitzm/jfree/feature/style src_junit/schmitzm/jfree/feature/style/testLineChartShape src_junit/skrueger src_junit/skrueger/versionnumber

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Apr 23 15:17:40 CEST 2010


Author: alfonx
Date: 2010-04-23 15:17:35 +0200 (Fri, 23 Apr 2010)
New Revision: 814

Added:
   trunk/src_junit/schmitzm/jfree/
   trunk/src_junit/schmitzm/jfree/feature/
   trunk/src_junit/schmitzm/jfree/feature/style/
   trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java
   trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/
   trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.dbf
   trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.prj
   trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.qpj
   trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.shp
   trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.shx
   trunk/src_junit/skrueger/versionnumber/
   trunk/src_junit/skrueger/versionnumber/ReleaseUtilTest.java
Modified:
   trunk/src/schmitzm/geotools/io/GeoExportUtil.java
   trunk/src/schmitzm/geotools/io/GeoImportUtil.java
Log:
Test f?\195?\188r skrueger.versionnumber und f?\195?\188r LineChart gebaut. Bei LineChart inkl. testdatensatz. In GeoImportUtil ein bisschen aufger?\195?\164umt und mit try/finally das disposen des ShapeFileWriters garantiert.

Modified: trunk/src/schmitzm/geotools/io/GeoExportUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/io/GeoExportUtil.java	2010-04-22 00:08:48 UTC (rev 813)
+++ trunk/src/schmitzm/geotools/io/GeoExportUtil.java	2010-04-23 13:17:35 UTC (rev 814)
@@ -90,31 +90,39 @@
 			FeatureCollection<SimpleFeatureType, SimpleFeature> fc, File outFile)
 			throws Exception {
 		// DataStore fuer Ausgabe-Datei oeffnen
-	    ShapefileDataStore shpStore = null;
-	    try {
-	      shpStore = new ShapefileDataStore(outFile.toURI().toURL());
-	    } catch (IllegalArgumentException err) {
-	      // ShapefileDataStore schmeisst eine IllegalArgumentException,
-	      // wenn Dateiname nicht ".shp", ".dbf", ... ist
-	      // -> Erweiterung anhaengen
-	      outFile = IOUtil.appendFileExt(outFile, ".shp");
-	      shpStore = new ShapefileDataStore(outFile.toURI().toURL());
-	    }
-		// shpStore.createSchema(featureReader.getFeatureType());
-		shpStore.createSchema(fc.getSchema());
-		// FeatureStore aus dem ShapeFile-DataStore ermitteln
-		FeatureSource<SimpleFeatureType, SimpleFeature> source = shpStore
-				.getFeatureSource();
+		ShapefileDataStore shpStore = null;
+		try {
+			shpStore = new ShapefileDataStore(outFile.toURI().toURL());
+		} catch (IllegalArgumentException err) {
+			// ShapefileDataStore schmeisst eine IllegalArgumentException,
+			// wenn Dateiname nicht ".shp", ".dbf", ... ist
+			// -> Erweiterung anhaengen
+			outFile = IOUtil.appendFileExt(outFile, ".shp");
+			shpStore = new ShapefileDataStore(outFile.toURI().toURL());
+		}
 
-		// TODO 26 @Martin?! Du hattest hier gecastet... ob das so noch geht?!
-		// FeatureStore featureStore = (FeatureStore)source;
-		FeatureStore<SimpleFeatureType, SimpleFeature> featureStore = (FeatureStore<SimpleFeatureType, SimpleFeature>) source;
+		try {
+			shpStore.createSchema(fc.getSchema());
+			// FeatureStore aus dem ShapeFile-DataStore ermitteln
+			FeatureSource<SimpleFeatureType, SimpleFeature> source = shpStore
+					.getFeatureSource();
 
-		// Features schreiben
-		Transaction transaction = featureStore.getTransaction();
-		featureStore.addFeatures(fc);
-		transaction.commit();
-		transaction.close();
+			FeatureStore<SimpleFeatureType, SimpleFeature> featureStore = (FeatureStore<SimpleFeatureType, SimpleFeature>) source;
+
+			// Features schreiben
+			Transaction transaction = featureStore.getTransaction();
+			try {
+				featureStore.addFeatures(fc);
+				transaction.commit();
+			} catch (Exception e) {
+				transaction.rollback();
+			} finally {
+				transaction.close();
+			}
+
+		} finally {
+			shpStore.dispose();
+		}
 	}
 
 	/**
@@ -312,7 +320,7 @@
 	 *            Koordinaten-System
 	 * @param outputFile
 	 *            Datei in die die Projektion geschrieben wird
-	 *            
+	 * 
 	 * @exception IOException
 	 *                falls die Datei nicht geschrieben werden kann
 	 */

Modified: trunk/src/schmitzm/geotools/io/GeoImportUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/io/GeoImportUtil.java	2010-04-22 00:08:48 UTC (rev 813)
+++ trunk/src/schmitzm/geotools/io/GeoImportUtil.java	2010-04-23 13:17:35 UTC (rev 814)
@@ -230,8 +230,24 @@
 	 * 
 	 * @param url
 	 *            {@link URL} to Shape-File
+	 *            
+	 * @return {@link FeatureCollection} that was read
+	 * @throws IOException 
+	 */
+	public static FeatureCollection<SimpleFeatureType, SimpleFeature> readFeaturesFromShapeURL(URL url) throws IOException {
+		return readFeaturesFromShapeURL(url, null);
+	}
+			
+	/**
+	 * Diese Methode extrahiert saemtliche Features aus einem ShapeFile-Projekt
+	 * (<code><i>name</i>.shp <i>name</i>.prj <i>name</i>.dbf ...</code>) und
+	 * speichert diese in einer
+	 * <code>org.geotools.feature.FeatureCollection</code>.<br>
+	 * 
+	 * @param url
+	 *            {@link URL} to Shape-File
 	 * @param prjUrl
-	 *            {@link URL} zu .prj Datei des Shape-File
+	 *            {@link URL} zu .prj Datei des Shape-File. Darf <code>null</code> sein.
 	 * 
 	 * 
 	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons

Added: trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java
===================================================================
--- trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java	2010-04-22 00:08:48 UTC (rev 813)
+++ trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java	2010-04-23 13:17:35 UTC (rev 814)
@@ -0,0 +1,48 @@
+package schmitzm.jfree.feature.style;
+
+import static org.junit.Assert.*;
+
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.net.URL;
+
+import org.apache.log4j.Logger;
+import org.geotools.feature.FeatureCollection;
+import org.junit.Test;
+import org.opengis.feature.simple.SimpleFeature;
+import org.opengis.feature.simple.SimpleFeatureType;
+
+import schmitzm.geotools.io.GeoImportUtil;
+
+public class FeatureChartStyleTest {
+	private static Logger log = Logger.getLogger(FeatureChartStyleTest.class);
+	
+	@Test
+	public void testLineChart() throws IOException {
+		
+		// Testdatenshape einlesen
+		URL resourceUrl = getClass().getResource("/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.shp");
+		assertNotNull("testKreiseLineChart2.shp wurde nicht gefunden!", resourceUrl);
+		FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = GeoImportUtil.readFeaturesFromShapeURL( resourceUrl);
+		assertNotNull("Testfeatures konnten nicht aus "+resourceUrl+" gelesen werden", testFeatures);
+		
+		// Daten auf korrektheit überprüfen
+		assertEquals("Testfeatures muss 2x3 Features enthalten",2*3,testFeatures.size());
+		String groupAttribName = "kgs5"; // KreisZahl
+		SimpleFeatureType testDatenSchema = testFeatures.getSchema();
+		assertNotNull(testDatenSchema.getDescriptor(groupAttribName));
+		String variablenAttribName = "dm_u3"; // Deutsche "Männer" unter 3 Jahren
+		assertNotNull(testDatenSchema.getDescriptor(variablenAttribName));
+		String labelAttribName = "krs_name"; // Attribute mit Label für Series
+		assertNotNull(testDatenSchema.getDescriptor(labelAttribName));
+		String rangeAttribName = "jahr"; // Diese Variable soll auf der X-Achse angezeigt werden
+		assertNotNull(testDatenSchema.getDescriptor(rangeAttribName));
+
+		
+		BufferedImage chartpng = null;
+		
+		// TODO Linehcart erstellen
+		
+		assertNotNull("Es konnte kein PNG aus dem Chart erstellt werden!", chartpng);
+	}
+}


Property changes on: trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id URL
Name: svn:eol-style
   + native

Added: trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.dbf
===================================================================
(Binary files differ)


Property changes on: trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.dbf
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.prj
===================================================================
--- trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.prj	2010-04-22 00:08:48 UTC (rev 813)
+++ trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.prj	2010-04-23 13:17:35 UTC (rev 814)
@@ -0,0 +1 @@
+GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
\ No newline at end of file

Added: trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.qpj
===================================================================
--- trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.qpj	2010-04-22 00:08:48 UTC (rev 813)
+++ trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.qpj	2010-04-23 13:17:35 UTC (rev 814)
@@ -0,0 +1 @@
+GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9108"]],AUTHORITY["EPSG","4326"]]

Added: trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.shp
===================================================================
(Binary files differ)


Property changes on: trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.shp
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.shx
===================================================================
(Binary files differ)


Property changes on: trunk/src_junit/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart2.shx
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/src_junit/skrueger/versionnumber/ReleaseUtilTest.java
===================================================================
--- trunk/src_junit/skrueger/versionnumber/ReleaseUtilTest.java	2010-04-22 00:08:48 UTC (rev 813)
+++ trunk/src_junit/skrueger/versionnumber/ReleaseUtilTest.java	2010-04-23 13:17:35 UTC (rev 814)
@@ -0,0 +1,17 @@
+package skrueger.versionnumber;
+
+import static org.junit.Assert.*;
+
+import org.apache.log4j.Logger;
+import org.junit.Test;
+
+public class ReleaseUtilTest {
+	private static Logger log = Logger.getLogger(ReleaseUtilTest.class);
+
+	@Test
+	public void testExtractMinVersionFromString() {
+		assertEquals(0,ReleaseUtil.extractMinVersionFromString("0.0"));
+		assertEquals(5,ReleaseUtil.extractMinVersionFromString("1.5-SNAPSHOT"));
+		assertEquals(5,ReleaseUtil.extractMinVersionFromString("1.5r234"));
+	}
+}


Property changes on: trunk/src_junit/skrueger/versionnumber/ReleaseUtilTest.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