[Schmitzm-commits] r1675 - trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Aug 15 23:11:25 CEST 2011


Author: alfonx
Date: 2011-08-15 23:11:25 +0200 (Mon, 15 Aug 2011)
New Revision: 1675

Modified:
   trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledGridCoverageReader.java
Log:
Hack um die Anzahl der B?\195?\164nder in eniem AbstractGridCoverage2DReader herauszufinden...

Modified: trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledGridCoverageReader.java
===================================================================
--- trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledGridCoverageReader.java	2011-08-15 21:09:06 UTC (rev 1674)
+++ trunk/schmitzm-gt/src/main/java/de/schmitzm/geotools/styling/StyledGridCoverageReader.java	2011-08-15 21:11:25 UTC (rev 1675)
@@ -29,16 +29,22 @@
  ******************************************************************************/
 package de.schmitzm.geotools.styling;
 
+import java.awt.Rectangle;
 import java.io.File;
 import java.net.URL;
 
 import javax.swing.ImageIcon;
 
+import org.geotools.coverage.grid.GeneralGridEnvelope;
 import org.geotools.coverage.grid.GridCoverage2D;
+import org.geotools.coverage.grid.GridGeometry2D;
 import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader;
+import org.geotools.coverage.grid.io.AbstractGridFormat;
 import org.geotools.data.FeatureSource;
 import org.geotools.geometry.jts.ReferencedEnvelope;
+import org.geotools.parameter.Parameter;
 import org.geotools.styling.Style;
+import org.opengis.parameter.GeneralParameterValue;
 
 import de.schmitzm.geotools.JTSUtil;
 import de.schmitzm.geotools.data.rld.RasterLegendData;
@@ -46,24 +52,20 @@
 import de.schmitzm.i18n.Translation;
 
 /**
- * This class provides a simple implementation of {@link StyledLayerInterface}
- * for {@link AbstractGridCoverage2DReader}. The uncache functionality is not
- * supported, because if the coverage is read once this class bases on an
- * existing {@link GridCoverage2D} object in memory.
+ * This class provides a simple implementation of {@link StyledLayerInterface} for {@link AbstractGridCoverage2DReader}.
+ * The uncache functionality is not supported, because if the coverage is read once this class bases on an existing
+ * {@link GridCoverage2D} object in memory.
  * 
- * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
- *         (University of Bonn/Germany)
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
  * @version 1.0
  */
-public class StyledGridCoverageReader extends
-		AbstractStyledLayer<AbstractGridCoverage2DReader> implements
+public class StyledGridCoverageReader extends AbstractStyledLayer<AbstractGridCoverage2DReader> implements
 		StyledGridCoverageReaderInterface {
 	private Double nodataValue;
 	private File sldFile;
 
 	/**
-	 * @return The {@link File} where the SLD was loaded from or
-	 *         <code>null</code> if there didn't exist a {@link File}.
+	 * @return The {@link File} where the SLD was loaded from or <code>null</code> if there didn't exist a {@link File}.
 	 * 
 	 * @author <a href="mailto:tzeggai at wikisquare.de">Stefan Alfons Tzeggai</a>
 	 */
@@ -73,8 +75,8 @@
 	}
 
 	/**
-	 * Associates this .sld with the {@link FeatureSource}, but does not
-	 * automatically load the file. It must not even exist.
+	 * Associates this .sld with the {@link FeatureSource}, but does not automatically load the file. It must not even
+	 * exist.
 	 * 
 	 * @param sldFile
 	 */
@@ -95,6 +97,7 @@
 
 	/** Holds the meta data for displaying a legend. */
 	protected RasterLegendData legendData = null;
+	private int bandCount;
 
 	/**
 	 * Creates a styled grid with language-specific informations.
@@ -118,12 +121,10 @@
 	 * @exception IllegalArgumentException
 	 *                if {@code null} is given as ID or geo object
 	 */
-	public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr,
-			String id, Translation title, Translation desc,
-			Translation keywords, Style style, RasterLegendData legendData,
-			ImageIcon icon) {
-		super(gcr, JTSUtil.createEnvelope(gcr.getOriginalEnvelope()), gcr
-				.getCrs(), id, title, desc, keywords, style, icon);
+	public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, Translation title, Translation desc,
+			Translation keywords, Style style, RasterLegendData legendData, ImageIcon icon) {
+		super(gcr, JTSUtil.createEnvelope(gcr.getOriginalEnvelope()), gcr.getCrs(), id, title, desc, keywords, style,
+				icon);
 		setLegendMetaData(legendData);
 	}
 
