use of org.datanucleus.tests.annotations.Datastore in project tests by datanucleus.
the class PgGeometrySpatialTest method testTransform.
@Datastore(POSTGRESQL)
public void testTransform() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Point geom = new Point("SRID=4326;POINT(10 10)");
Query query = pm.newQuery(SamplePoint.class, "geom != null && Spatial.equals(geom, Spatial.transform(Spatial.geomFromWKB(Spatial.asBinary(:geom), Spatial.srid(:geom)), 4326))");
List list = (List) query.execute(geom);
assertEquals("Wrong number of geometries 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 PgGeometrySpatialTest method testDistance.
@Datastore(POSTGRESQL)
public void testDistance() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Point point = new Point("SRID=4326;POINT(0 10)");
Double distance = new Double(10.0);
Query query = pm.newQuery(SamplePoint.class, "geom != null && Spatial.distance(geom, :point) == :distance");
List list = (List) query.execute(point, distance);
assertEquals("Wrong number of geometries with a distance of " + distance + " to a given point returned", 1, list.size());
assertTrue("Point 1 should be in the list of geometries with a distance of " + distance + " to a given point", list.contains(getSamplePoint(1)));
query = pm.newQuery(SamplePoint.class, "id == :id");
query.setResult("Spatial.distance(geom, Spatial.geomFromText('POINT(0 10)', 4326))");
query.setResultClass(Double.class);
query.setUnique(true);
Double distance_read = (Double) query.execute(new Long(getSamplePoint(1).getId()));
assertEquals("Point 1 should be in the given distance from the given point", distance, distance_read);
} finally {
tx.commit();
}
}
use of org.datanucleus.tests.annotations.Datastore in project tests by datanucleus.
the class PgGeometrySpatialTest method testRelate.
@Datastore(POSTGRESQL)
public void testRelate() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
LineString lineString = new LineString("SRID=4326;LINESTRING(25 25,25 75)");
// crosses
String pattern = "T*T******";
Query query = pm.newQuery(SampleLineString.class, "geom != null && Spatial.relate(geom, :lineString, :pattern)");
List list = (List) query.execute(lineString, pattern);
assertEquals("Wrong number of geometries which are related to a given linestring returned (crosses)", 1, list.size());
assertTrue("LineString 1 should be in the list of geometries which are related to a given linestring (crosses)", list.contains(getSampleLineString(1)));
query = pm.newQuery(SampleLineString.class, "id == :id");
query.setResult("Spatial.relate(geom, Spatial.geomFromText('LINESTRING(25 25,25 75)', 4326), 'T*T******')");
query.setResultClass(Boolean.class);
query.setUnique(true);
Boolean equals = (Boolean) query.execute(new Long(getSampleLineString(1).getId()));
assertEquals("LineString 1 should be crossed by the given linestring (relate mask T*T******)", true, equals.booleanValue());
} finally {
tx.commit();
}
}
use of org.datanucleus.tests.annotations.Datastore in project tests by datanucleus.
the class PgGeometrySpatialTest method testConvexHull.
@Datastore(POSTGRESQL)
public void testConvexHull() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Polygon convexHull = new Polygon("SRID=4326;POLYGON((110 10,120 25,110 45,100 25,110 10))");
Query query = pm.newQuery(SampleLineString.class, "geom != null && Spatial.equals(Spatial.convexHull(geom), :convexHull)");
List list = (List) query.execute(convexHull);
assertEquals("Wrong number of geometries with a given convex hull returned", 1, list.size());
assertTrue("LineSting 3 should be in the list of geometries with a given convex hull", list.contains(getSampleLineString(3)));
query = pm.newQuery(SampleLineString.class, "id == :id");
query.setResult("Spatial.convexHull(geom)");
query.setUnique(true);
Geometry convexHull_read = (Geometry) query.execute(new Long(getSampleLineString(3).getId()));
assertEquals("Returned convex hull should be a polygon", "POLYGON", convexHull.getTypeString());
assertEquals("Returned convex hull should have the given srid", 4326, convexHull.getSrid());
assertTrue("First point of returned convex hull should be equal to given point", convexHull.getFirstPoint().equals(convexHull_read.getFirstPoint()));
} finally {
tx.commit();
}
}
use of org.datanucleus.tests.annotations.Datastore in project tests by datanucleus.
the class PgGeometrySpatialTest method testPointOnSurfaceMethod.
@Datastore(POSTGRESQL)
public void testPointOnSurfaceMethod() throws SQLException {
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.getTypeString());
} finally {
tx.commit();
}
}
Aggregations