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 StaticMultiLineStringTest extends ConnectedTestCase {
055:
056: /**
057: * @param arg
058: */
059: public StaticMultiLineStringTest(String arg) {
060: super (arg);
061: }
062:
063: /**
064: * Round Trip test for a single line string
065: * @throws SQLException
066: */
067: public void testSingleMultiLineStringRoundTrip()
068: throws SQLException {
069: LineStringGenerator pgc = new LineStringGenerator();
070: pgc.setGeometryFactory(geometryFactory);
071: pgc.setNumberPoints(10);
072: MultiGenerator pg = new MultiGenerator(pgc);
073: pg.setBoundingBox(new Envelope(0, 10, 0, 10));
074: pg.setNumberGeometries(3);
075: pg.setGeometryFactory(geometryFactory);
076:
077: MultiLineString pt = (MultiLineString) pg.create();
078:
079: OraWriter ow = new OraWriter(getConnection());
080: STRUCT st = ow.write(pt);
081:
082: OraReader or = new OraReader();
083: MultiLineString pt2 = (MultiLineString) or.read(st);
084:
085: // System.out.println((pt==null?"NULL":pt.toString()));
086: // System.out.println((pt2==null?"NULL":pt2.toString()));
087: assertTrue(
088: "The input MultiLineString is not the same as the output MultiLineString",
089: pt.equals(pt2));
090: }
091:
092: /**
093: * Round Trip test for a 100 non overlapping line strings
094: * @throws SQLException
095: */
096: public void testGridMultiLineStringsRoundTrip() throws SQLException {
097: GridGenerator grid = new GridGenerator();
098: grid.setGeometryFactory(geometryFactory);
099: grid.setBoundingBox(new Envelope(0, 10, 0, 10));
100: grid.setNumberColumns(10);
101: grid.setNumberRows(10);
102:
103: MultiLineString[] pt = new MultiLineString[100];
104: STRUCT[] st = new STRUCT[100];
105:
106: LineStringGenerator pgc = new LineStringGenerator();
107: pgc.setGeometryFactory(geometryFactory);
108: pgc.setNumberPoints(10);
109: MultiGenerator pg = new MultiGenerator(pgc);
110: pg.setBoundingBox(new Envelope(0, 10, 0, 10));
111: pg.setNumberGeometries(3);
112: pg.setGeometryFactory(geometryFactory);
113:
114: OraWriter ow = new OraWriter(getConnection());
115:
116: int i = 0;
117: while (grid.canCreate() && i < 100) {
118: pg.setBoundingBox(grid.createEnv());
119: pt[i] = (MultiLineString) pg.create();
120: st[i] = ow.write(pt[i]);
121: i++;
122: }
123:
124: OraReader or = new OraReader();
125: i = 0;
126: while (i < 100 && pt[i] != null) {
127: MultiLineString pt2 = (MultiLineString) or.read(st[i]);
128: // System.out.println((pt[i]==null?"NULL":pt[i].toString()));
129: // System.out.println((pt2==null?"NULL":pt2.toString()));
130: assertTrue(
131: "The input MultiLineString is not the same as the output MultiLineString",
132: pt[i].equals(pt2));
133: i++;
134: }
135: }
136:
137: /**
138: * Round Trip test for a 8 overlapping line strings (4 distinct line strings)
139: * @throws SQLException
140: */
141: public void testOverlappingMultiLineStringsRoundTrip()
142: throws SQLException {
143: GridGenerator grid = new GridGenerator();
144: grid.setGeometryFactory(geometryFactory);
145: grid.setBoundingBox(new Envelope(0, 10, 0, 10));
146: grid.setNumberColumns(2);
147: grid.setNumberRows(2);
148:
149: MultiLineString[] pt = new MultiLineString[4];
150: STRUCT[] st = new STRUCT[8];
151:
152: LineStringGenerator pgc = new LineStringGenerator();
153: pgc.setGeometryFactory(geometryFactory);
154: pgc.setNumberPoints(10);
155: MultiGenerator pg = new MultiGenerator(pgc);
156: pg.setBoundingBox(new Envelope(0, 10, 0, 10));
157: pg.setNumberGeometries(3);
158: pg.setGeometryFactory(geometryFactory);
159:
160: OraWriter ow = new OraWriter(getConnection());
161:
162: int i = 0;
163: while (grid.canCreate() && i < 8) {
164: pg.setBoundingBox(grid.createEnv());
165: pt[i] = (MultiLineString) pg.create();
166: st[i] = ow.write(pt[i]);
167: i++;
168: }
169: for (int j = 0; j < 4; j++) {
170: if (pt[j] != null)
171: st[i++] = ow.write(pt[j]);
172: }
173:
174: OraReader or = new OraReader();
175: i = 0;
176: while (i < 8 && pt[i % 4] != null) {
177: MultiLineString pt2 = (MultiLineString) or.read(st[i]);
178: // System.out.println((pt==null?"NULL":pt[i%4].toString()));
179: // System.out.println((pt2==null?"NULL":pt2.toString()));
180: assertTrue(
181: "The input MultiLineString is not the same as the output MultiLineString",
182: pt[i % 4].equals(pt2));
183: i++;
184: }
185: }
186:
187: /**
188: * Round Trip test for a single line string with lotsa points
189: * @throws SQLException
190: */
191: public void testSingleMultiLineStringManyPointRoundTrip()
192: throws SQLException {
193:
194: LineStringGenerator pgc = new LineStringGenerator();
195: pgc.setGeometryFactory(geometryFactory);
196: pgc.setNumberPoints(1000);
197: pgc.setGenerationAlgorithm(LineStringGenerator.HORZ);
198: MultiGenerator pg = new MultiGenerator(pgc);
199: pg.setBoundingBox(new Envelope(0, 10, 0, 10));
200: pg.setNumberGeometries(3);
201: pg.setGeometryFactory(geometryFactory);
202:
203: MultiLineString pt = (MultiLineString) pg.create();
204: // System.out.println((pt==null?"NULL":pt.toString()));
205:
206: OraWriter ow = new OraWriter(getConnection());
207: STRUCT st = ow.write(pt);
208:
209: OraReader or = new OraReader();
210: MultiLineString pt2 = (MultiLineString) or.read(st);
211:
212: // System.out.println((pt==null?"NULL":pt.toString()));
213: // System.out.println((pt2==null?"NULL":pt2.toString()));
214: assertTrue(
215: "The input MultiLineString is not the same as the output MultiLineString",
216: pt.equals(pt2));
217: }
218: }
|