@Override public Geometry fromString(String string) { final WKTReader reader = new WKTReader(); try { return reader.read( string ); } catch (ParseException e) { throw new RuntimeException( String.format( "Can't parse string %s as WKT", string ) ); } }
private static Geometry createJtsGeometry(String wkt) { try { return new WKTReader().read(wkt); } catch (ParseException e) { throw new RuntimeException(e); } }
private static Geometry fromText(String text) { try { return new WKTReader().read(text); } catch (ParseException e) { throw new RuntimeException(e); } }
/** * Get or create a geometry value for the given geometry. * * @param s the WKT representation of the geometry * @return the value */ public static ValueGeometry get(String s) { try { Geometry g = new WKTReader().read(s); return get(g); } catch (ParseException ex) { throw DbException.convert(ex); } }
@Override public Polygon getTestPolygon() { WKTReader reader = new WKTReader(); try { Polygon polygon = (Polygon) reader.read( "POLYGON((0 0, 50 0, 90 90, 100 0, 0 0))" ); polygon.setSRID( getTestSrid() ); return polygon; } catch (ParseException e) { throw new RuntimeException( e ); } }
/** * Return a testsuite-suite polygon (filter, ...) * * @return a testsuite-suite polygon */ public Polygon getTestPolygon() { WKTReader reader = new WKTReader(); try { Polygon polygon = (Polygon) reader.read( TEST_POLYGON_WKT ); polygon.setSRID( getTestSrid() ); return polygon; } catch (ParseException e) { throw new RuntimeException( e ); } }
/** * Return a testsuite-suite point (filter, ...) * * @return a testsuite-suite point */ public Point getTestPoint() { WKTReader reader = new WKTReader(); try { Point point = (Point) reader.read( TEST_POINT_WKT ); point.setSRID( getTestSrid() ); return point; } catch (ParseException e) { throw new RuntimeException( e ); } }
/** * Get or create a geometry value for the given geometry. * * @param s the WKT representation of the geometry * @param srid the srid of the object * @return the value */ public static ValueGeometry get(String s, int srid) { try { GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(), srid); Geometry g = new WKTReader(geometryFactory).read(s); return get(g); } catch (ParseException ex) { throw DbException.convert(ex); } }
WKTReader reader = new WKTReader(); sfb.set("the_geom", reader.read("POINT (0.002 0.0008)")); sfb.set("FID", "023");
WKTReader reader = new WKTReader(); sfb.set("the_geom", reader.read("POINT (0.002 0.0008)")); sfb.set("FID", "023");
public Object getValue() { WKTReader reader = new WKTReader(); String wkt = text.getText(); if (wkt.length() == 0) { return null; } try { return reader.read(wkt); } catch (Throwable eek) { return null; } }
public static Geometry geomFromWKT(String wkt) { WKTReader wktreader = new WKTReader(); try { return wktreader.read(wkt); } catch (Exception e) { throw new IllegalArgumentException("bad wkt"); } }
b.add(new WKTReader().read("POINT(1 1)")); SimpleFeature f = b.buildFeature(null); f.getUserData().put("foo", "bar");
@Test public void testGetFeaturesFeatureSource() throws Exception { // check the schemas in feature source and feature collection SimpleFeatureSource fs = rts.getFeatureSource(RENAMED); assertEquals(primitive, fs.getSchema()); SimpleFeatureCollection fc = fs.getFeatures(); assertEquals(primitive, fc.getSchema()); assertTrue(fc.size() > 0); // make sure the feature schema is good as well FeatureIterator<SimpleFeature> it = fc.features(); SimpleFeature sf = it.next(); it.close(); assertEquals(primitive, sf.getFeatureType()); // check the feature ids have been renamed as well assertTrue( "Feature id has not been renamed, it's still " + sf.getID(), sf.getID().startsWith(RENAMED)); // check mappings occurred assertEquals("description-f001", sf.getAttribute("description")); assertTrue( new WKTReader() .read("MULTIPOINT(39.73245 2.00342)") .equalsExact((Geometry) sf.getAttribute("pointProperty"))); assertEquals(Long.valueOf(155), sf.getAttribute("intProperty")); assertNull(sf.getAttribute("newProperty")); }
@Override protected void setUp() throws Exception { super.setUp(); schema = DataUtilities.createType( "buildings", "the_geom:Geometry,name:String,ADDRESS:String"); feature = SimpleFeatureBuilder.build( schema, new Object[] {null, "ABC", "Random Road, 12"}, "building.1"); wkt = new WKTReader(); }
public void testFindCentralPoint() throws Exception { // self crossing polygon Polygon g = (Polygon) new WKTReader().read("POLYGON ((0 0, 0 10, 10 0, 10 10, 0 0))"); assertNotNull(RendererUtilities.getPolygonCentroid(g)); } }
public void testLineStringToCurve() throws Exception { Geometry ls = new WKTReader().read("LINESTRING(0 0, 10 10)"); Converter converter = getConverter(ls, CurvedGeometry.class); CurvedGeometry curve = converter.convert(ls, CurvedGeometry.class); assertTrue(curve instanceof CompoundCurve); CompoundCurve cc = (CompoundCurve) curve; assertEquals(1, cc.getComponents().size()); assertEquals(ls, cc.getComponents().get(0)); }
public void testEncodePointWithDecimals() throws Exception { Geometry geometry = new WKTReader().read("POINT(1.234 5.678)"); Document dom = encode(geometry, GML.geometryMember); // print(dom); XpathEngine xpath = XMLUnit.newXpathEngine(); assertEquals("1.23 5.68", xpath.evaluate("/gml:geometryMember/gml:Point/gml:pos", dom)); } }
@Before public void setUp() throws Exception { // System.setProperty("org.geotools.test.interactive", "true"); clipper = new GeometryClipper(new Envelope(0, 10, 0, 10)); wkt = new WKTReader(); boundsPoly = wkt.read("POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))"); }
public void testParse3D() throws Exception { Parser p = new Parser(new GMLConfiguration()); Object g = p.parse(GML3ParsingTest.class.getResourceAsStream("polygon3d.xml")); assertThat(g, instanceOf(Polygon.class)); Polygon polygon = (Polygon) g; assertEquals(3, CoordinateSequences.coordinateDimension(polygon)); Geometry expected = new WKTReader() .read( "POLYGON((94000 471000 10, 94001 471000 11, 94001 471001 12, 94000 471001 13, 94000 471000 10))"); assertTrue(CoordinateSequences.equalsND(expected, polygon)); }