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: * NOTE: The points may be re-ordered during these tests.
053: *
054: * @author David Zwiers, Vivid Solutions.
055: */
056: public class StaticMultiPolygonTest extends ConnectedTestCase {
057:
058: /**
059: * @param arg
060: */
061: public StaticMultiPolygonTest(String arg) {
062: super (arg);
063: }
064:
065: /**
066: * Round Trip test for a single MultiPolygon
067: * @throws SQLException
068: */
069: public void testSingleMultiPolygonNoHoleRoundTrip()
070: throws SQLException {
071: PolygonGenerator pgc = new PolygonGenerator();
072: pgc.setGeometryFactory(geometryFactory);
073: pgc.setNumberPoints(10);
074: MultiGenerator pg = new MultiGenerator(pgc);
075: pg.setBoundingBox(new Envelope(0, 10, 0, 10));
076: pg.setNumberGeometries(3);
077: pg.setGeometryFactory(geometryFactory);
078:
079: MultiPolygon pt = (MultiPolygon) pg.create();
080:
081: OraWriter ow = new OraWriter(getConnection());
082: STRUCT st = ow.write(pt);
083:
084: OraReader or = new OraReader();
085: MultiPolygon pt2 = (MultiPolygon) or.read(st);
086:
087: // System.out.println((pt==null?"NULL":pt.toString()));
088: // System.out.println((pt2==null?"NULL":pt2.toString()));
089: assertTrue(
090: "The input MultiPolygon is not the same as the output MultiPolygon",
091: pt.equals(pt2));
092: }
093:
094: /**
095: * Round Trip test for a 100 non overlapping MultiPolygon
096: * @throws SQLException
097: */
098: public void testGridMultiPolygonsNoHoleRoundTrip()
099: throws SQLException {
100: GridGenerator grid = new GridGenerator();
101: grid.setGeometryFactory(geometryFactory);
102: grid.setBoundingBox(new Envelope(0, 10, 0, 10));
103: grid.setNumberColumns(10);
104: grid.setNumberRows(10);
105:
106: MultiPolygon[] pt = new MultiPolygon[100];
107: STRUCT[] st = new STRUCT[100];
108:
109: PolygonGenerator pgc = new PolygonGenerator();
110: pgc.setGeometryFactory(geometryFactory);
111: pgc.setNumberPoints(10);
112: MultiGenerator pg = new MultiGenerator(pgc);
113: pg.setBoundingBox(new Envelope(0, 10, 0, 10));
114: pg.setNumberGeometries(3);
115: pg.setGeometryFactory(geometryFactory);
116:
117: OraWriter ow = new OraWriter(getConnection());
118:
119: int i = 0;
120: while (grid.canCreate() && i < 100) {
121: pg.setBoundingBox(grid.createEnv());
122: pt[i] = (MultiPolygon) pg.create();
123: st[i] = ow.write(pt[i]);
124: i++;
125: }
126:
127: OraReader or = new OraReader();
128: i = 0;
129: while (i < 100 && pt[i] != null) {
130: MultiPolygon pt2 = (MultiPolygon) or.read(st[i]);
131: // System.out.println((pt[i]==null?"NULL":pt[i].toString()));
132: // System.out.println((pt2==null?"NULL":pt2.toString()));
133: assertTrue(
134: "The input MultiPolygon is not the same as the output MultiPolygon",
135: pt[i].equals(pt2));
136: i++;
137: }
138: }
139:
140: /**
141: * Round Trip test for a 8 overlapping line MultiPolygons (4 distinct MultiPolygons)
142: * @throws SQLException
143: */
144: public void testOverlappingMultiPolygonsNoHoleRoundTrip()
145: throws SQLException {
146: GridGenerator grid = new GridGenerator();
147: grid.setGeometryFactory(geometryFactory);
148: grid.setBoundingBox(new Envelope(0, 10, 0, 10));
149: grid.setNumberColumns(2);
150: grid.setNumberRows(2);
151:
152: MultiPolygon[] pt = new MultiPolygon[4];
153: STRUCT[] st = new STRUCT[8];
154:
155: PolygonGenerator pgc = new PolygonGenerator();
156: pgc.setGeometryFactory(geometryFactory);
157: pgc.setNumberPoints(10);
158: MultiGenerator pg = new MultiGenerator(pgc);
159: pg.setBoundingBox(new Envelope(0, 10, 0, 10));
160: pg.setNumberGeometries(3);
161: pg.setGeometryFactory(geometryFactory);
162:
163: OraWriter ow = new OraWriter(getConnection());
164:
165: int i = 0;
166: while (grid.canCreate() && i < 8) {
167: pg.setBoundingBox(grid.createEnv());
168: pt[i] = (MultiPolygon) pg.create();
169: st[i] = ow.write(pt[i]);
170: i++;
171: }
172: for (int j = 0; j < 4; j++) {
173: if (pt[j] != null)
174: st[i++] = ow.write(pt[j]);
175: }
176:
177: OraReader or = new OraReader();
178: i = 0;
179: while (i < 8 && pt[i % 4] != null) {
180: MultiPolygon pt2 = (MultiPolygon) or.read(st[i]);
181: // System.out.println((pt==null?"NULL":pt[i%4].toString()));
182: // System.out.println((pt2==null?"NULL":pt2.toString()));
183: assertTrue(
184: "The input MultiPolygon is not the same as the output MultiPolygon",
185: pt[i % 4].equals(pt2));
186: i++;
187: }
188: }
189:
190: /**
191: * Round Trip test for a single MultiPolygon with lotsa points
192: * @throws SQLException
193: */
194: public void testSingleMultiPolygonManyPointsNoHoleRoundTrip()
195: throws SQLException {
196:
197: PolygonGenerator pgc = new PolygonGenerator();
198: pgc.setGeometryFactory(geometryFactory);
199: pgc.setGenerationAlgorithm(PolygonGenerator.BOX);
200: pgc.setNumberPoints(1000);
201: MultiGenerator pg = new MultiGenerator(pgc);
202: pg.setBoundingBox(new Envelope(0, 10, 0, 10));
203: pg.setNumberGeometries(3);
204: pg.setGeometryFactory(geometryFactory);
205:
206: MultiPolygon pt = (MultiPolygon) pg.create();
207: // System.out.println((pt==null?"NULL":pt.toString()));
208:
209: OraWriter ow = new OraWriter(getConnection());
210: STRUCT st = ow.write(pt);
211:
212: OraReader or = new OraReader();
213: MultiPolygon pt2 = (MultiPolygon) or.read(st);
214:
215: // System.out.println((pt==null?"NULL":pt.toString()));
216: // System.out.println((pt2==null?"NULL":pt2.toString()));
217: assertTrue(
218: "The input MultiPolygon is not the same as the output MultiPolygon",
219: pt.equals(pt2));
220: }
221:
222: /**
223: * Round Trip test for a single MultiPolygon
224: * @throws SQLException
225: */
226: public void testSingleMultiPolygonHolesRoundTrip()
227: throws SQLException {
228:
229: PolygonGenerator pgc = new PolygonGenerator();
230: pgc.setGeometryFactory(geometryFactory);
231: pgc.setGenerationAlgorithm(PolygonGenerator.BOX);
232: pgc.setNumberPoints(10);
233: pgc.setNumberHoles(4);
234: MultiGenerator pg = new MultiGenerator(pgc);
235: pg.setBoundingBox(new Envelope(0, 10, 0, 10));
236: pg.setNumberGeometries(3);
237: pg.setGeometryFactory(geometryFactory);
238:
239: MultiPolygon pt = (MultiPolygon) pg.create();
240:
241: OraWriter ow = new OraWriter(getConnection());
242: STRUCT st = ow.write(pt);
243:
244: OraReader or = new OraReader();
245: MultiPolygon pt2 = (MultiPolygon) or.read(st);
246:
247: // System.out.println((pt==null?"NULL":pt.toString()));
248: // System.out.println((pt2==null?"NULL":pt2.toString()));
249: assertTrue(
250: "The input MultiPolygon is not the same as the output MultiPolygon",
251: pt.equals(pt2));
252: }
253:
254: /**
255: * Round Trip test for a 100 non overlapping MultiPolygon
256: * @throws SQLException
257: */
258: public void testGridMultiPolygonsHolesRoundTrip()
259: throws SQLException {
260: GridGenerator grid = new GridGenerator();
261: grid.setGeometryFactory(geometryFactory);
262: grid.setBoundingBox(new Envelope(0, 10, 0, 10));
263: grid.setNumberColumns(10);
264: grid.setNumberRows(10);
265:
266: MultiPolygon[] pt = new MultiPolygon[100];
267: STRUCT[] st = new STRUCT[100];
268:
269: PolygonGenerator pgc = new PolygonGenerator();
270: pgc.setGeometryFactory(geometryFactory);
271: pgc.setGenerationAlgorithm(PolygonGenerator.BOX);
272: pgc.setNumberPoints(10);
273: pgc.setNumberHoles(4);
274: MultiGenerator pg = new MultiGenerator(pgc);
275: pg.setBoundingBox(new Envelope(0, 10, 0, 10));
276: pg.setNumberGeometries(3);
277: pg.setGeometryFactory(geometryFactory);
278:
279: OraWriter ow = new OraWriter(getConnection());
280:
281: int i = 0;
282: while (grid.canCreate() && i < 100) {
283: pg.setBoundingBox(grid.createEnv());
284: pt[i] = (MultiPolygon) pg.create();
285: st[i] = ow.write(pt[i]);
286: i++;
287: }
288:
289: OraReader or = new OraReader();
290: i = 0;
291: while (i < 100 && pt[i] != null) {
292: MultiPolygon pt2 = (MultiPolygon) or.read(st[i]);
293: // System.out.println((pt[i]==null?"NULL":pt[i].toString()));
294: // System.out.println((pt2==null?"NULL":pt2.toString()));
295: assertTrue(
296: "The input MultiPolygon is not the same as the output MultiPolygon",
297: pt[i].equals(pt2));
298: i++;
299: }
300: }
301:
302: /**
303: * Round Trip test for a 8 overlapping line MultiPolygons (4 distinct MultiPolygons)
304: * @throws SQLException
305: */
306: public void testOverlappingMultiPolygonsHolesRoundTrip()
307: throws SQLException {
308: GridGenerator grid = new GridGenerator();
309: grid.setGeometryFactory(geometryFactory);
310: grid.setBoundingBox(new Envelope(0, 10, 0, 10));
311: grid.setNumberColumns(2);
312: grid.setNumberRows(2);
313:
314: MultiPolygon[] pt = new MultiPolygon[4];
315: STRUCT[] st = new STRUCT[8];
316:
317: PolygonGenerator pgc = new PolygonGenerator();
318: pgc.setGeometryFactory(geometryFactory);
319: pgc.setGenerationAlgorithm(PolygonGenerator.BOX);
320: pgc.setNumberPoints(10);
321: pgc.setNumberHoles(4);
322: MultiGenerator pg = new MultiGenerator(pgc);
323: pg.setBoundingBox(new Envelope(0, 10, 0, 10));
324: pg.setNumberGeometries(3);
325: pg.setGeometryFactory(geometryFactory);
326:
327: OraWriter ow = new OraWriter(getConnection());
328:
329: int i = 0;
330: while (grid.canCreate() && i < 8) {
331: pg.setBoundingBox(grid.createEnv());
332: pt[i] = (MultiPolygon) pg.create();
333: st[i] = ow.write(pt[i]);
334: i++;
335: }
336: for (int j = 0; j < 4; j++) {
337: if (pt[j] != null)
338: st[i++] = ow.write(pt[j]);
339: }
340:
341: OraReader or = new OraReader();
342: i = 0;
343: while (i < 8 && pt[i % 4] != null) {
344: MultiPolygon pt2 = (MultiPolygon) or.read(st[i]);
345: // System.out.println((pt==null?"NULL":pt[i%4].toString()));
346: // System.out.println((pt2==null?"NULL":pt2.toString()));
347: assertTrue(
348: "The input MultiPolygon is not the same as the output MultiPolygon",
349: pt[i % 4].equals(pt2));
350: i++;
351: }
352: }
353:
354: /**
355: * Round Trip test for a single MultiPolygon with lotsa points
356: * @throws SQLException
357: */
358: public void testSingleMultiPolygonManyPointsHolesRoundTrip()
359: throws SQLException {
360:
361: PolygonGenerator pgc = new PolygonGenerator();
362: pgc.setGeometryFactory(geometryFactory);
363: pgc.setGenerationAlgorithm(PolygonGenerator.BOX);
364: pgc.setNumberPoints(1000);
365: pgc.setNumberHoles(4);
366: MultiGenerator pg = new MultiGenerator(pgc);
367: pg.setBoundingBox(new Envelope(0, 10, 0, 10));
368: pg.setNumberGeometries(3);
369: pg.setGeometryFactory(geometryFactory);
370:
371: MultiPolygon pt = (MultiPolygon) pg.create();
372: // System.out.println((pt==null?"NULL":pt.toString()));
373:
374: OraWriter ow = new OraWriter(getConnection());
375: STRUCT st = ow.write(pt);
376:
377: OraReader or = new OraReader();
378: MultiPolygon pt2 = (MultiPolygon) or.read(st);
379:
380: // System.out.println((pt==null?"NULL":pt.toString()));
381: // System.out.println((pt2==null?"NULL":pt2.toString()));
382: assertTrue(
383: "The input MultiPolygon is not the same as the output MultiPolygon",
384: pt.equals(pt2));
385: }
386:
387: /**
388: * Round Trip test for a single MultiPolygon with lotsa points
389: * @throws SQLException
390: */
391: public void testSingleMultiPolygonManyPointsManyHolesRoundTrip()
392: throws SQLException {
393:
394: PolygonGenerator pgc = new PolygonGenerator();
395: pgc.setGeometryFactory(geometryFactory);
396: pgc.setGenerationAlgorithm(PolygonGenerator.BOX);
397: pgc.setNumberPoints(100);
398: pgc.setNumberHoles(100);
399: MultiGenerator pg = new MultiGenerator(pgc);
400: pg.setBoundingBox(new Envelope(0, 10, 0, 10));
401: pg.setNumberGeometries(3);
402: pg.setGeometryFactory(geometryFactory);
403:
404: MultiPolygon pt = (MultiPolygon) pg.create();
405: // System.out.println((pt==null?"NULL":pt.toString()));
406:
407: OraWriter ow = new OraWriter(getConnection());
408: STRUCT st = ow.write(pt);
409:
410: OraReader or = new OraReader();
411: MultiPolygon pt2 = (MultiPolygon) or.read(st);
412:
413: // System.out.println((pt==null?"NULL":pt.toString()));
414: // System.out.println((pt2==null?"NULL":pt2.toString()));
415: assertTrue(
416: "The input MultiPolygon is not the same as the output MultiPolygon",
417: pt.equals(pt2));
418: }
419: }
|