[Schmitzm-commits] r548 - in branches/1.0-gt2-2.6/src/schmitzm/geotools: . gui
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Mon Nov 23 00:47:24 CET 2009
Author: alfonx
Date: 2009-11-23 00:47:22 +0100 (Mon, 23 Nov 2009)
New Revision: 548
Modified:
branches/1.0-gt2-2.6/src/schmitzm/geotools/JTSUtil.java
branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/RasterPositionLabel.java
branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/SelectableXMapPane.java
Log:
* Using more utility classes in the RasterPostionLabel code.
* added a transformEnvelope-method for ReferencedEnvelopes to JTSUtil
Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/JTSUtil.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/JTSUtil.java 2009-11-22 19:06:01 UTC (rev 547)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/JTSUtil.java 2009-11-22 23:47:22 UTC (rev 548)
@@ -45,28 +45,33 @@
import com.vividsolutions.jts.geom.Envelope;
/**
- * Diese Klasse enthaelt allgemeine Funktionen fuer die Arbeit mit den
- * in Geotools verwendeten JTS-Komponenten vereinfacht.
- * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
+ * Diese Klasse enthaelt allgemeine Funktionen fuer die Arbeit mit den in
+ * Geotools verwendeten JTS-Komponenten vereinfacht.
+ *
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
+ * (University of Bonn/Germany)
* @version 1.1
*/
public class JTSUtil {
- private static Logger LOGGER = Logger.getLogger( JTSUtil.class.getName() );
+ private static Logger LOGGER = Logger.getLogger(JTSUtil.class.getName());
- /**
- * Created an (CRS-less) JTS-Envelope from an OpenGIS-Envelope.
- * @param envelope an OpenGIS-Envelope
- * @return an JTS-Envelope
- */
- public static Envelope createEnvelope(org.opengis.geometry.Envelope envelope) { // gt2-2.4.2
-// public static Envelope createEnvelope(org.opengis.spatialschema.geometry.Envelope envelope) { // gt2-2.3.4
- return new Envelope(
- envelope.getMinimum(0), // X1
- envelope.getMaximum(0), // X2
- envelope.getMinimum(1), // Y1
- envelope.getMaximum(1) // Y2
- );
- }
+ /**
+ * Created an (CRS-less) JTS-Envelope from an OpenGIS-Envelope.
+ *
+ * @param envelope
+ * an OpenGIS-Envelope
+ * @return an JTS-Envelope
+ */
+ public static Envelope createEnvelope(org.opengis.geometry.Envelope envelope) { // gt2-2.4.2
+ // public static Envelope
+ // createEnvelope(org.opengis.spatialschema.geometry.Envelope envelope) { //
+ // gt2-2.3.4
+ return new Envelope(envelope.getMinimum(0), // X1
+ envelope.getMaximum(0), // X2
+ envelope.getMinimum(1), // Y1
+ envelope.getMaximum(1) // Y2
+ );
+ }
/**
* Expands an {@link Envelope} by percentage.
@@ -82,7 +87,6 @@
expandedEnv.expandBy(env.getWidth() * pct, env.getHeight() * pct);
return expandedEnv;
}
-
/**
* Expands an {@link Envelope} by percentage.
@@ -93,124 +97,162 @@
* percentage (e.g. 0.1 = 10%) to expands the envelope by.
* Negative values are allowed.
*/
- public static ReferencedEnvelope expandEnvelope(ReferencedEnvelope env, double pct) {
+ public static ReferencedEnvelope expandEnvelope(ReferencedEnvelope env,
+ double pct) {
final ReferencedEnvelope expandedEnv = new ReferencedEnvelope(env);
expandedEnv.expandBy(env.getWidth() * pct, env.getHeight() * pct);
return expandedEnv;
}
-
- /**
- * Transformiert einen JTS-Envelope von einem CRS in ein anderes. Wenn Bursa-Wolf parameter fehlen, wird lenient gerechnet.
- * @param sourceEnv JTS-Envelope
- * @param sourceCRS CRS von {@code sourceEnv}
- * @param destCRS CRS in das umgerechnet werden soll
- * @see CRS#findMathTransform(CoordinateReferenceSystem,CoordinateReferenceSystem)
- * @see JTS#transform(Envelope,MathTransform)
- */
- public static Envelope transformEnvelope(Envelope sourceEnv, CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem destCRS) {
- Envelope destEnv = null;
- MathTransform transform;
- try {
- transform = CRS.findMathTransform(sourceCRS, destCRS, getLenient());
- destEnv = JTS.transform(sourceEnv,transform);
- } catch (OperationNotFoundException e) {
- LOGGER.warn("CRS tranformation not found: "+e.getMessage());
- } catch (FactoryException e) {
- LOGGER.warn("CRS tranformation for JTS envelope not successfully",e);
- } catch (TransformException e) {
- LOGGER.warn("CRS tranformation for JTS envelope not successfully",e);
+ /**
+ * Transformiert einen JTS-Envelope von einem CRS in ein anderes. Wenn
+ * Bursa-Wolf parameter fehlen, wird abhängig von der function
+ * {@link #getLenient()} lenient gerechnet.
+ *
+ * @param sourceEnv
+ * JTS-Envelope
+ * @param sourceCRS
+ * CRS von {@code sourceEnv}
+ * @param destCRS
+ * CRS in das umgerechnet werden soll
+ * @see CRS#findMathTransform(CoordinateReferenceSystem,CoordinateReferenceSystem)
+ * @see JTS#transform(Envelope,MathTransform)
+ * @see #transformEnvelope(ReferencedEnvelope, CoordinateReferenceSystem)
+ */
+ public static Envelope transformEnvelope(Envelope sourceEnv,
+ CoordinateReferenceSystem sourceCRS,
+ CoordinateReferenceSystem destCRS) {
+ if (CRS.equalsIgnoreMetadata(sourceCRS, destCRS))
+ return new Envelope(sourceEnv);
+
+ Envelope destEnv = null;
+ MathTransform transform;
+ try {
+ transform = CRS.findMathTransform(sourceCRS, destCRS, getLenient());
+ destEnv = JTS.transform(sourceEnv, transform);
+ } catch (OperationNotFoundException e) {
+ LOGGER.warn("CRS tranformation not found: " + e.getMessage());
+ } catch (FactoryException e) {
+ LOGGER.warn("CRS tranformation for JTS envelope not successfully",
+ e);
+ } catch (TransformException e) {
+ LOGGER.warn("CRS tranformation for JTS envelope not successfully",
+ e);
+ }
+ return destEnv;
}
- return destEnv;
- }
- /**
- * @return Central setting to set the lenient param for CRS.findMathTransform(
- */
- private static boolean getLenient() {
- return true;
-}
+ /**
+ * @return Central setting to set the lenient param for
+ * CRS.findMathTransform(
+ */
+ private static boolean getLenient() {
+ return true;
+ }
-/**
- * Transformiert eine Koordinate von einem CRS in ein anderes.
- * @param sourceCoord Koordinate
- * @param sourceCRS CRS von {@code sourceCoord}
- * @param destCRS CRS in das umgerechnet werden soll
- * @see CRS#findMathTransform(CoordinateReferenceSystem,CoordinateReferenceSystem)
- * @see JTS#transform(Coordinate, Coordinate, MathTransform)
- */
- public static Coordinate transformCoordinate(Coordinate sourceCoord, CoordinateReferenceSystem sourceCRS, CoordinateReferenceSystem destCRS) {
- Coordinate destCoord = null;
- MathTransform transform;
- try {
- transform = CRS.findMathTransform(sourceCRS, destCRS, getLenient());
- destCoord = JTS.transform(sourceCoord,null,transform);
- } catch (FactoryException e) {
- LOGGER.warn("CRS tranformation for JTS coordinate not successful",e);
- } catch (TransformException e) {
- LOGGER.warn("CRS tranformation for JTS coordinate not successful",e);
- }
- return destCoord;
- }
-
- /**
- * Returns an {@link Envelope} that has the same aspect ratio as the given rectangle
- * @param rect
- * defines the aspect ratio the map area is fixed with (e.g. a
- * gui components size)
- * @param mapArea
- * the map area to apply the aspect ratio of "r" to
- * @param grow
- * If <code>true</code>, than the area will be enlarged to match
- * the aspect ratio. If <code>false</code>, it will only shrink.
- */
- public static ReferencedEnvelope fixAspectRatio(final Rectangle rect, final ReferencedEnvelope mapArea,
- boolean grow) {
- // no map area to fix the aspect ratio for
- if (mapArea == null) {
- LOGGER.warn("mapArea has been null in method fixAspectRatio, returning also NULL");
- return null;
- }
- // no component size to fix the aspect ratio with
- if ( rect == null || rect.width == 0 || rect.height == 0 ) {
- LOGGER.warn("Empty rectangle in method fixAspectRatio, returning an unmodified mapArea!");
- return mapArea;
- }
+ /**
+ * Transformiert eine Koordinate von einem CRS in ein anderes.
+ *
+ * @param sourceCoord
+ * Koordinate
+ * @param sourceCRS
+ * CRS von {@code sourceCoord}
+ * @param destCRS
+ * CRS in das umgerechnet werden soll
+ * @see CRS#findMathTransform(CoordinateReferenceSystem,CoordinateReferenceSystem)
+ * @see JTS#transform(Coordinate, Coordinate, MathTransform)
+ */
+ public static Coordinate transformCoordinate(Coordinate sourceCoord,
+ CoordinateReferenceSystem sourceCRS,
+ CoordinateReferenceSystem destCRS) {
- final double mapWidth = mapArea.getWidth(); /* get the extent of the map */
- final double mapHeight = mapArea.getHeight();
- final double scaleX = rect.getWidth() / mapArea.getWidth(); /*
- * calculate the
- * new scale
- */
+ if (CRS.equalsIgnoreMetadata(sourceCRS, destCRS))
+ return new Coordinate(sourceCoord.x, sourceCoord.y);
- final double scaleY = rect.getHeight() / mapArea.getHeight();
- double scale = 1.0; // stupid compiler!
+ Coordinate destCoord = null;
+ MathTransform transform;
+ try {
+ transform = CRS.findMathTransform(sourceCRS, destCRS, getLenient());
+ destCoord = JTS.transform(sourceCoord, null, transform);
+ } catch (FactoryException e) {
+ LOGGER.warn("CRS tranformation for JTS coordinate not successful",
+ e);
+ } catch (TransformException e) {
+ LOGGER.warn("CRS tranformation for JTS coordinate not successful",
+ e);
+ }
+ return destCoord;
+ }
- if ((grow && scaleX < scaleY) || (!grow && scaleX > scaleY)) {
- scale = scaleX;
- } else {
- scale = scaleY;
- }
+ /**
+ * Returns an {@link Envelope} that has the same aspect ratio as the given
+ * rectangle
+ *
+ * @param rect
+ * defines the aspect ratio the map area is fixed with (e.g. a
+ * gui components size)
+ * @param mapArea
+ * the map area to apply the aspect ratio of "r" to
+ * @param grow
+ * If <code>true</code>, than the area will be enlarged to match
+ * the aspect ratio. If <code>false</code>, it will only shrink.
+ */
+ public static ReferencedEnvelope fixAspectRatio(final Rectangle rect,
+ final ReferencedEnvelope mapArea, boolean grow) {
+ // no map area to fix the aspect ratio for
+ if (mapArea == null) {
+ LOGGER
+ .warn("mapArea has been null in method fixAspectRatio, returning also NULL");
+ return null;
+ }
+ // no component size to fix the aspect ratio with
+ if (rect == null || rect.width == 0 || rect.height == 0) {
+ LOGGER
+ .warn("Empty rectangle in method fixAspectRatio, returning an unmodified mapArea!");
+ return mapArea;
+ }
- /* calculate the difference in width and height of the new extent */
- final double deltaX = /* Math.abs */((rect.getWidth() / scale) - mapWidth);
- final double deltaY = /* Math.abs */((rect.getHeight() / scale) - mapHeight);
+ final double mapWidth = mapArea.getWidth(); /* get the extent of the map */
+ final double mapHeight = mapArea.getHeight();
+ final double scaleX = rect.getWidth() / mapArea.getWidth(); /*
+ * calculate
+ * the new
+ * scale
+ */
- /*
- * System.out.println("delta x " + deltaX);
- * System.out.println("delta y " + deltaY);
- */
+ final double scaleY = rect.getHeight() / mapArea.getHeight();
+ double scale = 1.0; // stupid compiler!
- /* create the new extent */
- final Coordinate ll = new Coordinate(
- mapArea.getMinX() - (deltaX / 2.0), mapArea.getMinY()
- - (deltaY / 2.0));
- final Coordinate ur = new Coordinate(
- mapArea.getMaxX() + (deltaX / 2.0), mapArea.getMaxY()
- + (deltaY / 2.0));
+ if ((grow && scaleX < scaleY) || (!grow && scaleX > scaleY)) {
+ scale = scaleX;
+ } else {
+ scale = scaleY;
+ }
- return new ReferencedEnvelope(new Envelope(ll, ur),mapArea.getCoordinateReferenceSystem());
- }
+ /* calculate the difference in width and height of the new extent */
+ final double deltaX = /* Math.abs */((rect.getWidth() / scale) - mapWidth);
+ final double deltaY = /* Math.abs */((rect.getHeight() / scale) - mapHeight);
+ /* create the new extent */
+ final Coordinate ll = new Coordinate(
+ mapArea.getMinX() - (deltaX / 2.0), mapArea.getMinY()
+ - (deltaY / 2.0));
+ final Coordinate ur = new Coordinate(
+ mapArea.getMaxX() + (deltaX / 2.0), mapArea.getMaxY()
+ + (deltaY / 2.0));
+
+ return new ReferencedEnvelope(new Envelope(ll, ur), mapArea
+ .getCoordinateReferenceSystem());
+ }
+
+ /**
+ * Transforms a {@link ReferencedEnvelope} into another CRS and return a
+ * {@link ReferencedEnvelope}
+ */
+ public static ReferencedEnvelope transformEnvelope(
+ ReferencedEnvelope bounds, CoordinateReferenceSystem destCRS) {
+ return new ReferencedEnvelope(transformEnvelope(bounds, bounds
+ .getCoordinateReferenceSystem(), destCRS), destCRS);
+ }
+
}
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-22 19:06:01 UTC (rev 547)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/RasterPositionLabel.java 2009-11-22 23:47:22 UTC (rev 548)
@@ -43,9 +43,11 @@
import org.geotools.geometry.GeneralDirectPosition;
import org.geotools.map.MapLayer;
import org.geotools.referencing.CRS;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.MathTransform;
import schmitzm.data.WritableGrid;
+import schmitzm.geotools.JTSUtil;
import schmitzm.geotools.feature.FeatureUtil;
import schmitzm.geotools.grid.GridUtil;
import schmitzm.swing.CaptionsChangeable;
@@ -57,14 +59,14 @@
* Raster-Koordinaten und der Rasterwert an der entsprechenden Stelle angezeigt
* werden.<br>
* Die Klasse fungiert als {@link MouseMotionListener} und kann so direkt an ein
- * {@link SelectableXMapPane} gekoppelt werden. Die Koordinaten-Darstellung im Label
- * aktualisiert sich somit automatisch, sobald sich die Maus ueber die Karte
- * bewegt.
- *
+ * {@link SelectableXMapPane} gekoppelt werden. Die Koordinaten-Darstellung im
+ * Label aktualisiert sich somit automatisch, sobald sich die Maus ueber die
+ * Karte bewegt.
+ *
* @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
* (University of Bonn/Germany)
* @version 1.1
- *
+ *
* SK 01.09.07: finals fuer Variablen eingefuegt... die Funktion
* displayCoordinates() wird oft benutzt und es gab viele Variablen,
* die nie geaendert wurden.
@@ -82,7 +84,7 @@
/**
* Key, um das Label-Praefix in der {@link CaptionsChangeable}-Map
* anzusprechen.
- *
+ *
* @see #resetCaptions(Map)
*/
public static final String LABEL_PREFIX = RasterPositionLabel.class
@@ -90,7 +92,7 @@
+ ".LABEL_PREFIX";
/**
* Praefix, das der Raster-Position vorangestellt wird.
- *
+ *
* @see #setLabelPrefix(String)
*/
public static String labelPrefix = GeotoolsGUIUtil.RESOURCE
@@ -106,7 +108,7 @@
/**
* Erzeugt ein neues Label.
- *
+ *
* @param fracDigits
* Anzahl an Nachkommastellen, auf der Rasterwert gerundet wird
*/
@@ -120,7 +122,8 @@
/**
* Stellt die Koordinaten und den Wert des obersten (sichtbaren) Rasters im
- * Label dar, wenn das Event von einem {@link SelectableXMapPane} ausgeloest wurde.<br>
+ * Label dar, wenn das Event von einem {@link SelectableXMapPane} ausgeloest
+ * wurde.<br>
* Wird {@link #mouseMoved(MouseEvent)} und
* {@link #mouseDragged(MouseEvent)} aufgerufen.
*/
@@ -136,43 +139,54 @@
// Welt-Koordinaten der Mausposition ermitteln (in CRS der Map)
if (actPos_MapCRS == null)
return;
-
+
// oberstes dargestelltes Raster suchen
final MapLayer layer = determineRasterLayer(mapPane, actPos_MapCRS);
if (layer == null) {
setText("");
return;
}
-
+
+ CoordinateReferenceSystem mapCrs = mapPane.getContext()
+ .getCoordinateReferenceSystem();
+ CoordinateReferenceSystem layerCrs = layer.getFeatureSource()
+ .getSchema().getGeometryDescriptor()
+ .getCoordinateReferenceSystem();
+
// 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;
+ // We checked that it's a GridLayer.. so have no fear...
+ // if ((layerObj == null)
+ // || (!(layerObj instanceof GridCoverage2D) && !(layerObj instanceof
+ // org.geotools.coverage.grid.io.AbstractGridCoverage2DReader)))
+ // return;
+
final StringBuffer valueStr = new StringBuffer();
if (layerObj instanceof GridCoverage2D) {
final GridCoverage2D gc = (GridCoverage2D) layerObj;
double[] gcValue = new double[0];
- final GeneralDirectPosition actPos_GridCRS = new GeneralDirectPosition(2);
+ GeneralDirectPosition actPos_GridCRS;
try {
- 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);
-
+ Coordinate posInLayerCRS = JTSUtil.transformCoordinate(
+ new Coordinate(actPos_MapCRS.getX(), actPos_MapCRS
+ .getY()), mapCrs, layerCrs);
+ //
+ // // Koordinaten in CRS des Rasters umrechnen
+ // final MathTransform mapToGrid = CRS.findMathTransform(mapCrs,
+ // layerCrs);
+ // mapToGrid.transform(new GeneralDirectPosition(actPos_MapCRS),
+ // actPos_GridCRS);
+
+ actPos_GridCRS = new GeneralDirectPosition(posInLayerCRS.x,
+ posInLayerCRS.y);
+ //
// Wert im Raster ermitteln
- gcValue = gc.evaluate(actPos_GridCRS.toPoint2D(),
- (double[]) null);
+ gcValue = gc.evaluate(actPos_GridCRS, (double[]) null);
} catch (final Exception err) {
// Position out of Raster data
+ return;
}
valueStr.append(labelPrefix == null ? "" : labelPrefix);
@@ -201,10 +215,10 @@
for (int j = 0; j < gcValue.length; j++) {
if (j > 0)
valueStr.append(" / ");
- valueStr.append(Double.isNaN(gcValue[j]) ? gcValue[j] : decForm
- .format(gcValue[j]));
- //Debug: ungerundeten Raster-Wert anzeigen
- //valueStr.append(" Orig = " + gcValue[j]);
+ valueStr.append(Double.isNaN(gcValue[j]) ? gcValue[j] : decForm
+ .format(gcValue[j]));
+ // Debug: ungerundeten Raster-Wert anzeigen
+ // valueStr.append(" Orig = " + gcValue[j]);
}
}
@@ -253,19 +267,26 @@
* Standardmaessig wird das oberste sichtbare Raster-Layer zurueckgegeben.
* Sub-Klassen koennen diese Methode ueberschreiben, um ein anderes Layer zu
* verwenden.
- *
+ *
* @param mapPane
* MapPane der angezeigten Layer.
- * @param actPos_MapCRS
- * Position fuer die das erste schneidende raster layer gefunden werden soll.
+ * @param actPos_MapCRS
+ * Position fuer die das erste schneidende raster layer gefunden
+ * werden soll.
*/
- protected MapLayer determineRasterLayer(final SelectableXMapPane mapPane, Point2D actPos_MapCRS) {
-
+ 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;
+ for (int idx = mapPane.getContext().getLayerCount(); idx >= 1; idx--) {
+ MapLayer layer = mapPane.getContext().getLayer(idx - 1);
+ if (!layer.isVisible())
+ continue;
+ if (!SelectableXMapPane.isGridCoverageLayer(layer))
+ continue;
+ if (!mapPane.layerIntersectsCoord(layer, new Coordinate(
+ actPos_MapCRS.getX(), actPos_MapCRS.getY())))
+ continue;
return layer;
}
return null;
@@ -274,7 +295,7 @@
/**
* Setzt den String, welcher der Rasterposition und dem Rasterwert
* vorangestellt wird.
- *
+ *
* @param label
* neues Praefix
*/
@@ -293,7 +314,7 @@
/**
* Setzt das Label-Praefix neu, sofern in der Map ein Wert fuer
* {@link #LABEL_PREFIX} hinterlegt ist.
- *
+ *
* @param captionMap
* neue Labels
*/
@@ -307,7 +328,7 @@
/**
* Setzt die Anzahl an Nachkommastellen, die fuer den Rasterwert dargestellt
* werden
- *
+ *
* @param fracDigits
* Anzahl an Nachkommastellen
*/
@@ -327,9 +348,9 @@
/**
* Wird aufgerufen, sobald die Maus bewegt wird. Stellt die Koordinaten und
- * den Rasterwert im Label dar, wenn das Event von einem {@link SelectableXMapPane}
- * ausgeloest wurde.
- *
+ * den Rasterwert im Label dar, wenn das Event von einem
+ * {@link SelectableXMapPane} ausgeloest wurde.
+ *
* @see #displayCoordinates(MouseEvent)
*/
public void mouseMoved(final MouseEvent e) {
@@ -340,7 +361,7 @@
* Wird aufgerufen, sobald die Maus bei gedrueckter Taste bewegt wird.
* Stellt die Koordinaten und den Rasterwert im Label dar, wenn das Event
* von einem {@link SelectableXMapPane} ausgeloest wurde.
- *
+ *
* @see #displayCoordinates(MouseEvent)
*/
public void mouseDragged(final MouseEvent e) {
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-22 19:06:01 UTC (rev 547)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/gui/SelectableXMapPane.java 2009-11-22 23:47:22 UTC (rev 548)
@@ -745,7 +745,7 @@
// Ansonsten Raster-Layer einfach uebergehen.
if (isGridCoverageLayer(layer)) {
if ((mode == SELECT_TOP || mode == SELECT_ONE_FROM_TOP)
- && gridLayerIntersectsEnvelope(layer, env))
+ && layerIntersectsEnvelope(layer, env))
break;
continue;
}
@@ -1137,7 +1137,7 @@
// Ansonsten Raster-Layer einfach uebergehen.
if (isGridCoverageLayer(layer)) {
if ((mode == SELECT_TOP || mode == SELECT_ONE_FROM_TOP)
- && gridLayerIntersectsEnvelope(layer, env))
+ && layerIntersectsEnvelope(layer, env))
break;
continue;
}
@@ -1201,16 +1201,17 @@
/**
* 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.
+ * in das CRS des MapPanes umgerechnets.<br>
+ * If the layer's bbox is <code>null</code>, returns <code>false</code>. *
*
* @param layer
* ein Layer
* @param env
* Bounding-Box in CRS des MapPane
- *
- * TODO movve to some utility class
+ *
+ * TODO movve to some utility class
*/
- public boolean gridLayerIntersectsEnvelope(MapLayer layer, Envelope env) {
+ public boolean layerIntersectsEnvelope(MapLayer layer, Envelope env) {
try {
// BB des Layers umrechnen von Layer-CRS in Map-CRS
Envelope bounds_MapCRS = JTSUtil.transformEnvelope(layer
@@ -1228,34 +1229,39 @@
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.
+ * Testet (anhand der Bounding-Box), ob das Objekt eines Layers eine
+ * Coordinate schneidet. Die Bounding-Box des Layer-Objekts wird zunaechst
+ * in das CRS des MapPanes umgerechnets.<br/>
+ * If the layer's bbox is <code>null</code>, returns <code>false</code>.
*
* @param layer
* ein Layer
* @param coord
* Coordinate in CRS des MapPane
- *
- * TODO movve to some utility class
+ *
+ * TODO movve to some utility class
*/
- public boolean gridLayerIntersectsCoord(MapLayer layer, Coordinate coord) {
+ public boolean layerIntersectsCoord(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()
+ ReferencedEnvelope bounds = layer.getFeatureSource().getBounds();
+
+ // Transform the layer bounds to map CRS if neeed
+ CoordinateReferenceSystem layerCRS = layer.getFeatureSource()
.getSchema().getGeometryDescriptor()
- .getCoordinateReferenceSystem(), getContext()
- .getCoordinateReferenceSystem());
+ .getCoordinateReferenceSystem();
+ CoordinateReferenceSystem mapCRS = getContext()
+ .getCoordinateReferenceSystem();
+ if (!CRS.equalsIgnoreMetadata(layerCRS, mapCRS)) {
- // TODO warum kann bounds_MapCRS == null sein ?? ?SK fragt martin???
- if (bounds_MapCRS == null)
+ bounds = JTSUtil.transformEnvelope(bounds, mapCRS);
+ }
+
+ if (bounds == null)
return false;
- return bounds_MapCRS.intersects(coord);
+ return bounds.intersects(coord);
} catch (Exception err) {
return false;
}
@@ -1271,21 +1277,22 @@
public static boolean isGridCoverageLayer(MapLayer 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();
+ // TODO when my patch is accepted, replace the whole method with
+ // MapLayerUtil.isGridLayer again
- if (className.contains(GRID_PACKAGE) || className.contains(GRID_PACKAGE2)) {
- return true;
- }
- }
+ Collection<PropertyDescriptor> descriptors = layer.getFeatureSource()
+ .getSchema().getDescriptors();
+ for (PropertyDescriptor desc : descriptors) {
+ String className = desc.getType().getBinding().getName();
- return false;
+ if (className.contains(GRID_PACKAGE)
+ || className.contains(GRID_PACKAGE2)) {
+ return true;
+ }
+ }
+
+ return false;
}
}
-
More information about the Schmitzm-commits
mailing list