use of org.datanucleus.tests.annotations.Datastore in project tests by datanucleus.
the class PgGeometrySpatialTest method testGeographicMethods.
@Datastore(POSTGRESQL)
public void testGeographicMethods() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
String strGeom = "SRID=4326;POINT(10 10)";
Query query = pm.newQuery(SamplePoint.class, "geom != null && Spatial.distance(Spatial.geogFromText(:strGeom), Spatial.geogFromWKB(Spatial.asBinary(geom))) == 0");
List list = (List) query.execute(strGeom);
assertEquals("Wrong number of g" + "eometries with a given wkb returned", 1, list.size());
assertTrue("Point 1 should be in the list of geometries with a given wkb", list.contains(getSamplePoint(1)));
} finally {
tx.commit();
}
}
use of org.datanucleus.tests.annotations.Datastore in project tests by datanucleus.
the class JtsGeometrySpatialTest method testBboxTest.
@Datastore(POSTGRESQL)
public void testBboxTest() throws SQLException, ParseException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Point point = (Point) wktReader.read("POINT(90 90)");
Query query = pm.newQuery(SamplePolygon.class, "geom != null && Spatial.bboxTest(:point, geom)");
List list = (List) query.execute(point);
assertEquals("Wrong number of geometries which pass the bbox test with a given point returned", 1, list.size());
assertTrue("Polygon 2 should be in the list of geometries which pass the bbox test with a given point", list.contains(getSamplePolygon(2)));
query = pm.newQuery(SamplePolygon.class, "id == :id");
query.setResult("Spatial.bboxTest(Spatial.geomFromText('POINT(90 90)', 4326), geom)");
query.setResultClass(Boolean.class);
query.setUnique(true);
Boolean equals = (Boolean) query.execute(new Long(getSamplePolygon(2).getId()));
assertEquals("Polygon 2 should pass bbox test with the given point", true, equals.booleanValue());
} finally {
tx.commit();
}
}
use of org.datanucleus.tests.annotations.Datastore in project tests by datanucleus.
the class JtsGeometrySpatialTest method testPointOnSurfaceMethod.
@Datastore(POSTGRESQL)
public void testPointOnSurfaceMethod() throws SQLException, ParseException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Query query = pm.newQuery(SamplePolygon.class, "geom != null && Spatial.pointOnSurface(geom) != null");
List list = (List) query.execute();
assertEquals("Wrong number of geometries with a point on the surface returned", 2, list.size());
assertTrue("Polygon 1 should be in the list of geometries with a point on the surface", list.contains(getSamplePolygon(1)));
assertTrue("Polygon 2 should be in the list of geometries with a point on the surface", list.contains(getSamplePolygon(2)));
query = pm.newQuery(SamplePolygon.class, "id == :id");
query.setResult("Spatial.pointOnSurface(geom)");
query.setUnique(true);
Geometry pointOnSurface = (Geometry) query.execute(new Long(getSamplePolygon(1).getId()));
assertNotNull("Polygon 1 should have a point on the surface", pointOnSurface);
assertEquals("Polygon 1 should have a point on the surface", "POINT", pointOnSurface.getGeometryType().toUpperCase());
} finally {
tx.commit();
}
}
use of org.datanucleus.tests.annotations.Datastore in project tests by datanucleus.
the class JtsGeometrySpatialTest method testIsRing.
@Datastore(POSTGRESQL)
public void testIsRing() throws SQLException, ParseException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Query query = pm.newQuery(SampleLineString.class, "geom != null && geom.isRing()");
List list = (List) query.execute();
assertEquals("Wrong number of rings returned", 0, list.size());
query = pm.newQuery(SampleLineString.class, "id == :id");
query.setResult("geom.isRing()");
query.setResultClass(Boolean.class);
query.setUnique(true);
Boolean isRing = (Boolean) query.execute(new Long(getSampleLineString(3).getId()));
assertEquals("LineString 3 should not be a ring", false, isRing.booleanValue());
} finally {
tx.commit();
}
}
use of org.datanucleus.tests.annotations.Datastore in project tests by datanucleus.
the class JtsGeometrySpatialTest method testCentroid.
@Datastore(POSTGRESQL)
public void testCentroid() throws SQLException, ParseException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Point centroid = (Point) wktReader.read("POINT(50 50)");
Query query = pm.newQuery(SamplePolygon.class, "geom != null && geom.getCentroid().toText() == Spatial.asText(:centroid)");
List list = (List) query.execute(centroid);
assertEquals("Wrong number of geometries with a given centroid returned", 1, list.size());
assertTrue("Polygon 1 should be in the list of geometries with a given centroid", list.contains(getSamplePolygon(1)));
query = pm.newQuery(SamplePolygon.class, "id == :id");
query.setResult("geom.getCentroid()");
query.setUnique(true);
Geometry centroid_read = (Geometry) query.execute(new Long(getSamplePolygon(1).getId()));
assertTrue("Given point shoul be centroid of Polygon 1", centroid_read.equalsExact(centroid));
} finally {
tx.commit();
}
}
Aggregations