@Override public int size() { int size = 0; for (Points points : pointsList) { size += points.size(); } return size; }
@Override public Point get(int i) { int offset = 0; for (Points points : pointsList) { if (i - offset < points.size()) { return points.get(i - offset); } offset += points.size(); } throw new NoSuchElementException(); }
/** * @throws XMLStreamException * @throws FactoryConfigurationError * @throws IOException * @throws UnknownCRSException * @throws TransformationException */ @Test public void testMultiGeometry() throws XMLStreamException, FactoryConfigurationError, IOException, TransformationException, UnknownCRSException { XMLStreamReaderWrapper xmlReader = new XMLStreamReaderWrapper(this.getClass().getResource(BASE_DIR + MULTIGEOMETRY_FILE)); xmlReader.nextTag(); Assert.assertEquals(XMLStreamConstants.START_ELEMENT, xmlReader.getEventType()); Assert.assertEquals(new QName(GML21NS, "MultiGeometry"), xmlReader.getName()); MultiGeometry<?> multiGeometry = new GML2GeometryReader().parseMultiGeometry(xmlReader, null); assertEquals("c731", multiGeometry.getId()); Point firstMember = (Point) multiGeometry.get(0); assertEquals("P6776", firstMember.getId()); comparePoint(50.0, 50.0, firstMember); LineString secondMember = (LineString) multiGeometry.get(1); assertEquals("L21216", secondMember.getId()); Points controlPoints = secondMember.getControlPoints(); comparePoint(0.0, 0.0, controlPoints.get(0)); comparePoint(0.0, 50.0, controlPoints.get(1)); comparePoint(100.0, 50.0, controlPoints.get(2)); Polygon thirdMember = (Polygon) multiGeometry.get(2); assertEquals("_877789", thirdMember.getId()); Points points = thirdMember.getExteriorRing().getControlPoints(); comparePoint(0.0, 0.0, points.get(0)); comparePoint(100.0, 0.0, points.get(1)); comparePoint(50.0, 100.0, points.get(2)); comparePoint(0.0, 0.0, points.get(3)); XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); outputFactory.setProperty("javax.xml.stream.isRepairingNamespaces", new Boolean(true)); XMLMemoryStreamWriter memoryWriter = new XMLMemoryStreamWriter(); SchemaLocationXMLStreamWriter writer = new SchemaLocationXMLStreamWriter( memoryWriter.getXMLStreamWriter(), SCHEMA_LOCATION_ATTRIBUTE); GML2GeometryWriter exporter = new GML2GeometryWriter(writer, null, null, new HashSet<String>()); writer.setPrefix("gml", "http://www.opengis.net/gml"); writer.setPrefix("xlink", "http://www.w3.org/1999/xlink"); exporter.export(multiGeometry); writer.flush(); XMLAssert.assertValidity(memoryWriter.getReader(), SCHEMA_LOCATION); }
/** * @throws XMLStreamException * @throws FactoryConfigurationError * @throws IOException * @throws UnknownCRSException * @throws TransformationException */ @Test public void testLineString() throws XMLStreamException, FactoryConfigurationError, IOException, UnknownCRSException, TransformationException { XMLStreamReaderWrapper xmlReader = new XMLStreamReaderWrapper(this.getClass().getResource(BASE_DIR + LINESTRING_FILE)); xmlReader.nextTag(); Assert.assertEquals(XMLStreamConstants.START_ELEMENT, xmlReader.getEventType()); Assert.assertEquals(new QName(GML21NS, "LineString"), xmlReader.getName()); LineString lineString = new GML2GeometryReader().parseLineString(xmlReader, null); Assert.assertEquals(XMLStreamConstants.END_ELEMENT, xmlReader.getEventType()); Assert.assertEquals(new QName(GML21NS, "LineString"), xmlReader.getName()); Points controlPoints = lineString.getControlPoints(); comparePoint(0.0, 0.0, controlPoints.get(0)); comparePoint(20.0, 35.0, controlPoints.get(1)); comparePoint(100.0, 100.0, controlPoints.get(2)); Assert.assertEquals( CRSRegistry.lookup("http://www.opengis.net/gml/srs/epsg.xml#4326"), lineString.getCoordinateSystem().getWrappedCRS()); XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); outputFactory.setProperty("javax.xml.stream.isRepairingNamespaces", new Boolean(true)); XMLMemoryStreamWriter memoryWriter = new XMLMemoryStreamWriter(); SchemaLocationXMLStreamWriter writer = new SchemaLocationXMLStreamWriter( memoryWriter.getXMLStreamWriter(), SCHEMA_LOCATION_ATTRIBUTE); GML2GeometryWriter exporter = new GML2GeometryWriter(writer, null, null, new HashSet<String>()); writer.setPrefix("gml", "http://www.opengis.net/gml"); writer.setPrefix("xlink", "http://www.w3.org/1999/xlink"); exporter.export(lineString); writer.flush(); XMLAssert.assertValidity(memoryWriter.getReader(), SCHEMA_LOCATION); }
/** * @throws XMLStreamException * @throws FactoryConfigurationError * @throws IOException * @throws UnknownCRSException * @throws TransformationException */ @Test public void testMultiLineString() throws XMLStreamException, FactoryConfigurationError, IOException, TransformationException, UnknownCRSException { XMLStreamReaderWrapper xmlReader = new XMLStreamReaderWrapper(this.getClass().getResource(BASE_DIR + MULTILINESTRING_FILE)); xmlReader.nextTag(); Assert.assertEquals(XMLStreamConstants.START_ELEMENT, xmlReader.getEventType()); Assert.assertEquals(new QName(GML21NS, "MultiLineString"), xmlReader.getName()); MultiLineString multiLineString = new GML2GeometryReader().parseMultiLineString(xmlReader, null); LineString firstMember = multiLineString.get(0); Points controlPoints = firstMember.getControlPoints(); comparePoint(56.1, 0.45, controlPoints.get(0)); comparePoint(67.23, 0.98, controlPoints.get(1)); LineString secondMember = multiLineString.get(1); controlPoints = secondMember.getControlPoints(); comparePoint(46.71, 9.25, controlPoints.get(0)); comparePoint(56.88, 10.44, controlPoints.get(1)); LineString thirdMember = multiLineString.get(2); controlPoints = thirdMember.getControlPoints(); comparePoint(324.1, 219.7, controlPoints.get(0)); comparePoint(0.45, 4.56, controlPoints.get(1)); XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); outputFactory.setProperty("javax.xml.stream.isRepairingNamespaces", new Boolean(true)); XMLMemoryStreamWriter memoryWriter = new XMLMemoryStreamWriter(); SchemaLocationXMLStreamWriter writer = new SchemaLocationXMLStreamWriter( memoryWriter.getXMLStreamWriter(), SCHEMA_LOCATION_ATTRIBUTE); GML2GeometryWriter exporter = new GML2GeometryWriter(writer, null, null, new HashSet<String>()); writer.setPrefix("gml", "http://www.opengis.net/gml"); writer.setPrefix("xlink", "http://www.w3.org/1999/xlink"); exporter.export(multiLineString); writer.flush(); XMLAssert.assertValidity(memoryWriter.getReader(), SCHEMA_LOCATION); }
/** * @throws XMLStreamException * @throws FactoryConfigurationError * @throws IOException * @throws UnknownCRSException * @throws TransformationException */ @Test public void testMultiPolygon() throws XMLStreamException, FactoryConfigurationError, IOException, UnknownCRSException, TransformationException { XMLStreamReaderWrapper xmlReader = new XMLStreamReaderWrapper(this.getClass().getResource(BASE_DIR + MULTIPOLYGON_FILE)); xmlReader.nextTag(); Assert.assertEquals(XMLStreamConstants.START_ELEMENT, xmlReader.getEventType()); Assert.assertEquals(new QName(GML21NS, "MultiPolygon"), xmlReader.getName()); MultiPolygon multiPolygon = new GML2GeometryReader().parseMultiPolygon(xmlReader, null); Polygon firstMember = multiPolygon.get(0); Points points = firstMember.getExteriorRing().getControlPoints(); comparePoint(0.0, 0.0, points.get(0)); comparePoint(100.0, 0.0, points.get(1)); comparePoint(100.0, 100.0, points.get(2)); comparePoint(0.0, 100.0, points.get(3)); comparePoint(0.0, 0.0, points.get(4)); List<Points> innerPoints = firstMember.getInteriorRingsCoordinates(); Points points1 = innerPoints.get(0); comparePoint(10.0, 10.0, points1.get(0)); comparePoint(10.0, 40.0, points1.get(1)); comparePoint(40.0, 40.0, points1.get(2)); comparePoint(40.0, 10.0, points1.get(3)); comparePoint(10.0, 10.0, points1.get(4)); Points points2 = innerPoints.get(1); comparePoint(60.0, 60.0, points2.get(0)); comparePoint(60.0, 90.0, points2.get(1)); comparePoint(90.0, 90.0, points2.get(2)); comparePoint(90.0, 60.0, points2.get(3)); comparePoint(60.0, 60.0, points2.get(4)); Polygon secondMember = multiPolygon.get(1); points = secondMember.getExteriorRing().getControlPoints(); comparePoint(0.0, 0.0, points.get(0)); comparePoint(100.0, 0.0, points.get(1)); comparePoint(100.0, 100.0, points.get(2)); comparePoint(0.0, 100.0, points.get(3)); comparePoint(0.0, 0.0, points.get(4)); Assert.assertEquals( CRSRegistry.lookup("http://www.opengis.net/gml/srs/epsg.xml#4326"), multiPolygon.getCoordinateSystem().getWrappedCRS()); XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); outputFactory.setProperty("javax.xml.stream.isRepairingNamespaces", new Boolean(true)); XMLMemoryStreamWriter memoryWriter = new XMLMemoryStreamWriter(); SchemaLocationXMLStreamWriter writer = new SchemaLocationXMLStreamWriter( memoryWriter.getXMLStreamWriter(), SCHEMA_LOCATION_ATTRIBUTE); GML2GeometryWriter exporter = new GML2GeometryWriter(writer, null, null, new HashSet<String>()); writer.setPrefix("gml", "http://www.opengis.net/gml"); writer.setPrefix("xlink", "http://www.w3.org/1999/xlink"); exporter.export(multiPolygon); writer.flush(); XMLAssert.assertValidity(memoryWriter.getReader(), SCHEMA_LOCATION); }
@Override public Point getEndPoint() { Points p = pointsList.get(pointsList.size() - 1); return p.getEndPoint(); }
@Override public int getCoordinateDimension() { return controlPoints.get(0).getCoordinateDimension(); }