GMLDatatype extends GeometryDatatype { @Override public GeometryWrapper read(String geometryLiteral) { try { GMLReader gmlReader = GMLReader.extract(geometryLiteral); Geometry geometry = gmlReader.getGeometry(); String srsURI = gmlReader.getSrsURI(); DimensionInfo dimensionInfo = gmlReader.getDimensionInfo(); return new GeometryWrapper(geometry, srsURI, URI, dimensionInfo, geometryLiteral); } catch (JDOMException | IOException ex) { throw new DatatypeFormatException("Illegal GML literal:" + geometryLiteral + ". " + ex.getMessage()); } } GMLDatatype(); @Override String unparse(Object geometry); @Override GeometryWrapper read(String geometryLiteral); @Override String toString(); static final String URI; static final GMLDatatype INSTANCE; static final String GML_PREFIX; }
@Test public void testPointURL() throws JDOMException, IOException { GeometryWrapper geo = GML_DATATYPE.read("<gml:Point srsName=\"http: Geometry test = GEOMETRY_FACTORY.createPoint(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "-83.4 34.4")); GeometryWrapper expResult = new GeometryWrapper(test, URL_SRS_NAMESPACE, GMLDatatype.URI, new DimensionInfo(2, 2, 0)); assertEquals(geo, expResult); }
@Test public void testPointURN() throws JDOMException, IOException { GeometryWrapper geo = GML_DATATYPE.read("<gml:Point srsName=\"urn:ogc:def:crs:EPSG::27700\" xmlns:gml=\"http: Geometry test = GEOMETRY_FACTORY.createPoint(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "-83.4 34.4")); GeometryWrapper expResult = new GeometryWrapper(test, URN_SRS_NAMESPACE, GMLDatatype.URI, new DimensionInfo(2, 2, 0)); assertEquals(geo, expResult); }
@Test public void testLineString() throws JDOMException, IOException { GeometryWrapper geo = GML_DATATYPE.read("<gml:LineString srsName=\"urn:ogc:def:crs:EPSG::27700\" xmlns:gml=\"http: Geometry test = GEOMETRY_FACTORY.createLineString(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "-83.4 34.0, -83.3 34.3")); GeometryWrapper expResult = new GeometryWrapper(test, URN_SRS_NAMESPACE, GMLDatatype.URI, new DimensionInfo(2, 2, 1)); assertEquals(geo, expResult); }
@Test public void testPolygon() throws JDOMException, IOException { GeometryWrapper geo = GML_DATATYPE.read("<gml:Polygon xmlns:gml=\"http: Geometry test = GEOMETRY_FACTORY.createPolygon(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "30 10, 40 40, 20 40, 10 20, 30 10")); GeometryWrapper expResult = new GeometryWrapper(test, URN_SRS_NAMESPACE, GMLDatatype.URI, new DimensionInfo(2, 2, 2)); assertEquals(geo, expResult); }
@Test public void testPolygon2() throws JDOMException, IOException { GeometryWrapper geo = GML_DATATYPE.read("<gml:Polygon xmlns:gml=\"http: LinearRing shell = GEOMETRY_FACTORY.createLinearRing(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "30 10, 40 40, 20 40, 10 20, 30 10")); LinearRing[] holes = new LinearRing[]{GEOMETRY_FACTORY.createLinearRing(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "20 30, 35 35, 30 20, 20 30"))}; Geometry test = GEOMETRY_FACTORY.createPolygon(shell, holes); GeometryWrapper expResult = new GeometryWrapper(test, URN_SRS_NAMESPACE, GMLDatatype.URI, new DimensionInfo(2, 2, 2)); assertEquals(geo, expResult); }
@Test public void testMultiPoint() throws JDOMException, IOException { GeometryWrapper geo = GML_DATATYPE.read("<gml:MultiPoint xmlns:gml=\"http: Geometry test = GEOMETRY_FACTORY.createMultiPoint(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "10 40, 40 30, 20 20, 30 10")); GeometryWrapper expResult = new GeometryWrapper(test, "urn:ogc:def:crs:EPSG::27700", GMLDatatype.URI, new DimensionInfo(2, 2, 0)); assertEquals(geo, expResult); }
@Test public void testMultiCurve() throws JDOMException, IOException { GeometryWrapper geo = GML_DATATYPE.read("<gml:MultiCurve xmlns:gml=\"http: LineString[] lineStrings = new LineString[2]; lineStrings[0] = GEOMETRY_FACTORY.createLineString(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "10 10, 20 20, 10 40")); lineStrings[1] = GEOMETRY_FACTORY.createLineString(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "40 40, 30 30, 40 20, 30 10")); Geometry test = GEOMETRY_FACTORY.createMultiLineString(lineStrings); GeometryWrapper expResult = new GeometryWrapper(test, URN_SRS_NAMESPACE, GMLDatatype.URI, new DimensionInfo(2, 2, 1)); assertEquals(geo, expResult); }
@Test public void testMultiSurface() throws JDOMException, IOException { GeometryWrapper geo = GML_DATATYPE.read("<gml:MultiSurface xmlns:gml=\"http: Polygon[] polygons = new Polygon[2]; polygons[0] = GEOMETRY_FACTORY.createPolygon(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "40 40, 20 45, 45 30, 40 40")); LinearRing shell = GEOMETRY_FACTORY.createLinearRing(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "20 35, 10 30, 10 10, 30 5, 45 20, 20 35")); LinearRing[] holes = new LinearRing[]{GEOMETRY_FACTORY.createLinearRing(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "30 20, 20 15, 20 25, 30 20"))}; polygons[1] = GEOMETRY_FACTORY.createPolygon(shell, holes); Geometry test = GEOMETRY_FACTORY.createMultiPolygon(polygons); GeometryWrapper expResult = new GeometryWrapper(test, URN_SRS_NAMESPACE, GMLDatatype.URI, new DimensionInfo(2, 2, 2)); assertEquals(geo, expResult); }
@Test public void testMultiGeometry() throws JDOMException, IOException { GeometryWrapper geo = GML_DATATYPE.read("<gml:MultiGeometry xmlns:gml=\"http: Geometry[] geometries = new Geometry[2]; geometries[0] = GEOMETRY_FACTORY.createPoint(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "4 6")); geometries[1] = GEOMETRY_FACTORY.createLineString(new CustomCoordinateSequence(CoordinateSequenceDimensions.XY, "4 6,7 10")); Geometry test = GEOMETRY_FACTORY.createGeometryCollection(geometries); GeometryWrapper expResult = new GeometryWrapper(test, URN_SRS_NAMESPACE, GMLDatatype.URI, new DimensionInfo(2, 2, 1)); assertEquals(geo, expResult); }
@Test public void testEmpty() throws JDOMException, IOException { GeometryWrapper geo = GML_DATATYPE.read(""); Geometry test = GEOMETRY_FACTORY.createPoint(); GeometryWrapper expResult = new GeometryWrapper(test, SRS_URI.DEFAULT_WKT_CRS84, GMLDatatype.URI, new DimensionInfo(2, 2, 0)); assertEquals(geo, expResult); }