@@ -147,19 +148,15 @@
 	 * @exception IllegalArgumentException
 	 *                if {@code null} is given as ID or geo object
 	 */
-	public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr,
-			String id, Translation title, Translation desc,
-			Translation keywords, StyledLayerStyle<RasterLegendData> style,
-			ImageIcon icon) {
-		super(gcr, JTSUtil.createEnvelope(gcr.getOriginalEnvelope()), gcr
-				.getCrs(), id, title, desc, keywords, style != null ? style
-				.getGeoObjectStyle() : null, icon);
+	public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, Translation title, Translation desc,
+			Translation keywords, StyledLayerStyle<RasterLegendData> style, ImageIcon icon) {
+		super(gcr, JTSUtil.createEnvelope(gcr.getOriginalEnvelope()), gcr.getCrs(), id, title, desc, keywords,
+				style != null ? style.getGeoObjectStyle() : null, icon);
 		setLegendMetaData(style != null ? style.getMetaData() : null);
 	}
 
 	/**
-	 * Creates a styled grid with a language-specific title, no long
-	 * description, no keywords and no icon.
+	 * Creates a styled grid with a language-specific title, no long description, no keywords and no icon.
 	 * 
 	 * @param gcr
 	 *            the grid reader
@@ -174,8 +171,7 @@
 	 * @exception IllegalArgumentException
 	 *                if {@code null} is given as ID or geo object
 	 */
-	public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr,
-			String id, Translation title, Style style,
+	public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, Translation title, Style style,
 			RasterLegendData legendData) {
 		this(gcr, id, title, null, null, style, legendData, null);
 	}
@@ -202,9 +198,8 @@
 	 * @exception IllegalArgumentException
 	 *                if {@code null} is given as ID or geo object
 	 */
-	public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr,
-			String id, String title, String desc, String keywords, Style style,
-			RasterLegendData legendData, ImageIcon icon) {
+	public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, String title, String desc,
+			String keywords, Style style, RasterLegendData legendData, ImageIcon icon) {
 		this(gcr, id, (Translation) null, null, null, style, legendData, icon);
 		setTitle(title);
 		setDesc(desc);
@@ -231,17 +226,14 @@
 	 * @exception IllegalArgumentException
 	 *                if {@code null} is given as ID or geo object
 	 */
-	public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr,
-			String id, String title, String desc, String keywords,
-			StyledLayerStyle<RasterLegendData> style, ImageIcon icon) {
-		this(gcr, id, title, desc, keywords, style != null ? style
-				.getGeoObjectStyle() : null, style != null ? style
+	public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, String title, String desc,
+			String keywords, StyledLayerStyle<RasterLegendData> style, ImageIcon icon) {
+		this(gcr, id, title, desc, keywords, style != null ? style.getGeoObjectStyle() : null, style != null ? style
 				.getMetaData() : null, icon);
 	}
 
 	/**
-	 * Creates a styled grid with a non-translated title, no long description,
-	 * no keywords and no icon.
+	 * Creates a styled grid with a non-translated title, no long description, no keywords and no icon.
 	 * 
 	 * @param gcr
 	 *            the grid reader
@@ -254,14 +246,13 @@
 	 * @exception IllegalArgumentException
 	 *                if {@code null} is given as ID or geo object
 	 */
-	public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr,
-			String id, String title, Style style, RasterLegendData legendData) {
+	public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, String title, Style style,
+			RasterLegendData legendData) {
 		this(gcr, id, title, null, null, style, legendData, null);
 	}
 
 	/**
-	 * Creates a styled grid with a non-translated title, no long description,
-	 * no keywords and no icon.
+	 * Creates a styled grid with a non-translated title, no long description, no keywords and no icon.
 	 * 
 	 * @param gcr
 	 *            the grid reader
@@ -274,10 +265,9 @@
 	 * @exception IllegalArgumentException
 	 *                if {@code null} is given as ID or geo object
 	 */
