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