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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sat Nov 21 19:22:37 CET 2009


Author: alfonx
Date: 2009-11-21 19:22:36 +0100 (Sat, 21 Nov 2009)
New Revision: 545

Modified:
   branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/RasterPositionLabel.java
   branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/SelectableXMapPane.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/XMapPane.java
Log:
Improved RasterPositionLabel. Earlier it was just looking for the top grid layer.. now it checks for the first grid layer under the mouse position. If there are multiple grid layers with different BBOXes this makes sense.

Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/RasterPositionLabel.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/RasterPositionLabel.java	2009-11-21 17:13:31 UTC (rev 544)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/RasterPositionLabel.java	2009-11-21 18:22:36 UTC (rev 545)
@@ -50,6 +50,8 @@
 import schmitzm.geotools.grid.GridUtil;
 import schmitzm.swing.CaptionsChangeable;
 
+import com.vividsolutions.jts.geom.Coordinate;
+
 /**
  * Diese Klasse stellt ein {@link JLabel} dar, in dem (2dimensionale)
  * Raster-Koordinaten und der Rasterwert an der entsprechenden Stelle angezeigt
@@ -127,14 +129,24 @@
 			return;
 
 		final SelectableXMapPane mapPane = (SelectableXMapPane) e.getSource();
+
+		// Welt-Koordinaten der Mausposition ermitteln (in CRS der Map)
+		final Point2D actPos_MapCRS = SelectableXMapPane
+				.getMapCoordinatesFromEvent(e);
+		// Welt-Koordinaten der Mausposition ermitteln (in CRS der Map)
+		if (actPos_MapCRS == null)
+			return;
+		
 		// oberstes dargestelltes Raster suchen
-		final MapLayer layer = determineRasterLayer(mapPane);
+		final MapLayer layer = determineRasterLayer(mapPane, actPos_MapCRS);
 		if (layer == null) {
 			setText("");
 			return;
 		}
+		
 		// Objekt aus Layer herausholen
 		final Object layerObj = FeatureUtil.getLayerSourceObject(layer);
+		
 		if ((layerObj == null)
 				|| (!(layerObj instanceof GridCoverage2D) && !(layerObj instanceof org.geotools.coverage.grid.io.AbstractGridCoverage2DReader)))
 			return;
@@ -143,20 +155,19 @@
 		if (layerObj instanceof GridCoverage2D) {
 			final GridCoverage2D gc = (GridCoverage2D) layerObj;
 			double[] gcValue = new double[0];
-			final GeneralDirectPosition actPos_GridCRS = new GeneralDirectPosition(
-					2);
+			final GeneralDirectPosition actPos_GridCRS = new GeneralDirectPosition(2);
 			try {
-				// Welt-Koordinaten der Mausposition ermitteln (in CRS der Map)
-				final Point2D actPos_MapCRS = SelectableXMapPane
-						.getMapCoordinatesFromEvent(e);
+
 				if (actPos_MapCRS == null)
 					return;
+				
 				// Koordinaten in CRS des Rasters umrechnen
 				final MathTransform mapToGrid = CRS.findMathTransform(mapPane
 						.getContext().getCoordinateReferenceSystem(), gc
 						.getCoordinateReferenceSystem());
 				mapToGrid.transform(new GeneralDirectPosition(actPos_MapCRS),
 						actPos_GridCRS);
+				
 				// Wert im Raster ermitteln
 				gcValue = gc.evaluate(actPos_GridCRS.toPoint2D(),
 						(double[]) null);
@@ -179,7 +190,7 @@
 			} else {
 				// sonst: Raster-Koordinaten ausrechnen
 				final int cell[] = GridUtil.convertRealToRaster(gc,
-						actPos_GridCRS.getCoordinates());
+						actPos_GridCRS.getCoordinate());
 				cellX = cell[0];
 				cellY = cell[1];
 			}
@@ -203,11 +214,7 @@
 			final GeneralDirectPosition actPos_GridCRS = new GeneralDirectPosition(
 					2);
 			try {
-				// Welt-Koordinaten der Mausposition ermitteln (in CRS der Map)
-				final Point2D actPos_MapCRS = SelectableXMapPane
-						.getMapCoordinatesFromEvent(e);
-				if (actPos_MapCRS == null)
-					return;
+
 				AbstractGridCoverage2DReader gcr = (AbstractGridCoverage2DReader) layerObj;
 				// Koordinaten in CRS des Rasters umrechnen
 				final MathTransform mapToGrid = CRS.findMathTransform(mapPane
@@ -249,9 +256,19 @@
 	 *
 	 * @param mapPane
 	 *            MapPane der angezeigten Layer.
+	 * @param actPos_MapCRS 
+	 *  		  Position fuer die das erste schneidende raster layer gefunden werden soll.
 	 */
