001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2003-2006, Geotools Project Managment Committee (PMC)
005: * (C) 2003, Institut de Recherche pour le Développement
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: */
017: package org.geotools.coverage.grid;
018:
019: // J2SE dependencies
020: import java.awt.geom.AffineTransform;
021:
022: // JUnit dependencies
023: import junit.framework.Test;
024: import junit.framework.TestCase;
025: import junit.framework.TestSuite;
026:
027: // OpenGIS dependencies
028: import org.opengis.referencing.FactoryException;
029: import org.opengis.referencing.operation.MathTransform;
030: import org.opengis.referencing.operation.MathTransformFactory;
031: import org.opengis.geometry.Envelope;
032:
033: // Geotools dependencies
034: import org.geotools.geometry.GeneralEnvelope;
035: import org.geotools.referencing.ReferencingFactoryFinder;
036: import org.geotools.referencing.operation.matrix.MatrixFactory;
037:
038: /**
039: * Test the {@link GridGeometry} implementation.
040: *
041: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/coverage/src/test/java/org/geotools/coverage/grid/GridGeometryTest.java $
042: * @version $Id: GridGeometryTest.java 25050 2007-04-06 00:41:49Z jgarnett $
043: * @author Martin Desruisseaux
044: */
045: public class GridGeometryTest extends TestCase {
046: /**
047: * Run the suite from the command line.
048: */
049: public static void main(final String[] args) {
050: junit.textui.TestRunner.run(suite());
051: }
052:
053: /**
054: * Returns the test suite.
055: */
056: public static Test suite() {
057: return new TestSuite(GridGeometryTest.class);
058: }
059:
060: /**
061: * Constructs a test case with the given name.
062: */
063: public GridGeometryTest(final String name) {
064: super (name);
065: }
066:
067: /**
068: * Tests the construction with an identity transform.
069: */
070: public void testIdentity() throws FactoryException {
071: final MathTransformFactory factory = ReferencingFactoryFinder
072: .getMathTransformFactory(null);
073: final int[] lower = new int[] { 0, 0, 2 };
074: final int[] upper = new int[] { 100, 200, 4 };
075: final MathTransform identity = factory
076: .createAffineTransform(MatrixFactory.create(4));
077: GridGeometry2D gg;
078: try {
079: gg = new GridGeometry2D(new GeneralGridRange(lower, upper),
080: identity, null);
081: fail();
082: } catch (IllegalArgumentException e) {
083: // This is the expected dimension.
084: }
085: upper[2] = 3;
086: gg = new GridGeometry2D(new GeneralGridRange(lower, upper),
087: identity, null);
088: assertTrue(identity.isIdentity());
089: assertTrue(gg.getGridToCoordinateSystem().isIdentity());
090: assertTrue(gg.getGridToCRS2D().isIdentity());
091: assertEquals(3, gg.getGridToCoordinateSystem()
092: .getSourceDimensions());
093: assertEquals(2, gg.getGridToCRS2D().getSourceDimensions());
094: assertTrue(gg.getGridToCRS2D() instanceof AffineTransform);
095: }
096:
097: /**
098: * Tests the construction from an envelope.
099: */
100: public void testEnvelope() {
101: final int[] lower = new int[] { 0, 0, 4 };
102: final int[] upper = new int[] { 90, 45, 5 };
103: final double[] minimum = new double[] { -180, -90, 9 };
104: final double[] maximum = new double[] { +180, +90, 10 };
105: final GridGeometry2D gg;
106: gg = new GridGeometry2D(new GeneralGridRange(lower, upper),
107: new GeneralEnvelope(minimum, maximum), null, false);
108: final AffineTransform tr = (AffineTransform) gg
109: .getGridToCRS2D();
110: assertEquals(AffineTransform.TYPE_UNIFORM_SCALE
111: | AffineTransform.TYPE_TRANSLATION, tr.getType());
112:
113: assertEquals(4, tr.getScaleX(), 0);
114: assertEquals(4, tr.getScaleY(), 0);
115: assertEquals(-178, tr.getTranslateX(), 0);
116: assertEquals(-88, tr.getTranslateY(), 0);
117: }
118: }
|