WKTReader implements ParserReader { public static WKTReader extract(String geometryLiteral) throws DatatypeFormatException { WKTTextSRS wktTextSRS = new WKTTextSRS(geometryLiteral); String srsURI = wktTextSRS.srsURI; String wktText = wktTextSRS.wktText; String goemetryType = "point"; String dimension = ""; String coordinates = ""; if (!wktText.equals("")) { wktText = wktText.trim(); wktText = wktText.toLowerCase(); String[] parts = wktText.split("\\(", 2); String remainder; if (parts.length == 1) { remainder = parts[0].replace("empty", "").trim(); } else { int coordinatesStart = wktText.indexOf("("); coordinates = wktText.substring(coordinatesStart); remainder = parts[0].trim(); } int firstSpace = remainder.indexOf(" "); if (firstSpace != -1) { goemetryType = remainder.substring(0, firstSpace); dimension = remainder.substring(firstSpace + 1); } else { goemetryType = remainder; } } return new WKTReader(goemetryType, dimension, coordinates, srsURI); } protected  WKTReader(String geometryType, String dimensionString, String coordinates, String srsURI); protected  WKTReader(String geometryType, String dimensionString, String coordinates); protected  WKTReader(); @Override Geometry getGeometry(); @Override CoordinateSequenceDimensions getDimensions(); @Override DimensionInfo getDimensionInfo(); @Override String getSrsURI(); static WKTReader extract(String geometryLiteral); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString();  }
@Test public void testExtractPoint2() { String wktText = "POINT (11.0 12.0)"; WKTReader expResult = new WKTReader("point", "", "(11.0 12.0)"); WKTReader result = WKTReader.extract(wktText); assertEquals(expResult, result); }
@Test public void testExtractPoint3() { String wktText = "POINT Z (11.0 12.0 8.0)"; WKTReader expResult = new WKTReader("point", "z", "(11.0 12.0 8.0)"); WKTReader result = WKTReader.extract(wktText); assertEquals(expResult, result); }
@Test public void testExtractPoint3b() { String wktText = "POINT M (11.0 12.0 5.0)"; WKTReader expResult = new WKTReader("point", "m", "(11.0 12.0 5.0)"); WKTReader result = WKTReader.extract(wktText); assertEquals(expResult, result); }
@Test public void testExtractPoint4() { String wktText = "POINT ZM (11.0 12.0 8.0 5.0)"; WKTReader expResult = new WKTReader("point", "zm", "(11.0 12.0 8.0 5.0)"); WKTReader result = WKTReader.extract(wktText); assertEquals(expResult, result); }
@Test public void testExtractPolygon() { String wktText = "POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))"; WKTReader expResult = new WKTReader("polygon", "", "(30 10, 40 40, 20 40, 10 20, 30 10)"); WKTReader result = WKTReader.extract(wktText); assertEquals(expResult, result); }
@Test public void testExtractPolygonHole() { String wktText = "POLYGON ((35 10, 45 45, 15 40, 10 20, 35 10),(20 30, 35 35, 30 20, 20 30))"; WKTReader expResult = new WKTReader("polygon", "", "(35 10, 45 45, 15 40, 10 20, 35 10),(20 30, 35 35, 30 20, 20 30)"); WKTReader result = WKTReader.extract(wktText); assertEquals(expResult, result); }
@Test public void testExtractLineString() { String wktText = "LINESTRING (30 10, 10 30, 40 40)"; WKTReader expResult = new WKTReader("linestring", "", "(30 10, 10 30, 40 40)"); WKTReader result = WKTReader.extract(wktText); assertEquals(expResult, result); }
@Test public void testExtractMultiPoint() { String wktText = "MULTIPOINT ((10 40), (40 30), (20 20), (30 10))"; WKTReader expResult = new WKTReader("multipoint", "", "((10 40), (40 30), (20 20), (30 10))"); WKTReader result = WKTReader.extract(wktText); assertEquals(expResult, result); }
@Test public void testExtractMultiPoint2() { String wktText = "MULTIPOINT (10 40, 40 30, 20 20, 30 10)"; WKTReader expResult = new WKTReader("multipoint", "", "(10 40, 40 30, 20 20, 30 10)"); WKTReader result = WKTReader.extract(wktText); assertEquals(expResult, result); }
@Test public void testExtractMutliLineString() { String wktText = "MULTILINESTRING ((10 10, 20 20, 10 40),(40 40, 30 30, 40 20, 30 10))"; WKTReader expResult = new WKTReader("multilinestring", "", "((10 10, 20 20, 10 40),(40 40, 30 30, 40 20, 30 10))"); WKTReader result = WKTReader.extract(wktText); assertEquals(expResult, result); }
@Test public void testExtractMultiPolygon() { String wktText = "MULTIPOLYGON (((30 20, 45 40, 10 40, 30 20)),((15 5, 40 10, 10 20, 5 10, 15 5)))"; WKTReader expResult = new WKTReader("multipolygon", "", "(((30 20, 45 40, 10 40, 30 20)),((15 5, 40 10, 10 20, 5 10, 15 5)))"); WKTReader result = WKTReader.extract(wktText); assertEquals(expResult, result); }
@Test public void testExtractMultiPolygon2() { String wktText = "MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)),((20 35, 10 30, 10 10, 30 5, 45 20, 20 35),(30 20, 20 15, 20 25, 30 20)))"; WKTReader expResult = new WKTReader("multipolygon", "", "(((40 40, 20 45, 45 30, 40 40)),((20 35, 10 30, 10 10, 30 5, 45 20, 20 35),(30 20, 20 15, 20 25, 30 20)))"); WKTReader result = WKTReader.extract(wktText); assertEquals(expResult, result); }
@Test public void testExtractGeometryCollection() { String wktText = "GEOMETRYCOLLECTION(POINT(4 6),LINESTRING(4 6,7 10), MULTIPOINT((6 8),(2 3)))"; WKTReader expResult = new WKTReader("geometrycollection", "", "(POINT(4 6),LINESTRING(4 6,7 10), MULTIPOINT((6 8),(2 3)))"); WKTReader result = WKTReader.extract(wktText); assertEquals(expResult, result); }