001: /*
002: * The JTS Topology Suite is a collection of Java classes that
003: * implement the fundamental operations required to validate a given
004: * geo-spatial data set to a known topological specification.
005: *
006: * Copyright (C) 2001 Vivid Solutions
007: *
008: * This library is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Lesser General Public
010: * License as published by the Free Software Foundation; either
011: * version 2.1 of the License, or (at your option) any later version.
012: *
013: * This library is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public
019: * License along with this library; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
021: *
022: * For more information, contact:
023: *
024: * Vivid Solutions
025: * Suite #1A
026: * 2328 Government Street
027: * Victoria BC V8T 5G5
028: * Canada
029: *
030: * (250)385-6040
031: * www.vividsolutions.com
032: */
033: package com.vividsolutions.jts.io.oracle;
034:
035: import java.sql.SQLException;
036:
037: import oracle.sql.STRUCT;
038:
039: import com.vividsolutions.jts.generator.*;
040: import com.vividsolutions.jts.geom.*;
041:
042: /**
043: *
044: * Does round trip testing by creating the oracle object, then decoding it.
045: *
046: * These tests do not include insert / delete / select operations.
047: *
048: * NOTE: This test does require a precision to be used during the comparison,
049: * as points are rounded somewhat when creating the oracle struct.
050: * (One less decimal than a java double).
051: *
052: * @author David Zwiers, Vivid Solutions.
053: */
054: public class StaticLineStringTest extends ConnectedTestCase {
055:
056: /**
057: * @param arg
058: */
059: public StaticLineStringTest(String arg) {
060: super (arg);
061: }
062:
063: /**
064: * Round Trip test for a single line string
065: * @throws SQLException
066: */
067: public void testSingleLineStringRoundTrip() throws SQLException {
068: LineStringGenerator pg = new LineStringGenerator();
069: pg.setGeometryFactory(geometryFactory);
070: pg.setBoundingBox(new Envelope(0, 10, 0, 10));
071: pg.setNumberPoints(10);
072:
073: LineString pt = (LineString) pg.create();
074:
075: OraWriter ow = new OraWriter(getConnection());
076: STRUCT st = ow.write(pt);
077:
078: OraReader or = new OraReader();
079: LineString pt2 = (LineString) or.read(st);
080:
081: // System.out.println((pt==null?"NULL":pt.toString()));
082: // System.out.println((pt2==null?"NULL":pt2.toString()));
083: assertTrue(
084: "The input LineString is not the same as the output LineString",
085: pt.equals(pt2));
086: }
087:
088: /**
089: * Round Trip test for a 100 non overlapping line strings
090: * @throws SQLException
091: */
092: public void testGridLineStringsRoundTrip() throws SQLException {
093: GridGenerator grid = new GridGenerator();
094: grid.setGeometryFactory(geometryFactory);
095: grid.setBoundingBox(new Envelope(0, 10, 0, 10));
096: grid.setNumberColumns(10);
097: grid.setNumberRows(10);
098:
099: LineString[] pt = new LineString[100];
100: STRUCT[] st = new STRUCT[100];
101:
102: LineStringGenerator pg = new LineStringGenerator();
103: pg.setGeometryFactory(geometryFactory);
104: pg.setNumberPoints(10);
105: OraWriter ow = new OraWriter(getConnection());
106:
107: int i = 0;
108: while (grid.canCreate() && i < 100) {
109: pg.setBoundingBox(grid.createEnv());
110: pt[i] = (LineString) pg.create();
111: st[i] = ow.write(pt[i]);
112: i++;
113: }
114:
115: OraReader or = new OraReader();
116: i = 0;
117: while (i < 100 && pt[i] != null) {
118: LineString pt2 = (LineString) or.read(st[i]);
119: // System.out.println((pt[i]==null?"NULL":pt[i].toString()));
120: // System.out.println((pt2==null?"NULL":pt2.toString()));
121: assertTrue(
122: "The input LineString is not the same as the output LineString",
123: pt[i].equals(pt2));
124: i++;
125: }
126: }
127:
128: /**
129: * Round Trip test for a 8 overlapping line strings (4 distinct line strings)
130: * @throws SQLException
131: */
132: public void testOverlappingLineStringsRoundTrip()
133: throws SQLException {
134: GridGenerator grid = new GridGenerator();
135: grid.setGeometryFactory(geometryFactory);
136: grid.setBoundingBox(new Envelope(0, 10, 0, 10));
137: grid.setNumberColumns(2);
138: grid.setNumberRows(2);
139:
140: LineString[] pt = new LineString[4];
141: STRUCT[] st = new STRUCT[8];
142:
143: LineStringGenerator pg = new LineStringGenerator();
144: pg.setGeometryFactory(geometryFactory);
145: pg.setNumberPoints(10);
146: OraWriter ow = new OraWriter(getConnection());
147:
148: int i = 0;
149: while (grid.canCreate() && i < 8) {
150: pg.setBoundingBox(grid.createEnv());
151: pt[i] = (LineString) pg.create();
152: st[i] = ow.write(pt[i]);
153: i++;
154: }
155: for (int j = 0; j < 4; j++) {
156: if (pt[j] != null)
157: st[i++] = ow.write(pt[j]);
158: }
159:
160: OraReader or = new OraReader();
161: i = 0;
162: while (i < 8 && pt[i % 4] != null) {
163: LineString pt2 = (LineString) or.read(st[i]);
164: // System.out.println((pt==null?"NULL":pt[i%4].toString()));
165: // System.out.println((pt2==null?"NULL":pt2.toString()));
166: assertTrue(
167: "The input LineString is not the same as the output LineString",
168: pt[i % 4].equals(pt2));
169: i++;
170: }
171: }
172:
173: /**
174: * Round Trip test for a single line string with lotsa points
175: * @throws SQLException
176: */
177: public void testSingleLineStringManyPointRoundTrip()
178: throws SQLException {
179: LineStringGenerator pg = new LineStringGenerator();
180: pg.setGeometryFactory(geometryFactory);
181: pg.setBoundingBox(new Envelope(0, 10, 0, 10));
182: pg.setGenerationAlgorithm(LineStringGenerator.HORZ);
183: pg.setNumberPoints(1000);
184:
185: LineString pt = (LineString) pg.create();
186: // System.out.println((pt==null?"NULL":pt.toString()));
187:
188: OraWriter ow = new OraWriter(getConnection());
189: STRUCT st = ow.write(pt);
190:
191: OraReader or = new OraReader();
192: LineString pt2 = (LineString) or.read(st);
193:
194: // System.out.println((pt==null?"NULL":pt.toString()));
195: // System.out.println((pt2==null?"NULL":pt2.toString()));
196: assertTrue(
197: "The input LineString is not the same as the output LineString",
198: pt.equals(pt2));
199: }
200: }
|