@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()); }
public void geomfromwkt(String pckg) throws SQLException { WKTWriter writer = new WKTWriter(); String wkt = writer.write( expectationsFactory.getTestPolygon() ); Map<Integer, Geometry> dbexpected = hanaExpectationsFactory.getGeomFromWKT( wkt ); String hql = format( "SELECT 1, cast(geomfromwkt(:param) as %s) FROM org.hibernate.spatial.integration.%s.GeomEntity g", getGeometryTypeFromPackage( pckg ), pckg ); Map<String, Object> params = createQueryParams( "param", wkt ); retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg ); }
public void geomfromewkb(String pckg) throws SQLException { WKBWriter writer = new WKBWriter( 2, true ); byte[] ewkb = writer.write( expectationsFactory.getTestPolygon() ); Map<Integer, Geometry> dbexpected = hanaExpectationsFactory.getGeomFromEWKB( ewkb ); String hql = format( "SELECT 1, cast(geomfromewkb(:param) as %s) FROM org.hibernate.spatial.integration.%s.GeomEntity g", getGeometryTypeFromPackage( pckg ), pckg ); Map<String, Object> params = createQueryParams( "param", ewkb ); retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg ); }
@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()); }
public void geomfromewkt(String pckg) throws SQLException { WKTWriter writer = new WKTWriter(); String ewkt = "SRID=" + expectationsFactory.getTestSrid() + ";" + writer.write( expectationsFactory.getTestPolygon() ); Map<Integer, Geometry> dbexpected = hanaExpectationsFactory.getGeomFromEWKT( ewkt ); String hql = format( "SELECT 1, cast(geomfromewkt(:param) as %s) FROM org.hibernate.spatial.integration.%s.GeomEntity g", getGeometryTypeFromPackage( pckg ), pckg ); Map<String, Object> params = createQueryParams( "param", ewkt ); retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg ); }
public void geomfromwkb(String pckg) throws SQLException { WKBWriter writer = new WKBWriter( 2, false ); byte[] wkb = writer.write( expectationsFactory.getTestPolygon() ); Map<Integer, Geometry> dbexpected = hanaExpectationsFactory.getGeomFromWKB( wkb ); String hql = format( "SELECT 1, cast(geomfromwkb(:param) as %s) FROM org.hibernate.spatial.integration.%s.GeomEntity g", getGeometryTypeFromPackage( pckg ), pckg ); Map<String, Object> params = createQueryParams( "param", wkb ); retrieveHQLResultsAndCompare( dbexpected, hql, params, pckg ); }
/** * 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); } }
/** * 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); } }
/** * 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 ); } }
@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")); }