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: * @author David Zwiers, Vivid Solutions.
049: */
050: public class StaticMultiPointTest extends ConnectedTestCase {
051:
052: /**
053: * @param arg
054: */
055: public StaticMultiPointTest(String arg) {
056: super (arg);
057: }
058:
059: /**
060: * Round Trip test for a single MultiPoint
061: * @throws SQLException
062: */
063: public void testSingleMultiPointRoundTrip() throws SQLException {
064: PointGenerator pgc = new PointGenerator();
065: pgc.setGeometryFactory(geometryFactory);
066: MultiGenerator pg = new MultiGenerator(pgc);
067: pg.setBoundingBox(new Envelope(0, 10, 0, 10));
068: pg.setNumberGeometries(3);
069: pg.setGeometryFactory(geometryFactory);
070:
071: MultiPoint pt = (MultiPoint) pg.create();
072:
073: OraWriter ow = new OraWriter(getConnection());
074: STRUCT st = ow.write(pt);
075:
076: OraReader or = new OraReader();
077: MultiPoint pt2 = (MultiPoint) or.read(st);
078:
079: // System.out.println((pt==null?"NULL":pt.toString()));
080: // System.out.println((pt2==null?"NULL":pt2.toString()));
081: assertTrue(
082: "The input MultiPoint is not the same as the output MultiPoint",
083: pt.equals(pt2));
084: }
085:
086: /**
087: * Round Trip test for a 100 non overlapping MultiPoints
088: * @throws SQLException
089: */
090: public void testGridMultiPointsRoundTrip() throws SQLException {
091: GridGenerator grid = new GridGenerator();
092: grid.setGeometryFactory(geometryFactory);
093: grid.setBoundingBox(new Envelope(0, 10, 0, 10));
094: grid.setNumberColumns(10);
095: grid.setNumberRows(10);
096:
097: MultiPoint[] pt = new MultiPoint[100];
098: STRUCT[] st = new STRUCT[100];
099:
100: PointGenerator pgc = new PointGenerator();
101: pgc.setGeometryFactory(geometryFactory);
102: MultiGenerator pg = new MultiGenerator(pgc);
103: pg.setBoundingBox(new Envelope(0, 10, 0, 10));
104: pg.setNumberGeometries(3);
105: pg.setGeometryFactory(geometryFactory);
106:
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] = (MultiPoint) 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: MultiPoint pt2 = (MultiPoint) 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 MultiPoint is not the same as the output MultiPoint",
125: pt[i].equals(pt2));
126: i++;
127: }
128: }
129:
130: /**
131: * Round Trip test for a 8 overlapping MultiPoints (4 distinct MultiPoints)
132: * @throws SQLException
133: */
134: public void testOverlappingMultiPointsRoundTrip()
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: MultiPoint[] pt = new MultiPoint[4];
143: STRUCT[] st = new STRUCT[8];
144:
145: PointGenerator pgc = new PointGenerator();
146: pgc.setGeometryFactory(geometryFactory);
147: MultiGenerator pg = new MultiGenerator(pgc);
148: pg.setBoundingBox(new Envelope(0, 10, 0, 10));
149: pg.setNumberGeometries(3);
150: pg.setGeometryFactory(geometryFactory);
151:
152: OraWriter ow = new OraWriter(getConnection());
153:
154: int i = 0;
155: while (grid.canCreate() && i < 8) {
156: pg.setBoundingBox(grid.createEnv());
157: pt[i] = (MultiPoint) pg.create();
158: st[i] = ow.write(pt[i]);
159: i++;
160: }
161: for (int j = 0; j < 4; j++) {
162: if (pt[j] != null)
163: st[i++] = ow.write(pt[j]);
164: }
165:
166: OraReader or = new OraReader();
167: i = 0;
168: while (i < 8 && pt[i % 4] != null) {
169: MultiPoint pt2 = (MultiPoint) or.read(st[i]);
170: // System.out.println((pt[i]==null?"NULL":pt[i].toString()));
171: // System.out.println((pt2==null?"NULL":pt2.toString()));
172: assertTrue(
173: "The input MultiPoint is not the same as the output MultiPoint",
174: pt[i % 4].equals(pt2));
175: i++;
176: }
177: }
178: }
|