@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); } }
sfb.set("the_geom", reader.read("POINT (0.002 0.0008)")); sfb.set("FID", "023"); sfb.set("NAME", "Old oak");
sfb.set("the_geom", reader.read("POINT (0.002 0.0008)")); sfb.set("FID", "023"); sfb.set("NAME", "Old oak");
@Test public void testLeaveNative() throws Exception { FeatureTypeInfo fti = getCatalog().getFeatureTypeByName(MockData.LINES.getLocalPart()); assertEquals("EPSG:3004", fti.getSRS()); assertEquals(ProjectionPolicy.NONE, fti.getProjectionPolicy()); FeatureCollection fc = fti.getFeatureSource(null, null).getFeatures(); assertEquals(CRS.decode("EPSG:32615"), fc.getSchema().getCoordinateReferenceSystem()); FeatureIterator fi = fc.features(); Feature f = fi.next(); // test that the geometry was left in tact Geometry g = (Geometry) f.getDefaultGeometryProperty().getValue(); assertTrue(g.equalsExact(WKT.read("LINESTRING(500125 500025,500175 500075)"))); fi.close(); assertEquals(CRS.decode("EPSG:32615"), f.getType().getCoordinateReferenceSystem()); }
@Test public void testReproject() throws Exception { FeatureTypeInfo fti = getCatalog().getFeatureTypeByName(MockData.POLYGONS.getLocalPart()); assertEquals("EPSG:4326", fti.getSRS()); assertEquals(ProjectionPolicy.REPROJECT_TO_DECLARED, fti.getProjectionPolicy()); FeatureCollection fc = fti.getFeatureSource(null, null).getFeatures(); assertEquals(CRS.decode("EPSG:4326"), fc.getSchema().getCoordinateReferenceSystem()); FeatureIterator fi = fc.features(); Feature f = fi.next(); // test that geometry was actually reprojected Geometry g = (Geometry) f.getDefaultGeometryProperty().getValue(); assertFalse( g.equalsExact( WKT.read( "POLYGON((500225 500025,500225 500075,500275 500050,500275 500025,500225 500025))"))); fi.close(); assertEquals(CRS.decode("EPSG:4326"), f.getType().getCoordinateReferenceSystem()); }
b.add(new WKTReader().read("POINT(1 1)")); SimpleFeature f = b.buildFeature(null); f.getUserData().put("foo", "bar");
@Test public void testWithRename() throws Exception { FeatureTypeInfo fti = getCatalog().getFeatureTypeByName("MyPoints"); assertEquals("EPSG:4326", fti.getSRS()); assertEquals(ProjectionPolicy.REPROJECT_TO_DECLARED, fti.getProjectionPolicy()); FeatureCollection fc = fti.getFeatureSource(null, null).getFeatures(); assertEquals(CRS.decode("EPSG:4326"), fc.getSchema().getCoordinateReferenceSystem()); FeatureIterator fi = fc.features(); Feature f = fi.next(); // test that geometry was reprojected Geometry g = (Geometry) f.getDefaultGeometryProperty().getValue(); assertFalse(g.equalsExact(WKT.read("POINT(500050 500050)"))); fi.close(); assertEquals(CRS.decode("EPSG:4326"), f.getType().getCoordinateReferenceSystem()); }
@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")); }
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)); }
@Test public void testTouchLine() throws Exception { LineString ls = (LineString) wkt.read("LINESTRING(0 0, 0 10)"); LineString clipped = (LineString) clipper.clip(ls, false); assertTrue(clipped.equalsExact(ls)); showResult("Touch border", ls, clipped); }
@Test public void testFullyOutsideCircle() throws Exception { Point p = (Point) wkt.read("POINT(5 5)"); LineString ls = ((Polygon) p.buffer(10)).getExteriorRing(); Geometry clipped = clipper.clip(ls, false); assertNull(clipped); showResult("Circle around", ls, clipped); }
@Test public void testCrossingCircle() throws Exception { Point p = (Point) wkt.read("POINT(5 5)"); LineString ls = ((Polygon) p.buffer(6)).getExteriorRing(); MultiLineString clipped = (MultiLineString) clipper.clip(ls, false); assertEquals(4, clipped.getNumGeometries()); showResult("Circle around", ls, clipped); }