WKTDatatype extends GeometryDatatype { @Override public GeometryWrapper read(String geometryLiteral) { WKTReader wktReader = WKTReader.extract(geometryLiteral); Geometry geometry = wktReader.getGeometry(); String srsURI = wktReader.getSrsURI(); DimensionInfo dimensionInfo = wktReader.getDimensionInfo(); return new GeometryWrapper(geometry, srsURI, URI, dimensionInfo, geometryLiteral); } private  WKTDatatype(); @Override String unparse(Object geometry); @Override GeometryWrapper read(String geometryLiteral); @Override String toString(); static final String URI; static final WKTDatatype INSTANCE; }
@Test public void testReadPoint() { String wktLiteral = "POINT ZM (11.0 12.0 8.0 5.0)"; Geometry geometry = GEOMETRY_FACTORY.createPoint(new CustomCoordinateSequence(CoordinateSequenceDimensions.XYZM, "11.0 12.0 8.0 5.0")); GeometryWrapper expResult = new GeometryWrapper(geometry, SRS_URI.DEFAULT_WKT_CRS84, WKTDatatype.URI, new DimensionInfo(4, 3, 0)); GeometryWrapper result = WKT_DATATYPE.read(wktLiteral); assertEquals(expResult, result); }
@Test public void testReadPoint2() { String wktLiteral = "<http: Geometry geometry = GEOMETRY_FACTORY.createPoint(new CustomCoordinateSequence(CoordinateSequenceDimensions.XYZM, "11.0 12.0 8.0 5.0")); GeometryWrapper expResult = new GeometryWrapper(geometry, SRS_URI.DEFAULT_WKT_CRS84, WKTDatatype.URI, new DimensionInfo(4, 3, 0), wktLiteral); GeometryWrapper result = WKT_DATATYPE.read(wktLiteral); assertEquals(expResult, result); }
@Test public void testReadLineString() { String wktLiteral = "LINESTRING ZM (11 12.1 8 5, 3 4 6 2)"; Geometry geometry = GEOMETRY_FACTORY.createLineString(new CustomCoordinateSequence(CoordinateSequenceDimensions.XYZM, "11 12.1 8 5, 3 4 6 2")); GeometryWrapper expResult = new GeometryWrapper(geometry, SRS_URI.DEFAULT_WKT_CRS84, WKTDatatype.URI, new DimensionInfo(4, 3, 1)); GeometryWrapper result = WKT_DATATYPE.read(wktLiteral); assertEquals(expResult, result); }
@Test public void testReadPolygon() { String wktLiteral = "POLYGON ZM((30 10 0 1, 40 40 0 1, 20 40 0 1, 10 20 0 1, 30 10 0 1))"; Geometry geometry = GEOMETRY_FACTORY.createPolygon(new CustomCoordinateSequence(CoordinateSequenceDimensions.XYZM, "30 10 0 1, 40 40 0 1, 20 40 0 1, 10 20 0 1, 30 10 0 1")); GeometryWrapper expResult = new GeometryWrapper(geometry, SRS_URI.DEFAULT_WKT_CRS84, WKTDatatype.URI, new DimensionInfo(4, 3, 2), wktLiteral); GeometryWrapper result = WKT_DATATYPE.read(wktLiteral); assertEquals(expResult, result); }
@Test public void testReadPolygon2() { String wktLiteral = "POLYGON ZM((30 10 0 1, 40 40 0 1, 20 40 0 1, 10 20 0 1, 30 10 0 1), (20 30 0 1, 35 35 0 1, 30 20 0 1, 20 30 0 1))"; LinearRing shell = GEOMETRY_FACTORY.createLinearRing(new CustomCoordinateSequence(CoordinateSequenceDimensions.XYZM, "30 10 0 1, 40 40 0 1, 20 40 0 1, 10 20 0 1, 30 10 0 1")); LinearRing[] holes = new LinearRing[]{GEOMETRY_FACTORY.createLinearRing(new CustomCoordinateSequence(CoordinateSequenceDimensions.XYZM, "20 30 0 1, 35 35 0 1, 30 20 0 1, 20 30 0 1"))}; Geometry geometry = GEOMETRY_FACTORY.createPolygon(shell, holes); GeometryWrapper expResult = new GeometryWrapper(geometry, SRS_URI.DEFAULT_WKT_CRS84, WKTDatatype.URI, new DimensionInfo(4, 3, 2)); GeometryWrapper result = WKT_DATATYPE.read(wktLiteral); assertEquals(expResult, result); }
@Test public void testReadMultiPoint() { String wktLiteral = "MULTIPOINT ZM((10 40 0 1), (40 30 0 1), (20 20 0 1), (30 10 0 1))"; Geometry geometry = GEOMETRY_FACTORY.createMultiPoint(new CustomCoordinateSequence(CoordinateSequenceDimensions.XYZM, "10 40 0 1, 40 30 0 1, 20 20 0 1, 30 10 0 1")); GeometryWrapper expResult = new GeometryWrapper(geometry, SRS_URI.DEFAULT_WKT_CRS84, WKTDatatype.URI, new DimensionInfo(4, 3, 0)); GeometryWrapper result = WKT_DATATYPE.read(wktLiteral); assertEquals(expResult, result); }
@Test public void testReadMultiLineString() { String wktLiteral = "MULTILINESTRING ZM((10 10 0 1, 20 20 0 1, 10 40 0 1), (40 40 0 1, 30 30 0 1, 40 20 0 1, 30 10 0 1))"; LineString[] lineStrings = new LineString[2]; lineStrings[0] = GEOMETRY_FACTORY.createLineString(new CustomCoordinateSequence(CoordinateSequenceDimensions.XYZM, "10 10 0 1, 20 20 0 1, 10 40 0 1")); lineStrings[1] = GEOMETRY_FACTORY.createLineString(new CustomCoordinateSequence(CoordinateSequenceDimensions.XYZM, "40 40 0 1, 30 30 0 1, 40 20 0 1, 30 10 0 1")); Geometry geometry = GEOMETRY_FACTORY.createMultiLineString(lineStrings); GeometryWrapper expResult = new GeometryWrapper(geometry, SRS_URI.DEFAULT_WKT_CRS84, WKTDatatype.URI, new DimensionInfo(4, 3, 1)); GeometryWrapper result = WKT_DATATYPE.read(wktLiteral); assertEquals(expResult, result); }
@Test public void testReadMultiPolygon() { String wktLiteral = "MULTIPOLYGON ZM(((40 40 0 1, 20 45 0 1, 45 30 0 1, 40 40 0 1)), ((20 35 0 1, 10 30 0 1, 10 10 0 1, 30 5 0 1, 45 20 0 1, 20 35 0 1), (30 20 0 1, 20 15 0 1, 20 25 0 1, 30 20 0 1)))"; Polygon[] polygons = new Polygon[2]; polygons[0] = GEOMETRY_FACTORY.createPolygon(new CustomCoordinateSequence(CoordinateSequenceDimensions.XYZM, "40 40 0 1, 20 45 0 1, 45 30 0 1, 40 40 0 1")); LinearRing shell = GEOMETRY_FACTORY.createLinearRing(new CustomCoordinateSequence(CoordinateSequenceDimensions.XYZM, "20 35 0 1, 10 30 0 1, 10 10 0 1, 30 5 0 1, 45 20 0 1, 20 35 0 1")); LinearRing[] holes = new LinearRing[]{GEOMETRY_FACTORY.createLinearRing(new CustomCoordinateSequence(CoordinateSequenceDimensions.XYZM, "30 20 0 1, 20 15 0 1, 20 25 0 1, 30 20 0 1"))}; polygons[1] = GEOMETRY_FACTORY.createPolygon(shell, holes); Geometry geometry = GEOMETRY_FACTORY.createMultiPolygon(polygons); GeometryWrapper expResult = new GeometryWrapper(geometry, SRS_URI.DEFAULT_WKT_CRS84, WKTDatatype.URI, new DimensionInfo(4, 3, 2)); GeometryWrapper result = WKT_DATATYPE.read(wktLiteral); assertEquals(expResult, result); }
@Test public void testReadGeometryCollection() { String wktLiteral = "GEOMETRYCOLLECTION ZM(POINT ZM (4 6 0 1), LINESTRING ZM (4 6 0 1, 7 10 0 1))"; Geometry[] geometries = new Geometry[2]; geometries[0] = GEOMETRY_FACTORY.createPoint(new CustomCoordinateSequence(CoordinateSequenceDimensions.XYZM, "4 6 0 1")); geometries[1] = GEOMETRY_FACTORY.createLineString(new CustomCoordinateSequence(CoordinateSequenceDimensions.XYZM, "4 6 0 1,7 10 0 1")); Geometry geometry = GEOMETRY_FACTORY.createGeometryCollection(geometries); GeometryWrapper expResult = new GeometryWrapper(geometry, SRS_URI.DEFAULT_WKT_CRS84, WKTDatatype.URI, new DimensionInfo(4, 3, 1)); GeometryWrapper result = WKT_DATATYPE.read(wktLiteral); assertEquals(expResult, result); }
@Test public void testEmpty() { GeometryWrapper geo = WKT_DATATYPE.read(""); Geometry test = GEOMETRY_FACTORY.createPoint(); GeometryWrapper expResult = new GeometryWrapper(test, SRS_URI.DEFAULT_WKT_CRS84, WKTDatatype.URI, new DimensionInfo(2, 2, 0)); assertEquals(geo, expResult); }