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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Sep 4 13:33:04 CEST 2009


Author: alfonx
Date: 2009-09-04 13:33:03 +0200 (Fri, 04 Sep 2009)
New Revision: 377

Modified:
   branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/LegendIconFeatureRenderer.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/io/GeoImportUtilURL.java
Log:
* Patched the ImagePyramid and ImageMosaic classes from GT26-m2 again, because their Transparency doesn't work, nor do they support URLs.
* URL support is not yet fixed.

Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java	2009-09-04 09:24:36 UTC (rev 376)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java	2009-09-04 11:33:03 UTC (rev 377)
@@ -1755,7 +1755,7 @@
 				// The labeltext is read from the SLD. Its either the title
 				// directly, or interpreted as OneLine Code
 				// ****************************************************************************
-				final String rawText = rule.getTitle();
+				final String rawText = rule.getDescription().getTitle().toString();
 
 				Translation labelT = new Translation();
 				labelT.fromOneLine(rawText);

Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/LegendIconFeatureRenderer.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/LegendIconFeatureRenderer.java	2009-09-04 09:24:36 UTC (rev 376)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/LegendIconFeatureRenderer.java	2009-09-04 11:33:03 UTC (rev 377)
@@ -42,13 +42,11 @@
  **/
 package skrueger.geotools;
 
-import java.awt.Canvas;
 import java.awt.Color;
 import java.awt.Dimension;
 import java.awt.Graphics2D;
 import java.awt.RenderingHints;
 import java.awt.image.BufferedImage;
-import java.awt.image.ImageObserver;
 
 import javax.swing.tree.DefaultTreeCellRenderer;
 
