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.FileReader;
036: import java.io.IOException;
037:
038: import javax.xml.parsers.ParserConfigurationException;
039:
040: import org.xml.sax.SAXException;
041:
042: import com.vividsolutions.jts.geom.*;
043:
044: import junit.framework.TestCase;
045:
046: public class GMLReaderTestCase extends TestCase {
047:
048: public GMLReaderTestCase(String arg0) {
049: super (arg0);
050: // TODO Auto-generated constructor stub
051: }
052:
053: protected static PrecisionModel precisionModel = new PrecisionModel(
054: 1000);
055: protected static GeometryFactory geometryFactory = new GeometryFactory(
056: precisionModel);
057:
058: public void testPointRead() throws SAXException, IOException,
059: ParserConfigurationException {
060: FileReader fr = new FileReader("./jtsio/test/data/points.xml");
061:
062: GMLReader gr = new GMLReader();
063: Geometry g = gr.read(fr, geometryFactory);
064:
065: GeometryCollection gc = (GeometryCollection) g;
066: assertTrue(gc.getNumGeometries() == 25);
067:
068: for (int i = 0; i < 25; i++) {
069: Point p = (Point) gc.getGeometryN(i);
070: assertNotNull(p);
071: }
072: }
073:
074: public void testLineStringRead() throws SAXException, IOException,
075: ParserConfigurationException {
076: FileReader fr = new FileReader(
077: "./jtsio/test/data/linestrings.xml");
078:
079: GMLReader gr = new GMLReader();
080: Geometry g = gr.read(fr, geometryFactory);
081:
082: GeometryCollection gc = (GeometryCollection) g;
083: assertTrue(gc.getNumGeometries() == 25);
084:
085: for (int i = 0; i < 25; i++) {
086: LineString ls = (LineString) gc.getGeometryN(i);
087: assertNotNull(ls);
088: }
089: }
090:
091: public void testPolygonRead() throws SAXException, IOException,
092: ParserConfigurationException {
093: FileReader fr = new FileReader("./jtsio/test/data/polygons.xml");
094:
095: GMLReader gr = new GMLReader();
096: Geometry g = gr.read(fr, geometryFactory);
097:
098: GeometryCollection gc = (GeometryCollection) g;
099: assertTrue(gc.getNumGeometries() == 25);
100:
101: for (int i = 0; i < 25; i++) {
102: Polygon p = (Polygon) gc.getGeometryN(i);
103: assertNotNull(p);
104: }
105: }
106:
107: public void testMultiPointRead() throws SAXException, IOException,
108: ParserConfigurationException {
109: FileReader fr = new FileReader(
110: "./jtsio/test/data/multipoints.xml");
111:
112: GMLReader gr = new GMLReader();
113: Geometry g = gr.read(fr, geometryFactory);
114:
115: GeometryCollection gc = (GeometryCollection) g;
116: assertTrue(gc.getNumGeometries() == 25);
117:
118: for (int i = 0; i < 25; i++) {
119: MultiPoint p = (MultiPoint) gc.getGeometryN(i);
120: assertNotNull(p);
121: }
122: }
123:
124: public void testMultiLineStringRead() throws SAXException,
125: IOException, ParserConfigurationException {
126: FileReader fr = new FileReader(
127: "./jtsio/test/data/multilinestrings.xml");
128:
129: GMLReader gr = new GMLReader();
130: Geometry g = gr.read(fr, geometryFactory);
131:
132: GeometryCollection gc = (GeometryCollection) g;
133: assertTrue(gc.getNumGeometries() == 25);
134:
135: for (int i = 0; i < 25; i++) {
136: MultiLineString ls = (MultiLineString) gc.getGeometryN(i);
137: assertNotNull(ls);
138: }
139: }
140:
141: public void testMultiPolygonRead() throws SAXException,
142: IOException, ParserConfigurationException {
143: FileReader fr = new FileReader(
144: "./jtsio/test/data/multipolygons.xml");
145:
146: GMLReader gr = new GMLReader();
147: Geometry g = gr.read(fr, geometryFactory);
148:
149: GeometryCollection gc = (GeometryCollection) g;
150: assertTrue(gc.getNumGeometries() == 25);
151:
152: for (int i = 0; i < 25; i++) {
153: MultiPolygon p = (MultiPolygon) gc.getGeometryN(i);
154: assertNotNull(p);
155: }
156: }
157:
158: }
|