public Object convert(Object source, Class target) throws Exception { return new WKTReader2().read((String) source); } };
/** * Creates a <code>LineString</code> using the next token in the stream, the provided dimension * and measures will be used to create the <code>LineString</code>. */ private LineString readLineStringText(int dimension, int measures) throws IOException, ParseException { if (measures == 0) { // default situation, capable of handle elevations but no measures return geometryFactory.createLineString(getCoordinates()); } // handle linestring subtypes with measures (elevation and measures) return geometryFactory.createLineString( buildCoordinateSequence(getCoordinates(true), dimension, measures)); }
public PropertyFeatureReader(String namespace, File file, GeometryFactory geometryFactory) throws IOException { reader = new BufferedReader(new FileReader(file)); // read until "_="; while ((line = reader.readLine()) != null) { if (line.startsWith("_=")) break; } if ((line == null) || !line.startsWith("_=")) { throw new IOException("Property file schema not available found"); } String typeSpec = line.substring(2); String name = file.getName(); String typeName = name.substring(0, name.lastIndexOf('.')); try { type = DataUtilities.createType(namespace, typeName, typeSpec); } catch (SchemaException e) { throw new DataSourceException(typeName + " schema not available", e); } line = null; next = null; if (geometryFactory == null) { wktReader = new WKTReader2(); } else { wktReader = new WKTReader2(geometryFactory); } }
/** * Reads a Well-Known Text representation of a {@link Geometry} from a {@link String}. * * @param wellKnownText one or more <Geometry Tagged Text>strings (see the OpenGIS Simple * Features Specification) separated by whitespace * @return a <code>Geometry</code> specified by <code>wellKnownText</code> * @throws ParseException if a parsing problem occurs */ public Geometry read(String wellKnownText) throws ParseException { StringReader reader = new StringReader(wellKnownText); try { return read(reader); } finally { reader.close(); } }
/** * Creates a <code>LineString</code> using the next token in the stream. * * @return * @throws IOException * @throws ParseException */ private LineString readCircularStringText() throws IOException, ParseException { List<Coordinate> coordinates = getCoordinateList( true ); List<Coordinate> segmentized; if (coordinates.size() < 3) { segmentized = coordinates; } else { segmentized = new ArrayList<Coordinate>(); for (int i = 0; i < coordinates.size() - 1; i += 2) { Coordinate p1 = coordinates.get(i); Coordinate p2 = coordinates.get(i + 1); Coordinate p3 = coordinates.get(i + 2); List<Coordinate> segments = circularSegmentize(p1, p2, p3); segmentized.addAll(segments.subList(0, segments.size() - 1)); } segmentized.add(coordinates.get(coordinates.size() - 1)); } // we can now process these coordinates based on the current precision model Coordinate array[] = segmentized.toArray(new Coordinate[segmentized.size()]); return geometryFactory.createLineString(array); }
return circularSegmentize( p1, p2, p3, center, radius, 32 );
@Override protected FeatureReader<SimpleFeatureType, SimpleFeature> getReaderInternal(Query query) throws IOException { File file = new File(store.dir, typeName + ".properties"); PropertyFeatureReader reader = new PropertyFeatureReader(store.getNamespaceURI(), file, getGeometryFactory(query)); Double tolerance = (Double) query.getHints().get(Hints.LINEARIZATION_TOLERANCE); if (tolerance != null) { reader.setWKTReader(new WKTReader2(tolerance)); } return reader; }
&& !stringValue.isEmpty()) { try { Geometry geometry = wktReader.read(stringValue); value = Converters.convert(geometry, attType.getType().getBinding()); } catch (ParseException e) {
WKTReader2 reader = new WKTReader2(); LiteShape shape = new LiteShape(reader.read(wkt), null, false); LOGGER.info("Created symbol from WKT " + wkt); return shape;
@Test public void verifyWKT() throws Exception { String WKT = "LINESTRING (60 380, 60 20, 200 400, 280 20, 360 400, 420 20, 500 400, 580 20, 620 400)"; WKTReader reader = new WKTReader2(); Geometry geometry = reader.read(WKT); assertNotNull(geometry); assertTrue(geometry instanceof LineString); }
/** * Reads a Well-Known Text representation of a {@link Geometry} from a {@link String}. * * @param wellKnownText * one or more <Geometry Tagged Text>strings (see the OpenGIS Simple Features * Specification) separated by whitespace * @return a <code>Geometry</code> specified by <code>wellKnownText</code> * @throws ParseException * if a parsing problem occurs */ public Geometry read(String wellKnownText) throws ParseException { StringReader reader = new StringReader(wellKnownText); try { return read(reader); } finally { reader.close(); } }
private void testRoundTrip(String wkt, String expectedWkt) throws ParseException { WKTReader2 reader = new WKTReader2(0.2); Geometry geometry = reader.read(wkt); WKTWriter2 writer = new WKTWriter2(); String wkt2 = writer.write(geometry); assertEquals(expectedWkt, wkt2); }
/** * Lazily initialize the WKTReader */ private WKTReader getWKTReader() { if (reader == null) { reader = new WKTReader2(); } return reader; }
/** no encode gml:id test */ public void testEncodeMultiPointNoGmlId() throws Exception { MultiPointEncoder encoder = new MultiPointEncoder(gtEncoder, "gml", GML.NAMESPACE, false); Geometry geometry = new WKTReader2().read("MULTIPOINT(0 0, 1 1)"); Document doc = encode(encoder, geometry, "points"); assertEquals( "0", xpath.evaluate("count(//gml:MultiPoint/gml:pointMember/gml:Point/@gml:id)", doc)); } }
@Test public void testCaseInsensitive() throws Exception { WKTReader reader = new WKTReader2(); assertNotNull(reader.read("POINT(1 2)")); assertNotNull(reader.read("Point(1 2)")); assertNotNull(reader.read("LINESTRING(0 2, 2 0, 8 6)")); assertNotNull(reader.read("LineString(0 2, 2 0, 8 6)")); }
public void testEncode3DPoint() throws Exception { PointEncoder encoder = new PointEncoder(gtEncoder, "gml", GML.NAMESPACE); Geometry geometry = new WKTReader2().read("POINT(0 0 50)"); Document doc = encode(encoder, geometry); // print(doc); assertEquals("0 0 50", xpath.evaluate("//gml:pos", doc)); }
@Test public void testParseMulticurve() throws Exception { WKTReader reader = new WKTReader2(); String WKT = "MULTICURVE EMPTY"; MultiLineString ml = (MultiLineString) reader.read(WKT); assertTrue(ml.isEmpty()); WKT = "MULTICURVE((0 0, 5 5),CIRCULARSTRING(4 0, 4 4, 8 4))"; ml = (MultiLineString) reader.read(WKT); assertEquals(2, ml.getNumGeometries()); assertTrue(ml.getGeometryN(0).getClass() == LineString.class); assertTrue(ml.getGeometryN(1) instanceof CircularString); WKT = "MULTICURVE((100 100, 120 120), COMPOUNDCURVE(CIRCULARSTRING(0 0, 2 0, 2 1, 2 3, 4 3),(4 3, 4 5, 1 4, 0 0)))"; ml = (MultiLineString) reader.read(WKT); assertEquals(2, ml.getNumGeometries()); assertTrue(ml.getGeometryN(0).getClass() == LineString.class); assertTrue(ml.getGeometryN(1) instanceof CompoundRing); }
/** No encode gml:id test */ public void testEncodeMultiPolygonNoGmlId() throws Exception { MultiPolygonEncoder encoder = new MultiPolygonEncoder(gtEncoder, "gml", GML.NAMESPACE, false); Geometry geometry = new WKTReader2() .read( "MULTIPOLYGON(((1 1,5 1,5 5,1 5,1 1),(2 2, 3 2, 3 3, 2 3,2 2)),((3 3,6 2,6 4,3 3)))"); Document doc = encode(encoder, geometry, "mpoly"); assertEquals( "0", xpath.evaluate( "count(/gml:MultiSurface/gml:surfaceMember/gml:Polygon/@gml:id)", doc)); } }
@Test public void multiPointWithInnerParens() throws Exception { String WKT = "MULTIPOINT ((111 -47), (110 -46.5))"; WKTReader reader = new WKTReader2(); Geometry geometry = reader.read(WKT); assertNotNull(geometry); assertTrue(geometry instanceof MultiPoint); MultiPoint mp = (MultiPoint) geometry; assertEquals(2, mp.getNumGeometries()); assertEquals(new Coordinate(111, -47), mp.getGeometryN(0).getCoordinate()); assertEquals(new Coordinate(110, -46.5), mp.getGeometryN(1).getCoordinate()); }
public void testEncode3DLine() throws Exception { LineStringEncoder encoder = new LineStringEncoder(gtEncoder, "gml", GML.NAMESPACE); Geometry geometry = new WKTReader2().read("LINESTRING(0 0 50, 120 0 100)"); Document doc = encode(encoder, geometry, "threed"); // print(doc); assertEquals("0 0 50 120 0 100", xpath.evaluate("//gml:posList", doc)); assertEquals("threed", xpath.evaluate("//gml:LineString/@gml:id", doc)); }