[Schmitzm-commits] r382 - in branches/1.0-gt2-2.6/src: schmitzm/geotools/gui skrueger skrueger/geotools/io

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Sep 4 19:02:59 CEST 2009


Author: alfonx
Date: 2009-09-04 19:02:58 +0200 (Fri, 04 Sep 2009)
New Revision: 382

Modified:
   branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/JMapPane.java
   branches/1.0-gt2-2.6/src/skrueger/RasterLegendData.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/io/GeoImportUtilURL.java
Log:
* ImagePyramidReader and ImageMosaicReader now work with URLs again.

Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/JMapPane.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/JMapPane.java	2009-09-04 14:42:13 UTC (rev 381)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/JMapPane.java	2009-09-04 17:02:58 UTC (rev 382)
@@ -2308,11 +2308,10 @@
 
 			try {
 				SimpleFeature onlyFeature = fIt.next();
-				GridCoverage2D grid = (GridCoverage2D) onlyFeature
-						.getAttribute(1);
+				
+				// GridCoverage2D or ImagePyramidReader
+				return onlyFeature.getAttribute(1);
 
-				return grid;
-
 			} finally {
 				fIt.close();
 			}

Modified: branches/1.0-gt2-2.6/src/skrueger/RasterLegendData.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/RasterLegendData.java	2009-09-04 14:42:13 UTC (rev 381)
+++ branches/1.0-gt2-2.6/src/skrueger/RasterLegendData.java	2009-09-04 17:02:58 UTC (rev 382)
@@ -61,7 +61,6 @@
 	 * indicating nominal values in the raster (e.g. classifications)
 	 */
 	public RasterLegendData(boolean paintGaps) {
-		super();
 		this.paintGaps = paintGaps;
 	}
 

Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/io/GeoImportUtilURL.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/io/GeoImportUtilURL.java	2009-09-04 14:42:13 UTC (rev 381)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/io/GeoImportUtilURL.java	2009-09-04 17:02:58 UTC (rev 382)
@@ -31,7 +31,9 @@
 
 import java.awt.geom.Rectangle2D;
 import java.awt.image.BufferedImage;
+import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
 import java.net.URL;
 
 import javax.imageio.IIOException;
@@ -40,6 +42,7 @@
 import org.apache.log4j.Logger;
 import org.geotools.coverage.grid.GridCoverage2D;
 import org.geotools.coverage.grid.GridCoverageFactory;
+import org.geotools.data.DataUtilities;
 import org.geotools.factory.Hints;
 import org.geotools.gce.geotiff.GeoTiffReader;
 import org.geotools.geometry.Envelope2D;
@@ -178,11 +181,61 @@
 		 * .de/atlas/raster_textur00949608497.jar!/ad/data
 		 * /raster_textur00949608497/textur.tif
 		 */
-		GeoTiffReader reader = new GeoTiffReader(input, hints);
 
-		gc = (GridCoverage2D) reader.read(readParams);
-		LOGGER.debug("... was successfull!");
-		return gc;
+		try {
+
+			GeoTiffReader reader = new GeoTiffReader(input, hints);
+
+			gc = (GridCoverage2D) reader.read(readParams);
+			LOGGER.debug("... was successfull!");
+			return gc;
+		} catch (Exception e) {
+			// keine Geo-Informationen in Tiff
+			// --> Raster ueber ImageIO einlesen und WorldFile/ProjectionFile
+			// verwenden
+			LOGGER.warn("No geo information found in '" + input
+					+ "'. Using world- and prj-file...");
+
+			BufferedImage im = null;
+			double[] tfwInfo = null ;
+			if (input instanceof File) {
+				im = ImageIO.read((File) input);
+				tfwInfo = readWorldFile(IOUtil.changeFileExt((File)input, "tfw"));
+				if (crs == null)
+					crs = determineProjection((File)input);
+			} else if (input instanceof URL) {
+				tfwInfo = readWorldFile(IOUtil.changeUrlExt((URL)input, "tfw").openStream());
+				im = ImageIO.read((URL) input);
+				if (crs == null)
+					crs = determineProjection((URL)input);
+			}
+
+			if (im == null)
+				throw new IIOException(
+						"No image reader found for this image type!");
+			// World-File einlesen
+			
+			float w = (float) (im.getWidth() * tfwInfo[0]); // reale Breite =
+			// RasterSpalten * hor.
+			// Aufloesung
+			float h = (float) (im.getHeight() * (-tfwInfo[3])); // reale Hoehe =
+			// RasterZeilen *
+			// vert. Aufloesung
+			float x = (float) tfwInfo[4]; // Suedwestliche Ecke!
+			float y = (float) tfwInfo[5] - h; // Suedwestliche Ecke (im tfw-File
+			// steht die Nordwestliche!)
+			// ggf. Projektion einlesen
+			Envelope2D envelope = new Envelope2D(crs, new Rectangle2D.Float(x,
+					y, w, h));
+			// WICHTIG: Name des Rasters sollte Leer-String sein, da ansonsten
+			// das
+			// Coloring des Rasters nicht klappt.
+			// --> Name der Categories muss (warum auch immer) mit dem Namen
+			// des Rasters uebereinstimmen!!!
+			gc = new GridCoverageFactory().create("", im.copyData(null),
+					envelope);
+			return gc;
+		}
 	}
 
 	//		



More information about the Schmitzm-commits mailing list