001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/test/junit/org/deegree/model/spatialschema/GeometryTest.java $
002: /*---------------- FILE HEADER ------------------------------------------
003:
004: This file is part of deegree.
005: Copyright (C) 2001-2008 by:
006: EXSE, Department of Geography, University of Bonn
007: http://www.giub.uni-bonn.de/deegree/
008: lat/lon GmbH
009: http://www.lat-lon.de
010:
011: This library is free software; you can redistribute it and/or
012: modify it under the terms of the GNU Lesser General Public
013: License as published by the Free Software Foundation; either
014: version 2.1 of the License, or (at your option) any later version.
015:
016: This library is distributed in the hope that it will be useful,
017: but WITHOUT ANY WARRANTY; without even the implied warranty of
018: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: Lesser General Public License for more details.
020:
021: You should have received a copy of the GNU Lesser General Public
022: License along with this library; if not, write to the Free Software
023: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024:
025: Contact:
026:
027: Andreas Poth
028: lat/lon GmbH
029: Aennchenstr. 19
030: 53115 Bonn
031: Germany
032: E-Mail: poth@lat-lon.de
033:
034: Prof. Dr. Klaus Greve
035: Department of Geography
036: University of Bonn
037: Meckenheimer Allee 166
038: 53115 Bonn
039: Germany
040: E-Mail: greve@giub.uni-bonn.de
041:
042:
043: ---------------------------------------------------------------------------*/
044: package org.deegree.model.spatialschema;
045:
046: import junit.framework.TestCase;
047:
048: import org.deegree.model.crs.CRSFactory;
049: import org.deegree.model.crs.CoordinateSystem;
050: import org.deegree.model.crs.UnknownCRSException;
051:
052: /**
053: *
054: *
055: * @version $Revision: 9336 $
056: * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
057: * @author last edited by: $Author: apoth $
058: *
059: * @version 1.0. $Revision: 9336 $, $Date: 2007-12-27 03:31:18 -0800 (Thu, 27 Dec 2007) $
060: *
061: * @since 2.0
062: */
063: public class GeometryTest extends TestCase {
064:
065: private final static int EPSG_CS_NUMBER = 4326;
066:
067: private final static String EPSG_CS_NAME = "EPSG:" + EPSG_CS_NUMBER;
068:
069: private CoordinateSystem cs;
070:
071: public void setUp() {
072: try {
073: cs = CRSFactory.create(EPSG_CS_NAME);
074: } catch (UnknownCRSException e) {
075: e.printStackTrace();
076: throw new RuntimeException(e);
077: }
078: }
079:
080: public void testSurface1() throws Exception {
081: Surface s1 = createTestSurface1();
082: Surface s2 = createTestSurface1();
083: assertEquals(s1, s2);
084: }
085:
086: public void testSurface2() throws Exception {
087: Surface s1 = createTestSurface2();
088: Surface s2 = createTestSurface2();
089: assertEquals(s1, s2);
090: }
091:
092: public void testSurface3() throws Exception {
093: Surface s1 = createTestSurface1();
094: Surface s2 = createTestSurface2();
095: assertEquals(s1, s2);
096: }
097:
098: /**
099: * Creates a simple test surface (one patch) with one interior ring
100: * @return
101: * @throws GeometryException
102: */
103: private Surface createTestSurface1() throws GeometryException {
104: double[] exteriorRingOrdinates = new double[] { 2581000.0,
105: 5618000.0, 2580950.0, 5618050.0, 2581000.0, 5618100.0,
106: 2581100.0, 5618100.0, 2581100.0, 5618000.0, 2581000.0,
107: 5618000.0 };
108: double[] interiorRingOrdinates = new double[] { 2581025.0,
109: 5618025.0, 2581075.0, 5618025.0, 2581075.0, 5618075.0,
110: 2581025.0, 5618075.0, 2581025.0, 5618025.0 };
111: double[][] interiorRingsOrdinates = new double[][] { interiorRingOrdinates };
112: return GeometryFactory.createSurface(exteriorRingOrdinates,
113: interiorRingsOrdinates, 2, this .cs);
114: }
115:
116: private Surface createTestSurface2() throws GeometryException {
117: double[][] exteriorSegs = new double[3][];
118: exteriorSegs[0] = new double[] { 2581000.0, 5618000.0,
119: 2580950.0, 5618050.0 };
120: exteriorSegs[1] = new double[] { 2581000.0, 5618100.0,
121: 2581100.0, 5618100.0 };
122: exteriorSegs[2] = new double[] { 2581100.0, 5618000.0,
123: 2581000.0, 5618000.0 };
124:
125: CurveSegment[] ecs = new CurveSegment[exteriorSegs.length];
126: for (int i = 0; i < ecs.length; i++) {
127: Position[] pos = new Position[exteriorSegs[i].length / 2];
128: int k = 0;
129: for (int j = 0; j < exteriorSegs[i].length / 2; j++) {
130: pos[j] = GeometryFactory.createPosition(
131: exteriorSegs[i][k++], exteriorSegs[i][k++]);
132: }
133: ecs[i] = GeometryFactory.createCurveSegment(pos, this .cs);
134: }
135:
136: double[][] interiorSegs = new double[2][];
137: interiorSegs[0] = new double[] { 2581025.0, 5618025.0,
138: 2581075.0, 5618025.0 };
139: interiorSegs[1] = new double[] { 2581075.0, 5618075.0,
140: 2581025.0, 5618075.0, 2581025.0, 5618025.0 };
141: CurveSegment[] ics = new CurveSegment[interiorSegs.length];
142: for (int i = 0; i < ics.length; i++) {
143: Position[] pos = new Position[interiorSegs[i].length / 2];
144: int k = 0;
145: for (int j = 0; j < interiorSegs[i].length / 2; j++) {
146: pos[j] = GeometryFactory.createPosition(
147: interiorSegs[i][k++], interiorSegs[i][k++]);
148: }
149: ics[i] = GeometryFactory.createCurveSegment(pos, this .cs);
150: }
151: CurveSegment[][] inner = new CurveSegment[1][2];
152: inner[0][0] = ics[0];
153: inner[0][1] = ics[1];
154:
155: SurfacePatch sp = GeometryFactory.createSurfacePatch(ecs,
156: inner, this.cs);
157: return GeometryFactory.createSurface(sp);
158: }
159:
160: }
|