-	public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr,
-			String id, String title, StyledLayerStyle<RasterLegendData> style) {
-		this(gcr, id, title, null, null, style != null ? style
-				.getGeoObjectStyle() : null, style != null ? style
+	public StyledGridCoverageReader(AbstractGridCoverage2DReader gcr, String id, String title,
+			StyledLayerStyle<RasterLegendData> style) {
+		this(gcr, id, title, null, null, style != null ? style.getGeoObjectStyle() : null, style != null ? style
 				.getMetaData() : null, null);
 	}
 
@@ -300,15 +290,13 @@
 	 */
 	public RasterLegendData getLegendMetaData() {
 		if (legendData == null)
-			return StyledLayerUtil.generateRasterLegendData(getStyle(), false,
-					null);
+			return StyledLayerUtil.generateRasterLegendData(getStyle(), false, null);
 		return legendData;
 	}
 
 	/**
-	 * Sets the meta data needed for displaying a legend. If {@code legendData}
-	 * is {@code null} an empty {@link RasterLegendData} (without gaps) is set,
-	 * so {@link #getLegendMetaData()} never returns {@code null}.
+	 * Sets the meta data needed for displaying a legend. If {@code legendData} is {@code null} an empty
+	 * {@link RasterLegendData} (without gaps) is set, so {@link #getLegendMetaData()} never returns {@code null}.
 	 * 
 	 * @param legendData
 	 *            legend meta data
@@ -320,8 +308,7 @@
 	}
 
 	/**
-	 * Simply sets the {@link #geoObject}, {@link #crs}, {@link #envelope} and
-	 * {@link #legendData} to {@code null}.
+	 * Simply sets the {@link #geoObject}, {@link #crs}, {@link #envelope} and {@link #legendData} to {@code null}.
 	 */
 	public void dispose() {
 		this.geoObject = null;
@@ -340,8 +327,8 @@
 	}
 
 	/**
-	 * Does nothing, because the {@link AbstractStyledLayer} bases on existing
-	 * objects (in memory) which can not be uncached and reloaded.
+	 * Does nothing, because the {@link AbstractStyledLayer} bases on existing objects (in memory) which can not be
+	 * uncached and reloaded.
 	 */
 	public void uncache() {
 		LOGGER.warn("Uncache functionality is not supported. Object remains in memory.");
@@ -366,18 +353,33 @@
 	 */
 	/**
 	 * 
-	 * Killed by SK: 6. April 09: Ein Layer soll nicht generell auf
-	 * verstecken/nicht verstecken gestellt werden können. Das sind
-	 * Eigenschaften der Karte/MapContext, ebenso wie die Reihenfolge der Layer.
-	 * Im Atlas verwaltet deshalb nun die Klasse skrueger.atlas.Map welche Layer
-	 * nicht in der Legende auftauchen sollen. Meines Wissens hat keiner bisher
-	 * die Funktion genutzt.
+	 * Killed by SK: 6. April 09: Ein Layer soll nicht generell auf verstecken/nicht verstecken gestellt werden können.
+	 * Das sind Eigenschaften der Karte/MapContext, ebenso wie die Reihenfolge der Layer. Im Atlas verwaltet deshalb nun
+	 * die Klasse skrueger.atlas.Map welche Layer nicht in der Legende auftauchen sollen. Meines Wissens hat keiner
+	 * bisher die Funktion genutzt.
 	 * 
 	 * public boolean isHideInLegend() { return false; }
 	 */
 
 	@Override
 	public int getBandCount() {
-		return getGeoObject().getGridCoverageCount();
+		if (bandCount == 0) {
+			Parameter readGG = new Parameter(AbstractGridFormat.READ_GRIDGEOMETRY2D);
+
+			ReferencedEnvelope mapExtend = new org.geotools.geometry.jts.ReferencedEnvelope(getEnvelope(), getCrs());
+			//
+			// readGG.setValue(new GridGeometry2D(new GeneralGridEnvelope(
+			// getBounds()), mapExtend));
+			readGG.setValue(new GridGeometry2D(new GeneralGridEnvelope(new Rectangle(1, 1)), mapExtend));
+
+			try {
+				GridCoverage2D sourceGrid = getGeoObject().read(new GeneralParameterValue[] { readGG });
+				bandCount = sourceGrid.getNumSampleDimensions();
+			} catch (Exception e) {
+				LOGGER.error("Fehler beim (in der API nichtunterstützen) Versuch die ANzhal an Bändern im Raster des readers herauszufinden", e);
+			}
+		}
+		return bandCount;
 	}
+
 }



More information about the Schmitzm-commits mailing list