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.gml2;
034:
035: import java.io.IOException;
036:
037: import javax.xml.parsers.ParserConfigurationException;
038:
039: import org.xml.sax.SAXException;
040:
041: import com.vividsolutions.jts.generator.MultiGenerator;
042: import com.vividsolutions.jts.generator.PolygonGenerator;
043: import com.vividsolutions.jts.geom.Envelope;
044: import com.vividsolutions.jts.geom.MultiPolygon;
045:
046: /**
047: *
048: * Does round trip testing by creating the oracle object, then decoding it.
049: *
050: * These tests do not include insert / delete / select operations.
051: *
052: * NOTE: This test does require a precision to be used during the comparison,
053: * as points are rounded somewhat when creating the oracle struct.
054: * (One less decimal than a java double).
055: *
056: * NOTE: The points may be re-ordered during these tests.
057: *
058: * @author David Zwiers, Vivid Solutions.
059: */
060: public class StaticMultiPolygonTest extends WritingTestCase {
061:
062: /**
063: * @param arg
064: */
065: public StaticMultiPolygonTest(String arg) {
066: super (arg);
067: }
068:
069: /**
070: * Round Trip test for a single MultiPolygon
071: * @throws ParserConfigurationException
072: * @throws IOException
073: * @throws SAXException
074: */
075: public void testSingleMultiPolygonNoHoleRoundTrip()
076: throws SAXException, IOException,
077: ParserConfigurationException {
078: PolygonGenerator pgc = new PolygonGenerator();
079: pgc.setGeometryFactory(geometryFactory);
080: pgc.setNumberPoints(10);
081: MultiGenerator pg = new MultiGenerator(pgc);
082: pg.setBoundingBox(new Envelope(0, 10, 0, 10));
083: pg.setNumberGeometries(3);
084: pg.setGeometryFactory(geometryFactory);
085:
086: MultiPolygon pt = (MultiPolygon) pg.create();
087:
088: GMLWriter out = new GMLWriter();
089: out.setPrefix(null);
090: out.write(pt, getWriter());
091:
092: GMLReader in = new GMLReader();
093: MultiPolygon pt2 = (MultiPolygon) in.read(getReader(),
094: geometryFactory);
095:
096: // System.out.println((pt==null?"NULL":pt.toString()));
097: // System.out.println((pt2==null?"NULL":pt2.toString()));
098: assertTrue(
099: "The input MultiPolygon is not the same as the output MultiPolygon",
100: pt.equals(pt2));
101: }
102:
103: /**
104: * Round Trip test for a single MultiPolygon with lotsa points
105: * @throws ParserConfigurationException
106: * @throws IOException
107: * @throws SAXException
108: */
109: public void testSingleMultiPolygonManyPointsNoHoleRoundTrip()
110: throws SAXException, IOException,
111: ParserConfigurationException {
112:
113: PolygonGenerator pgc = new PolygonGenerator();
114: pgc.setGeometryFactory(geometryFactory);
115: pgc.setGenerationAlgorithm(PolygonGenerator.BOX);
116: pgc.setNumberPoints(1000);
117: MultiGenerator pg = new MultiGenerator(pgc);
118: pg.setBoundingBox(new Envelope(0, 10, 0, 10));
119: pg.setNumberGeometries(3);
120: pg.setGeometryFactory(geometryFactory);
121:
122: MultiPolygon pt = (MultiPolygon) pg.create();
123:
124: GMLWriter out = new GMLWriter();
125: out.setPrefix(null);
126: out.write(pt, getWriter());
127:
128: GMLReader in = new GMLReader();
129: MultiPolygon pt2 = (MultiPolygon) in.read(getReader(),
130: geometryFactory);
131:
132: // System.out.println((pt==null?"NULL":pt.toString()));
133: // System.out.println((pt2==null?"NULL":pt2.toString()));
134: assertTrue(
135: "The input MultiPolygon is not the same as the output MultiPolygon",
136: pt.equals(pt2));
137: }
138:
139: /**
140: * Round Trip test for a single MultiPolygon
141: * @throws ParserConfigurationException
142: * @throws IOException
143: * @throws SAXException
144: */
145: public void testSingleMultiPolygonHolesRoundTrip()
146: throws SAXException, IOException,
147: ParserConfigurationException {
148:
149: PolygonGenerator pgc = new PolygonGenerator();
150: pgc.setGeometryFactory(geometryFactory);
151: pgc.setGenerationAlgorithm(PolygonGenerator.BOX);
152: pgc.setNumberPoints(10);
153: pgc.setNumberHoles(4);
154: MultiGenerator pg = new MultiGenerator(pgc);
155: pg.setBoundingBox(new Envelope(0, 10, 0, 10));
156: pg.setNumberGeometries(3);
157: pg.setGeometryFactory(geometryFactory);
158:
159: MultiPolygon pt = (MultiPolygon) pg.create();
160:
161: GMLWriter out = new GMLWriter();
162: out.setPrefix(null);
163: out.write(pt, getWriter());
164:
165: GMLReader in = new GMLReader();
166: MultiPolygon pt2 = (MultiPolygon) in.read(getReader(),
167: geometryFactory);
168:
169: // System.out.println((pt==null?"NULL":pt.toString()));
170: // System.out.println((pt2==null?"NULL":pt2.toString()));
171: assertTrue(
172: "The input MultiPolygon is not the same as the output MultiPolygon",
173: pt.equals(pt2));
174: }
175:
176: /**
177: * Round Trip test for a single MultiPolygon with lotsa points
178: * @throws ParserConfigurationException
179: * @throws IOException
180: * @throws SAXException
181: */
182: public void testSingleMultiPolygonManyPointsHolesRoundTrip()
183: throws SAXException, IOException,
184: ParserConfigurationException {
185:
186: PolygonGenerator pgc = new PolygonGenerator();
187: pgc.setGeometryFactory(geometryFactory);
188: pgc.setGenerationAlgorithm(PolygonGenerator.BOX);
189: pgc.setNumberPoints(1000);
190: pgc.setNumberHoles(4);
191: MultiGenerator pg = new MultiGenerator(pgc);
192: pg.setBoundingBox(new Envelope(0, 10, 0, 10));
193: pg.setNumberGeometries(3);
194: pg.setGeometryFactory(geometryFactory);
195:
196: MultiPolygon pt = (MultiPolygon) pg.create();
197: // System.out.println((pt==null?"NULL":pt.toString()));
198:
199: GMLWriter out = new GMLWriter();
200: out.setPrefix(null);
201: out.write(pt, getWriter());
202:
203: GMLReader in = new GMLReader();
204: MultiPolygon pt2 = (MultiPolygon) in.read(getReader(),
205: geometryFactory);
206:
207: // System.out.println((pt==null?"NULL":pt.toString()));
208: // System.out.println((pt2==null?"NULL":pt2.toString()));
209: assertTrue(
210: "The input MultiPolygon is not the same as the output MultiPolygon",
211: pt.equals(pt2));
212: }
213:
214: /**
215: * Round Trip test for a single MultiPolygon with lotsa points
216: * @throws ParserConfigurationException
217: * @throws IOException
218: * @throws SAXException
219: */
220: public void testSingleMultiPolygonManyPointsManyHolesRoundTrip()
221: throws SAXException, IOException,
222: ParserConfigurationException {
223:
224: PolygonGenerator pgc = new PolygonGenerator();
225: pgc.setGeometryFactory(geometryFactory);
226: pgc.setGenerationAlgorithm(PolygonGenerator.BOX);
227: pgc.setNumberPoints(100);
228: pgc.setNumberHoles(100);
229: MultiGenerator pg = new MultiGenerator(pgc);
230: pg.setBoundingBox(new Envelope(0, 10, 0, 10));
231: pg.setNumberGeometries(3);
232: pg.setGeometryFactory(geometryFactory);
233:
234: MultiPolygon pt = (MultiPolygon) pg.create();
235: // System.out.println((pt==null?"NULL":pt.toString()));
236:
237: GMLWriter out = new GMLWriter();
238: out.setPrefix(null);
239: out.write(pt, getWriter());
240:
241: GMLReader in = new GMLReader();
242: MultiPolygon pt2 = (MultiPolygon) in.read(getReader(),
243: geometryFactory);
244:
245: // System.out.println((pt==null?"NULL":pt.toString()));
246: // System.out.println((pt2==null?"NULL":pt2.toString()));
247: assertTrue(
248: "The input MultiPolygon is not the same as the output MultiPolygon",
249: pt.equals(pt2));
250: }
251: }
|