[Schmitzm-commits] r914 - in branches/2.2.x: src/schmitzm/geotools src/schmitzm/geotools/gui src_junit/schmitzm/geotools/gui
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Sat Jun 26 13:06:33 CEST 2010
Author: alfonx
Date: 2010-06-26 13:06:32 +0200 (Sat, 26 Jun 2010)
New Revision: 914
Added:
branches/2.2.x/src_junit/schmitzm/geotools/gui/XMapPaneTest.java
Modified:
branches/2.2.x/src/schmitzm/geotools/JTSUtil.java
branches/2.2.x/src/schmitzm/geotools/gui/XMapPane.java
Log:
BugFix: XMapPane crashed for one-point-only layers, because their BBOX has width 0 and hence no screenToWorld transformation could be calculated.
Modified: branches/2.2.x/src/schmitzm/geotools/JTSUtil.java
===================================================================
--- branches/2.2.x/src/schmitzm/geotools/JTSUtil.java 2010-06-26 10:55:49 UTC (rev 913)
+++ branches/2.2.x/src/schmitzm/geotools/JTSUtil.java 2010-06-26 11:06:32 UTC (rev 914)
@@ -323,23 +323,91 @@
return re;
}
-
+
/**
* TODO doku
+ *
* @param wkt
* @param crs
* @return
* @throws ParseException
*/
- public static Geometry parseWKT(String wkt, CoordinateReferenceSystem crs) throws ParseException {
- Hints hints = new Hints( Hints.CRS, crs != null ? crs : DefaultGeographicCRS.WGS84 );
- GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory( hints );
+ public static Geometry parseWKT(String wkt, CoordinateReferenceSystem crs)
+ throws ParseException {
+ Hints hints = new Hints(Hints.CRS, crs != null ? crs
+ : DefaultGeographicCRS.WGS84);
+ GeometryFactory geometryFactory = JTSFactoryFinder
+ .getGeometryFactory(hints);
- WKTReader reader = new WKTReader( geometryFactory );
+ WKTReader reader = new WKTReader(geometryFactory);
Geometry geometry = (Geometry) reader.read(wkt);
-
+
return geometry;
+
+ }
+
+ /**
+ * Checks that the passed {@link ReferencedEnvelope} doesn't have a width or
+ * height of 0! If any of them is zero, it's increased by +/-1 in each
+ * direction.
+ *
+ * TODO check that the new Envelope is still in the valid are of the CRS
+ * env.getCoordinateReferenceSystem().getDomainOfValidity()
+ *
+ * @return A {@link ReferencedEnvelope} that has an area greater 0!
+ */
+ public static ReferencedEnvelope checkNotZeroArea(
+ final ReferencedEnvelope env) {
+ ReferencedEnvelope env2 = env;
+ // Check, that the BBOX doesn't have a height of 0. If so, the height is
+ // increased by 2!
+ if (env2.getHeight() == 0.) {
+ env2 = new ReferencedEnvelope(env2.getMinX(), env2.getMaxX(), env2
+ .getMinY() - 1., env2.getMaxY() + 1., env2
+ .getCoordinateReferenceSystem());
+ }
+ // Check, that the BBOX doesn't have a width of 0. If so, the width is
+ // increased by 2!
+ if (env2.getWidth() == 0.) {
+ env2 = new ReferencedEnvelope(env2.getMinX() - 1.,
+ env2.getMaxX() + 1., env2.getMinY(), env2.getMaxY(), env2
+ .getCoordinateReferenceSystem());
+ }
+
+ // env.getCoordinateReferenceSystem().getDomainOfValidity()
+
+ return env2;
}
+ /**
+ * Checks that the passed {@link Envelope} doesn't have a width or
+ * height of 0! If any of them is zero, it's increased by +/-1 in each
+ * direction.
+ *
+ * TODO check that the new Envelope is still in the valid are of the CRS
+ * env.getCoordinateReferenceSystem().getDomainOfValidity()
+ *
+ * @return A {@link ReferencedEnvelope} that has an area greater 0!
+ */
+ public static Envelope checkNotZeroArea(final Envelope env_) {
+ Envelope env = env_;
+ // Check, that the BBOX doesn't have a height of 0. If so, the height is
+ // increased by 2!
+ if (env.getHeight() == 0.) {
+ env = new Envelope(env.getMinX(), env.getMaxX(),
+ env.getMinY() - 1., env.getMaxY() + 1.);
+ }
+ // Check, that the BBOX doesn't have a width of 0. If so, the width is
+ // increased by 2!
+ if (env.getWidth() == 0.) {
+ env = new Envelope(env.getMinX() - 1., env.getMaxX() + 1., env
+ .getMinY(), env.getMaxY());
+ }
+
+ // env.getCoordinateReferenceSystem().getDomainOfValidity()
+
+ return env;
+ }
+
}
Modified: branches/2.2.x/src/schmitzm/geotools/gui/XMapPane.java
===================================================================
--- branches/2.2.x/src/schmitzm/geotools/gui/XMapPane.java 2010-06-26 10:55:49 UTC (rev 913)
+++ branches/2.2.x/src/schmitzm/geotools/gui/XMapPane.java 2010-06-26 11:06:32 UTC (rev 914)
@@ -774,17 +774,21 @@
* corrected. This change implies, that setMapArea() will most of the time
* not allow setting to a wrong aspectRatio.
*
- * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
- * Tzeggai</a>
+ * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Tzeggai</a>
*/
public ReferencedEnvelope bestAllowedMapArea(ReferencedEnvelope env) {
- if (getWidth() == 0)
- return env;
-
if (env == null)
return null;
+ env = JTSUtil.checkNotZeroArea(env);
+
+ if (getWidth() == 0) {
+ // If the Swing component is not rendered yet, we can't apply aspect
+ // ratio calculations and return unchanged envelope
+ return env;
+ }
+
Envelope newArea = null;
/**
@@ -969,8 +973,7 @@
*
* Removes all {@link JMapPaneListener}s that are registered
*
- * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
- * Tzeggai</a>
+ * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Tzeggai</a>
*/
public void dispose() {
if (isDisposed())
@@ -1275,7 +1278,7 @@
addDefaultMargin(layerBounds), true);
}
- return maxExtend;
+ return JTSUtil.checkNotZeroArea(maxExtend);
}
public static final String SPECIAL_LINES_LAYER_ID = "SPECIAL_LINES_LAYER_ID";
@@ -1300,7 +1303,6 @@
if (!layer.isVisible())
continue;
-
if (layer.getTitle().equals(SPECIAL_LINES_LAYER_ID))
continue;
/*
@@ -1340,7 +1342,7 @@
}
}
- return result;
+ return JTSUtil.checkNotZeroArea(result);
}
@@ -1348,8 +1350,7 @@
* Retuns the maximum allowed zoom scale. This is the smaller number value
* of the two. Defaults to {@link Double}.MIN_VALUE
*
- * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
- * Tzeggai</a>
+ * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Tzeggai</a>
*/
public Double getMaxZoomScale() {
return maxZoomScale;
@@ -1359,8 +1360,7 @@
* Retuns the minimum allowed zoom scale. This is the bigger number value of
* the two. Defaults to {@link Double}.MAX_VALUE
*
- * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
- * Tzeggai</a>
+ * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Tzeggai</a>
*/
public Double getMinZoomScale() {
return minZoomScale;
@@ -1799,11 +1799,16 @@
final ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea,
getMapContext().getCoordinateReferenceSystem());
+ // TODO Die
+
worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv,
getVisibleRect());
try {
- screenToWorld = worldToScreen.createInverse();
+ if (worldToScreen != null)
+ screenToWorld = worldToScreen.createInverse();
+ else
+ screenToWorld = null;
} catch (final NoninvertibleTransformException ex) {
LOGGER
@@ -2041,8 +2046,7 @@
* the two. If <code>null</code> is passed, Double.MINVALUE are used which
* mean there is no restriction.
*
- * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
- * Tzeggai</a>
+ * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Tzeggai</a>
*/
public void setMaxZoomScale(final Double maxZoomScale) {
this.maxZoomScale = maxZoomScale == null ? Double.MIN_VALUE
@@ -2063,8 +2067,7 @@
* used which mean there is no restriction.
*
*
- * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
- * Tzeggai</a>
+ * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Tzeggai</a>
*/
public void setMinZoomScale(final Double minZoomScale) {
this.minZoomScale = minZoomScale == null ? Double.MAX_VALUE
@@ -2244,7 +2247,7 @@
repaint();
}
}
-
+
if (getCursor() == SwingUtil.PANNING_CURSOR) {
// This cursor will reset itself
return;
@@ -2316,7 +2319,7 @@
- mapImage.getWidth() - 10, getVisibleRect().height
- mapImage.getHeight() - 10, null);
}
-
+
int y = 17;
// If the rendering process is still running, indicate this is the image
@@ -2600,15 +2603,19 @@
// BB umrechnen von Layer-CRS in Map-CRS
final CoordinateReferenceSystem targetCRS = getMapContext()
.getCoordinateReferenceSystem();
- CoordinateReferenceSystem sourceCRS = layer
- .getFeatureSource().getSchema()
- .getCoordinateReferenceSystem();
+ CoordinateReferenceSystem sourceCRS = layer.getFeatureSource()
+ .getSchema().getCoordinateReferenceSystem();
if (sourceCRS == null) {
- sourceCRS = layer.getFeatureSource().getSchema().getGeometryDescriptor().getCoordinateReferenceSystem();
- LOGGER.info("CRS for "+layer.getTitle()+" could not be determined from schema, trying GeometryDescriptor results: "+sourceCRS );
+ sourceCRS = layer.getFeatureSource().getSchema()
+ .getGeometryDescriptor().getCoordinateReferenceSystem();
+ LOGGER
+ .info("CRS for "
+ + layer.getTitle()
+ + " could not be determined from schema, trying GeometryDescriptor results: "
+ + sourceCRS);
}
-
+
Envelope mapAreaNew;
if (!CRS.equalsIgnoreMetadata(sourceCRS, targetCRS)) {
mapAreaNew = JTSUtil.transformEnvelope(layer.getFeatureSource()
@@ -2687,8 +2694,7 @@
* Index of the {@link MapLayer} in the {@link MapContext} (from
* back to top)
*
- * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
- * Tzeggai</a>
+ * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Tzeggai</a>
*/
public void zoomToLayer(int index) {
final MapContext context = getMapContext();
@@ -2710,8 +2716,7 @@
* Reverse index of the {@link MapLayer} in the
* {@link MapContext}
*
- * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
- * Tzeggai</a>
+ * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Tzeggai</a>
*/
public void zoomToLayerIdxReverse(int index) {
zoomToLayer(getMapContext().getLayerCount() - 1 - index);
@@ -2722,8 +2727,7 @@
* {@link SelectableXMapPane}. AntiALiasing ist besonders fuer
* Textbeschriftung sehr schoen, verbraucht aber auch mehr Performance.
*
- * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
- * Tzeggai</a>
+ * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Tzeggai</a>
*/
public void setAntiAliasing(final boolean aa) {
// LOGGER.info("Setting AntiAliasing for this JMapPane to " + aa);
Added: branches/2.2.x/src_junit/schmitzm/geotools/gui/XMapPaneTest.java
===================================================================
--- branches/2.2.x/src_junit/schmitzm/geotools/gui/XMapPaneTest.java 2010-06-26 10:55:49 UTC (rev 913)
+++ branches/2.2.x/src_junit/schmitzm/geotools/gui/XMapPaneTest.java 2010-06-26 11:06:32 UTC (rev 914)
@@ -0,0 +1,27 @@
+package schmitzm.geotools.gui;
+
+import static org.junit.Assert.*;
+
+import org.geotools.geometry.jts.ReferencedEnvelope;
+import org.junit.Test;
+
+import schmitzm.geotools.GTUtil;
+
+public class XMapPaneTest {
+
+ @Test
+ public void testBestAllowedMapArea() {
+
+ XMapPane xMapPane = new XMapPane();
+
+ ReferencedEnvelope zeroWidthBBOx = new ReferencedEnvelope(1,1,2,2,GTUtil.WGS84);
+ assertEquals(0., zeroWidthBBOx.getWidth(), 0.);
+ assertEquals(0., zeroWidthBBOx.getHeight(), 0.);
+ ReferencedEnvelope corrected = xMapPane.bestAllowedMapArea(zeroWidthBBOx);
+
+ assertTrue(corrected.getWidth() > 0.);
+ assertTrue(corrected.getHeight() > 0.);
+
+ }
+
+}
Property changes on: branches/2.2.x/src_junit/schmitzm/geotools/gui/XMapPaneTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Id URL
Name: svn:eol-style
+ native
More information about the Schmitzm-commits
mailing list