@@ -97,7 +95,7 @@
  * @author Stefan Alfons Krüger
  */
 public class LegendIconFeatureRenderer extends DefaultTreeCellRenderer {
-	private static final Dimension SIZE = new Dimension(30,20);
+//	private static final Dimension SIZE = new Dimension(30,20);
 
 	Logger LOGGER = Logger.getLogger(LegendIconFeatureRenderer.class);
 
@@ -111,18 +109,17 @@
 
 	public static LegendIconFeatureRenderer getInstance() {
 		// In GT 2.4.5 it we have to create a new one all the time!
+		
+		// TODO TEST, whether we still need to recreate the renderer here....
 		return new LegendIconFeatureRenderer();
 //		 return instance;
 	}
 
-	/** The image produced at <code>produceLegendGraphic</code> */
-	private BufferedImage legendGraphic;
-
 	/**
 	 * used to create sample point shapes with LiteShape (not lines nor
 	 * polygons)
 	 */
-	private static final GeometryFactory geomFac = new GeometryFactory();
+	private static final GeometryFactory geomFac = FeatureUtil.GEOMETRY_FACTORY;
 
 	/** padding percentage factor at both sides of the legend. */
 	private static final float hpaddingFactor = 0.11f; // was 0.15
@@ -131,12 +128,6 @@
 	private static final float vpaddingFactor = 0.08f; // was 0.15
 
 	/**
-	 * Image observer to help in creating the stack like legend graphic from the
-	 * images created for each rule
-	 */
-	private static final ImageObserver imgObs = new Canvas();
-
-	/**
 	 * Just a holder to avoid creating many polygon shapes from inside
 	 * <code>getSampleShape()</code>
 	 */

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 09:24:36 UTC (rev 376)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/io/GeoImportUtilURL.java	2009-09-04 11:33:03 UTC (rev 377)
@@ -43,33 +43,40 @@
 import org.geotools.factory.Hints;
 import org.geotools.gce.geotiff.GeoTiffReader;
 import org.geotools.geometry.Envelope2D;
+import org.opengis.parameter.GeneralParameterValue;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 
 import schmitzm.geotools.io.GeoImportUtil;
 import schmitzm.io.IOUtil;
 
 /**
- * Erweiterungen von Martin's {@link GeoImportUtil} classe fuer die konsequente Benutzung mit {@link URL}s.
- * TODO Diese Klasse sollte vielleicht mit der {@link GeoImportUtil} zusammengefuegt werden.
- *
+ * Erweiterungen von Martin's {@link GeoImportUtil} classe fuer die konsequente
+ * Benutzung mit {@link URL}s. TODO Diese Klasse sollte vielleicht mit der
+ * {@link GeoImportUtil} zusammengefuegt werden.
+ * 
  * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Kr&uuml;ger</a>
- *
+ * 
  */
 public class GeoImportUtilURL extends GeoImportUtil {
-	final static private Logger LOGGER = Logger.getLogger(GeoImportUtilURL.class);
+	final static private Logger LOGGER = Logger
+			.getLogger(GeoImportUtilURL.class);
 
 	/**
-	 * Read a {@link GridCoverage2D} from an image file. .prj and .wld files are usually expected
+	 * Read a {@link GridCoverage2D} from an image file. .prj and .wld files are
+	 * usually expected
 	 */
 	public static GridCoverage2D readGridFromImage(URL url) throws IOException {
 		return readGridFromImage(url, null);
 	}
 
 	/**
-	 * Read a {@link GridCoverage2D} from an image file. .wld file is usually expected also. The CRS can be given as the crs parameter. null is valid.
-	 *
-	 * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
-	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Kr&uuml;ger</a>
+	 * Read a {@link GridCoverage2D} from an image file. .wld file is usually
+	 * expected also. The CRS can be given as the crs parameter. null is valid.
+	 * 
+	 * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
+	 *         (University of Bonn/Germany)
+	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
+	 *         Kr&uuml;ger</a>
 	 */
 	public static GridCoverage2D readGridFromImage(URL url,
 			CoordinateReferenceSystem crs) throws IOException {
@@ -82,10 +89,11 @@
 		// World-File einlesen
 		double[] tfwInfo = null;
 
-		for (WORLD_POSTFIXES pf : WORLD_POSTFIXES.values()){
+		for (WORLD_POSTFIXES pf : WORLD_POSTFIXES.values()) {
 			if (tfwInfo == null) {
 				try {
-					tfwInfo = readWorldFile( IOUtil.changeUrlExt(url, pf.toString() ).openStream());
+					tfwInfo = readWorldFile(IOUtil.changeUrlExt(url,
+							pf.toString()).openStream());
 				} catch (Exception e) {
 				}
 			}
@@ -94,7 +102,7 @@
 		if (tfwInfo == null)
 			throw new IllegalArgumentException(
 					"No georeferencing information found.\n"
-					+ "Attach a .wld file to "+url+"please.");
+							+ "Attach a .wld file to " + url + "please.");
 
 		float w = (float) (im.getWidth() * tfwInfo[0]); // reale Breite =
 		// RasterSpalten *
@@ -109,14 +117,15 @@
 		// Nordwestliche!)
 		// ggf. Projektion einlesen
 		if (crs == null) {
-			crs = determineProjection( IOUtil.changeUrlExt(url, "prj") );
+			crs = determineProjection(IOUtil.changeUrlExt(url, "prj"));
 		}
 		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 und ColorMapEntries-Labels muss (warum auch immer) mit dem Namen
+		// --> Name der Categories und ColorMapEntries-Labels muss (warum auch
+		// immer) mit dem Namen
 		// des Rasters uebereinstimmen!!!
 		gc = new GridCoverageFactory().create("", im, envelope);
 
@@ -124,122 +133,100 @@
 	}
 
 	/**
-	 * Diese Methode importiert ein Raster aus einer Datei im GeoTIFF-Format.
-	 * Zunaechst wird versucht, die Geo-Informationen (Referenz+CRS) aus den
-	 * TIFF-Metadaten zu ermitteln. Ist dies nicht erfolgreich, werden ein
-	 * gleichnamiges World-File (.tfw) und Projection-File (.prj) herangezogen.
-	 * Als Projektion (.prj) ist sowohl ein EPSG-Code "EPSG:...", als auch eine
-	 * WKT-Definition erlaubt. Kann kein CRS ermitteln werden, wird
-	 * {@link #DEFAULT_CRS} als CRS verwendet.
-	 *
-	 * @param geotiffURL
-	 *            URL to GeoTIFF-File
+	 * @param input
+	 *            URL, File oder InputStream to a GeoTIFF-File
 	 * @param crs
 	 *            erzwungenes CoordinateReferenceSystem fuer das Raster (kann
 	 *            {@code null} sein)
-	 * @throws java.lang.Exception
-	 *             bei irgendeinem Fehler
-	 *
+	 * 
 	 * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
 	 *         (University of Bonn/Germany)
-	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Kr&uuml;ger</a>
+	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
+	 *         Kr&uuml;ger</a>
+	 * 
+	 * @param readParams
+	 *            May be {@link NullPointerException}. Otherwise an array of
+	 *            {@link GeneralParameterValue}s
 	 */
-	public static GridCoverage2D readGridFromGeoTiff(URL geotiffURL,
-			CoordinateReferenceSystem crs) throws Exception {
+	public static GridCoverage2D readGridFromGeoTiff(Object input,
+			CoordinateReferenceSystem crs, GeneralParameterValue[] readParams)
+			throws IOException {
 		GridCoverage2D gc = null;
-		LOGGER.debug("Loading GeoTiff from URL = " + geotiffURL + " now.");
+		LOGGER.debug("Loading GeoTiff from URL = " + input + " now.");
 
 		// Versuchen Geo-Information aus Tiff zu lesen
-		try {
 
-			// Wenn CRS angegeben, dieses durch Hint erzwingen
-			Hints hints = new Hints();
+		// Wenn CRS angegeben, dieses durch Hint erzwingen
+		Hints hints = new Hints();
 
-			if (crs != null)
-				hints.put(Hints.DEFAULT_COORDINATE_REFERENCE_SYSTEM, crs);
-			// Reader (mit Metadaten) erzeugen
+		if (crs != null)
+			hints.put(Hints.DEFAULT_COORDINATE_REFERENCE_SYSTEM, crs);
+		// Reader (mit Metadaten) erzeugen
 
-			LOGGER.debug("First try to create GeoTiff reader");
+		LOGGER.debug("First try to create GeoTiff reader");
 
-			/**
-			 * Attention, Attention: The GeoTiffReader fails for URLs like:
-			 * 
-			 * jar:file:/home/sdsd/ad/atlas/raster_textur00949608497.jar!/ad/data/raster_textur00949608497/textur.tif
-			 * 
-			 * It should be converted to something like:
-			 * jar:http:///atlas/raster_textur00949608497.jar!/ad/data/raster_textur00949608497/textur.tif
-			 * jar:http://www.wikisquare.de/atlas/raster_textur00949608497.jar!/ad/data/raster_textur00949608497/textur.tif
-			 */
-			GeoTiffReader reader = new GeoTiffReader(geotiffURL, hints);
+		/**
+		 * Attention, Attention: The GeoTiffReader fails for URLs like:
+		 * 
+		 * jar:file:/home/sdsd/ad/atlas/raster_textur00949608497.jar!/ad/data/
+		 * raster_textur00949608497/textur.tif
+		 * 
+		 * It should be converted to something like:
+		 * jar:http:///atlas/raster_textur00949608497
+		 * .jar!/ad/data/raster_textur00949608497/textur.tif
+		 * jar:http://www.wikisquare
+		 * .de/atlas/raster_textur00949608497.jar!/ad/data
+		 * /raster_textur00949608497/textur.tif
+		 */
+		GeoTiffReader reader = new GeoTiffReader(input, hints);
 
-			// Wenn kein Referenzsystem vorhanden, versuchen ein prj-File zu
-			// verwenden
-			if (reader.getOriginalEnvelope().getCoordinateReferenceSystem() == null) {
-				LOGGER
-						.warn("Second try because no projection information found in GeoTIFF. Using prj-file...");
-
-				final CoordinateReferenceSystem determineProjection = determineProjection(IOUtil.changeUrlExt(
-						geotiffURL, "prj"));
-				hints.put(Hints.DEFAULT_COORDINATE_REFERENCE_SYSTEM,
-						determineProjection);
-				reader = new GeoTiffReader(geotiffURL, hints);
-			}
-			gc = (GridCoverage2D) reader.read(null);
-			LOGGER.debug("... was successfull!");
-		} catch (UnsupportedOperationException err) {
-			LOGGER.debug("... failed.");
-			LOGGER.error(err);
-			LOGGER.warn("No GeoTIFF information found. Using simple image + world- and prj-file...");
-			LOGGER.debug("Second try to use readGridFromImage()");
-			gc = readGridFromImage(geotiffURL, crs); //TODO style
-		}
+		gc = (GridCoverage2D) reader.read(readParams);
+		LOGGER.debug("... was successfull!");
 		return gc;
 	}
 
-//		
-//		ArcGridRaster reader = new ArcGridRaster(new BufferedReader(
-//				new InputStreamReader(url.openStream())), false);
-//		WritableRaster raster = reader.readRaster();
-//		if (crs == null)
-//			crs = determineProjection(IOUtil.changeUrlExt(url, "prj"));
-//
-//		LOGGER.debug("Position  " + reader.getXlCorner() + " / "
-//				+ reader.getYlCorner());
-//		LOGGER.debug("Size      " + reader.getNCols() + " / "
-//				+ reader.getNRows());
-//		LOGGER.debug("Min/Max   " + reader.getMinValue() + " / "
-//				+ reader.getMaxValue());
-//		LOGGER.debug("NoData    " + reader.getNoData());
-//		LOGGER.debug("CellSize  " + reader.getCellSize());
-//
-//		Double x = reader.getXlCorner(); // Suedwestliche Ecke!
-//		Double y = reader.getYlCorner(); // Suedwestliche Ecke!
-//		if (y.isNaN() || x.isNaN()) {
-//			throw new IllegalArgumentException(
-//					"The parameters xlCorner and/or ylCorner could not be read. Hint: Check if the file defines 'xlcenter' instead of 'xlcorner'. If so, just replace all 'center' with 'corner' and try again.");
-//		}
-//
-//		Double w = (reader.getNCols() * reader.getCellSize()); // reale Breite =
-//		// RasterSpalten
-//		// * Aufloesung
-//		Double h = (reader.getNRows() * reader.getCellSize()); // reale Hoehe =
-//		// RasterZeilen
-//		// * Aufloesung
-//		Envelope2D envelope = new Envelope2D(crs, new Rectangle2D.Double(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!!!
-//		return new GridCoverageFactory().create("", raster, envelope);
-//		//
-//		// === OHNE ArcGridRaster ===
-//		// // ArcGridReader reader = new ArcGridReader( new BufferedReader( new
-//		// InputStreamReader( new FileInputStream(file) ) ));
-//		// ArcGridReader reader = new ArcGridReader( file );
-//		// return (GridCoverage2D)reader.read(null);
-	
+	//		
+	// ArcGridRaster reader = new ArcGridRaster(new BufferedReader(
+	// new InputStreamReader(url.openStream())), false);
+	// WritableRaster raster = reader.readRaster();
+	// if (crs == null)
+	// crs = determineProjection(IOUtil.changeUrlExt(url, "prj"));
+	//
+	// LOGGER.debug("Position  " + reader.getXlCorner() + " / "
+	// + reader.getYlCorner());
+	// LOGGER.debug("Size      " + reader.getNCols() + " / "
+	// + reader.getNRows());
+	// LOGGER.debug("Min/Max   " + reader.getMinValue() + " / "
+	// + reader.getMaxValue());
+	// LOGGER.debug("NoData    " + reader.getNoData());
+	// LOGGER.debug("CellSize  " + reader.getCellSize());
+	//
+	// Double x = reader.getXlCorner(); // Suedwestliche Ecke!
+	// Double y = reader.getYlCorner(); // Suedwestliche Ecke!
+	// if (y.isNaN() || x.isNaN()) {
+	// throw new IllegalArgumentException(
+	// "The parameters xlCorner and/or ylCorner could not be read. Hint: Check if the file defines 'xlcenter' instead of 'xlcorner'. If so, just replace all 'center' with 'corner' and try again.");
+	// }
+	//
+	// Double w = (reader.getNCols() * reader.getCellSize()); // reale Breite =
+	// // RasterSpalten
+	// // * Aufloesung
+	// Double h = (reader.getNRows() * reader.getCellSize()); // reale Hoehe =
+	// // RasterZeilen
+	// // * Aufloesung
+	// Envelope2D envelope = new Envelope2D(crs, new Rectangle2D.Double(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!!!
+	// return new GridCoverageFactory().create("", raster, envelope);
+	// //
+	// // === OHNE ArcGridRaster ===
+	// // // ArcGridReader reader = new ArcGridReader( new BufferedReader( new
+	// // InputStreamReader( new FileInputStream(file) ) ));
+	// // ArcGridReader reader = new ArcGridReader( file );
+	// // return (GridCoverage2D)reader.read(null);
 
-
 }



More information about the Schmitzm-commits mailing list