001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/test/junit/org/deegree/io/datastore/sql/oracle/JGeometryAdapterTest.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.io.datastore.sql.oracle;
045:
046: import junit.framework.TestCase;
047: import oracle.spatial.geometry.JGeometry;
048:
049: import org.deegree.model.crs.CRSFactory;
050: import org.deegree.model.crs.CoordinateSystem;
051: import org.deegree.model.crs.UnknownCRSException;
052: import org.deegree.model.spatialschema.Curve;
053: import org.deegree.model.spatialschema.GeometryException;
054: import org.deegree.model.spatialschema.GeometryFactory;
055: import org.deegree.model.spatialschema.MultiCurve;
056: import org.deegree.model.spatialschema.MultiPoint;
057: import org.deegree.model.spatialschema.MultiSurface;
058: import org.deegree.model.spatialschema.Point;
059: import org.deegree.model.spatialschema.Position;
060: import org.deegree.model.spatialschema.Surface;
061:
062: /**
063: * Bla bla bla...
064: *
065: * @author <a href="mailto:schneider@lat-lon.de">Markus Schneider </a>
066: *
067: * @author last edited by: $Author $
068: *
069: * @version 2.0, $Revision $, $Date $
070: *
071: * @since 2.0
072: */
073: public class JGeometryAdapterTest extends TestCase {
074:
075: private final static int EPSG_CS_NUMBER = 4326;
076:
077: private final static String EPSG_CS_NAME = "EPSG:" + EPSG_CS_NUMBER;
078:
079: private CoordinateSystem cs;
080:
081: public void setUp() {
082: try {
083: cs = CRSFactory.create(EPSG_CS_NAME);
084: } catch (UnknownCRSException e) {
085: e.printStackTrace();
086: throw new RuntimeException(e);
087: }
088: }
089:
090: public void testPoint() throws GeometryException {
091: Point point = GeometryFactory.createPoint(2581400, 5618780, cs);
092:
093: JGeometry jGeometry = JGeometryAdapter.export(point,
094: EPSG_CS_NUMBER);
095:
096: assertEquals(JGeometry.GTYPE_POINT, jGeometry.getType());
097: assertEquals(EPSG_CS_NUMBER, jGeometry.getSRID());
098: Point point2 = (Point) JGeometryAdapter.wrap(jGeometry, cs);
099: assertEquals(point, point2);
100: }
101:
102: public void testMultiPoint() throws GeometryException {
103: Point point1 = GeometryFactory
104: .createPoint(2581400, 5618780, cs);
105: Point point2 = GeometryFactory
106: .createPoint(2581300, 5618680, cs);
107: MultiPoint multiPoint = GeometryFactory
108: .createMultiPoint(new Point[] { point1, point2 });
109:
110: JGeometry jGeometry = JGeometryAdapter.export(multiPoint,
111: EPSG_CS_NUMBER);
112:
113: assertEquals(JGeometry.GTYPE_MULTIPOINT, jGeometry.getType());
114: assertEquals(EPSG_CS_NUMBER, jGeometry.getSRID());
115: MultiPoint multiPoint2 = (MultiPoint) JGeometryAdapter.wrap(
116: jGeometry, cs);
117: assertEquals(multiPoint, multiPoint2);
118: }
119:
120: public void testCurve() throws GeometryException {
121: Position[] positions = new Position[4];
122: positions[0] = GeometryFactory.createPosition(2581400, 5618780);
123: positions[1] = GeometryFactory.createPosition(2581300, 5618680);
124: positions[2] = GeometryFactory.createPosition(2581200, 5618580);
125: positions[3] = GeometryFactory.createPosition(2581100, 5618480);
126: Curve curve = GeometryFactory.createCurve(positions, this .cs);
127: JGeometry jGeometry = JGeometryAdapter.export(curve,
128: EPSG_CS_NUMBER);
129: assertEquals(JGeometry.GTYPE_CURVE, jGeometry.getType());
130: assertEquals(EPSG_CS_NUMBER, jGeometry.getSRID());
131: Curve curve2 = (Curve) JGeometryAdapter.wrap(jGeometry, cs);
132: assertEquals(curve, curve2);
133: }
134:
135: public void testMultiCurve() throws GeometryException {
136: Position[] positions1 = new Position[4];
137: positions1[0] = GeometryFactory
138: .createPosition(2581400, 5618780);
139: positions1[1] = GeometryFactory
140: .createPosition(2581300, 5618680);
141: positions1[2] = GeometryFactory
142: .createPosition(2581200, 5618580);
143: positions1[3] = GeometryFactory
144: .createPosition(2581100, 5618480);
145: Curve curve1 = GeometryFactory.createCurve(positions1, this .cs);
146: Position[] positions2 = new Position[2];
147: positions2[0] = GeometryFactory
148: .createPosition(2581200, 5618580);
149: positions2[1] = GeometryFactory
150: .createPosition(2581100, 5618480);
151: Curve curve2 = GeometryFactory.createCurve(positions2, this .cs);
152: Position[] positions3 = new Position[5];
153: positions3[0] = GeometryFactory
154: .createPosition(2581400, 5618780);
155: positions3[1] = GeometryFactory
156: .createPosition(2581300, 5618680);
157: positions3[2] = GeometryFactory
158: .createPosition(2581200, 5618580);
159: positions3[3] = GeometryFactory
160: .createPosition(2581100, 5618480);
161: positions3[4] = GeometryFactory
162: .createPosition(2581300, 5618680);
163: Curve curve3 = GeometryFactory.createCurve(positions3, this .cs);
164: MultiCurve multiCurve = GeometryFactory
165: .createMultiCurve(new Curve[] { curve1, curve2, curve3 });
166: JGeometry jGeometry = JGeometryAdapter.export(multiCurve,
167: EPSG_CS_NUMBER);
168: assertEquals(JGeometry.GTYPE_MULTICURVE, jGeometry.getType());
169: assertEquals(EPSG_CS_NUMBER, jGeometry.getSRID());
170: MultiCurve multiCurve2 = (MultiCurve) JGeometryAdapter.wrap(
171: jGeometry, cs);
172: // TODO: implement and use MultiCurve.equals() here
173: assertEquals(multiCurve.toString(), multiCurve2.toString());
174: }
175:
176: public void testSurface() throws GeometryException {
177: Surface surface = createTestSurface1();
178: JGeometry jGeometry = JGeometryAdapter.export(surface,
179: EPSG_CS_NUMBER);
180: assertEquals(JGeometry.GTYPE_POLYGON, jGeometry.getType());
181: assertEquals(EPSG_CS_NUMBER, jGeometry.getSRID());
182: Surface surface2 = (Surface) JGeometryAdapter.wrap(jGeometry,
183: cs);
184: assertEquals(surface, surface2);
185: }
186:
187: public void testMultiSurface() throws GeometryException {
188: MultiSurface multiSurface = GeometryFactory
189: .createMultiSurface(new Surface[] {
190: createTestSurface1(), createTestSurface2() });
191: JGeometry jGeometry = JGeometryAdapter.export(multiSurface,
192: EPSG_CS_NUMBER);
193: assertEquals(JGeometry.GTYPE_MULTIPOLYGON, jGeometry.getType());
194: assertEquals(EPSG_CS_NUMBER, jGeometry.getSRID());
195: JGeometryAdapter.wrap(jGeometry, cs);
196: // TODO: implement and use MultiSurface.equals() here
197: // assertEquals(multiSurface, multiSurface2);
198: }
199:
200: // Creates a simple test surface (one patch) with one interior ring
201: private Surface createTestSurface1() throws GeometryException {
202: double[] exteriorRingOrdinates = new double[] { 2581000.0,
203: 5618000.0, 2580950.0, 5618050.0, 2581000.0, 5618100.0,
204: 2581100.0, 5618100.0, 2581100.0, 5618000.0, 2581000.0,
205: 5618000.0 };
206: double[] interiorRingOrdinates = new double[] { 2581025.0,
207: 5618025.0, 2581075.0, 5618025.0, 2581075.0, 5618075.0,
208: 2581025.0, 5618075.0, 2581025.0, 5618025.0 };
209: double[][] interiorRingsOrdinates = new double[][] { interiorRingOrdinates };
210: return GeometryFactory.createSurface(exteriorRingOrdinates,
211: interiorRingsOrdinates, 2, this .cs);
212: }
213:
214: // Creates a simple test surface (one patch) with two interior rings
215: private Surface createTestSurface2() throws GeometryException {
216: double[] exteriorRingOrdinates = new double[] { 2586000.0,
217: 5618000.0, 2585950.0, 5618050.0, 2586000.0, 5618100.0,
218: 2586100.0, 5618100.0, 2586100.0, 5618000.0, 2586000.0,
219: 5618000.0 };
220: double[] interiorRing1Ordinates = new double[] { 2586025.0,
221: 5618025.0, 2586075.0, 5618025.0, 2586075.0, 5618075.0,
222: 2586025.0, 5618075.0, 2586025.0, 5618025.0 };
223: double[] interiorRing2Ordinates = new double[] { 2586010.0,
224: 5618010.0, 2586020.0, 5618010.0, 2586015.0, 5618015.0,
225: 2586010.0, 5618010.0 };
226: double[][] interiorRingsOrdinates = new double[][] {
227: interiorRing1Ordinates, interiorRing2Ordinates };
228: return GeometryFactory.createSurface(exteriorRingOrdinates,
229: interiorRingsOrdinates, 2, this.cs);
230: }
231: }
|