-	protected MapLayer determineRasterLayer(final SelectableXMapPane mapPane) {
-		return mapPane.getTopVisibleGridCoverageLayer();
+	protected MapLayer determineRasterLayer(final SelectableXMapPane mapPane, Point2D actPos_MapCRS) {
+		
+		// find the first grid layer intersecting with the click position
+		for (int idx = mapPane.getContext().getLayerCount(); idx >1; idx--){
+			MapLayer layer = mapPane.getContext().getLayer(idx-1);
+			if (!SelectableXMapPane.isGridCoverageLayer(layer)) continue;
+			if (!mapPane.gridLayerIntersectsCoord(layer, new Coordinate(actPos_MapCRS.getX(), actPos_MapCRS.getY()))) continue;
+			return layer;
+		}
+		return null;
 	}
 
 	/**

Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/SelectableXMapPane.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/SelectableXMapPane.java	2009-11-21 17:13:31 UTC (rev 544)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/SelectableXMapPane.java	2009-11-21 18:22:36 UTC (rev 545)
@@ -38,6 +38,7 @@
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Point2D;
 import java.io.IOException;
+import java.util.Collection;
 import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.Map;
@@ -70,6 +71,7 @@
 import org.opengis.coverage.CannotEvaluateException;
 import org.opengis.feature.simple.SimpleFeature;
 import org.opengis.feature.simple.SimpleFeatureType;
+import org.opengis.feature.type.PropertyDescriptor;
 import org.opengis.filter.Filter;
 import org.opengis.parameter.GeneralParameterValue;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
@@ -1205,8 +1207,10 @@
 	 *            ein Layer
 	 * @param env
 	 *            Bounding-Box in CRS des MapPane
+	 *            
+	 * TODO movve to some utility class
 	 */
-	private boolean gridLayerIntersectsEnvelope(MapLayer layer, Envelope env) {
+	public boolean gridLayerIntersectsEnvelope(MapLayer layer, Envelope env) {
 		try {
 			// BB des Layers umrechnen von Layer-CRS in Map-CRS
 			Envelope bounds_MapCRS = JTSUtil.transformEnvelope(layer
@@ -1224,8 +1228,40 @@
 			return false;
 		}
 	}
+	
 
 	/**
+	 * Testet (anhand der Bounding-Box), ob das Objekt eines Layers eine andere
+	 * Bounding-Box schneidet. Die Bounding-Box des Layer-Objekts wird zunaechst
+	 * in das CRS des MapPanes umgerechnets.
+	 * 
+	 * @param layer
+	 *            ein Layer
+	 * @param coord
+	 *            Coordinate in CRS des MapPane
+	 *            
+	 * TODO movve to some utility class
+	 */
+	public boolean gridLayerIntersectsCoord(MapLayer layer, Coordinate coord) {
+		try {
+			// BB des Layers umrechnen von Layer-CRS in Map-CRS
+			Envelope bounds_MapCRS = JTSUtil.transformEnvelope(layer
+					.getFeatureSource().getBounds(), layer.getFeatureSource()
+					.getSchema().getGeometryDescriptor()
+					.getCoordinateReferenceSystem(), getContext()
+					.getCoordinateReferenceSystem());
+
+			// TODO warum kann bounds_MapCRS == null sein ?? ?SK fragt martin???
+			if (bounds_MapCRS == null)
+				return false;
+
+			return bounds_MapCRS.intersects(coord);
+		} catch (Exception err) {
+			return false;
+		}
+	}
+
+	/**
 	 * Prueft, ob es sich bei einem Layer um ein Raster-Layer handelt. VOn SK an
 	 * eine GT Methode abgegeben.
 	 * 
@@ -1233,7 +1269,23 @@
 	 *            zu ueberpruefendes Layer
 	 */
 	public static boolean isGridCoverageLayer(MapLayer layer) {
-		return (MapLayerUtils.isGridLayer(layer));
+		String GRID_PACKAGE = "org.geotools.coverage.grid";
+		String GRID_PACKAGE2 = "org.opengis.coverage.grid";
+		
+		// TODO when my patch is accepted, replace the whole method with MapLayerUtil.isGridLayer again
+
+		
+        Collection<PropertyDescriptor> descriptors = layer.getFeatureSource().getSchema().getDescriptors();
+        for (PropertyDescriptor desc : descriptors) {
+            String className = desc.getType().getBinding().getName();
+
+            if (className.contains(GRID_PACKAGE) || className.contains(GRID_PACKAGE2)) {
+                return true;
+            }
+        }
+
+        return false;
 	}
 
 }
+

Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/XMapPane.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/XMapPane.java	2009-11-21 17:13:31 UTC (rev 544)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/XMapPane.java	2009-11-21 18:22:36 UTC (rev 545)
@@ -30,7 +30,6 @@
 
 import org.apache.log4j.Logger;
 import org.geotools.feature.FeatureCollection;
-import org.geotools.geometry.Envelope2D;
 import org.geotools.geometry.jts.JTS;
 import org.geotools.geometry.jts.ReferencedEnvelope;
 import org.geotools.map.DefaultMapContext;



More information about the Schmitzm-commits mailing list