use of org.datanucleus.tests.annotations.Datastore in project tests by datanucleus.
the class PgGeometrySpatialTest method testIntersection.
@Datastore(POSTGRESQL)
public void testIntersection() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
LineString lineString = new LineString("SRID=4326;LINESTRING(25 25, 25 75)");
Point intersection = new Point("SRID=4326;POINT(25 50)");
Query query = pm.newQuery(SampleLineString.class, "geom != null && Spatial.asText(Spatial.intersection(geom, :lineString)) == Spatial.asText(:intersection)");
List list = (List) query.execute(lineString, intersection);
assertEquals("Wrong number of geometries which intersect a given linestring at a given point returned", 1, list.size());
assertTrue("LineSting 1 should be in the list of geometries which intersect a given linestring at a given point", list.contains(getSampleLineString(1)));
query = pm.newQuery(SampleLineString.class, "id == :id");
query.setResult("Spatial.intersection(geom, Spatial.geomFromText('LINESTRING(25 25, 25 75)', 4326))");
query.setUnique(true);
Geometry intersection_read = (Geometry) query.execute(new Long(getSampleLineString(1).getId()));
assertEquals("Returned intersection should be equal to the given point", intersection, intersection_read);
} finally {
tx.commit();
}
}
use of org.datanucleus.tests.annotations.Datastore in project tests by datanucleus.
the class PgGeometrySpatialTest method testBboxTest.
@Datastore(POSTGRESQL)
public void testBboxTest() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Point point = new Point("SRID=4326;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 PgGeometrySpatialTest method testIsRing.
@Datastore(POSTGRESQL)
public void testIsRing() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Query query = pm.newQuery(SampleLineString.class, "geom != null && Spatial.isRing(geom)");
List list = (List) query.execute();
assertEquals("Wrong number of rings returned", 0, list.size());
query = pm.newQuery(SampleLineString.class, "id == :id");
query.setResult("Spatial.isRing(geom)");
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 PgGeometrySpatialTest method testBoundary.
@Datastore(POSTGRESQL)
public void testBoundary() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
LineString boundary = new LineString("SRID=4326;LINESTRING(75 75,100 75,100 100,75 75)");
Query query = pm.newQuery(SamplePolygon.class, "geom != null && Spatial.equals(Spatial.boundary(geom), :boundary)");
List list = (List) query.execute(boundary);
assertEquals("Wrong number of geometries with a given boundary returned", 1, list.size());
assertTrue("Polygon 2 should be in the list of geometries with a given boundary", list.contains(getSamplePolygon(2)));
query = pm.newQuery(SamplePolygon.class, "id == :id");
query.setResult("Spatial.boundary(geom)");
query.setUnique(true);
Geometry boundary_read = (Geometry) query.execute(new Long(getSamplePolygon(2).getId()));
assertEquals("Boundary of Polygon 2 should be equal to a given boundary", boundary, boundary_read);
} finally {
tx.commit();
}
}
use of org.datanucleus.tests.annotations.Datastore in project tests by datanucleus.
the class JtsGeometrySpatialTest method testBoundary.
@Datastore(POSTGRESQL)
public void testBoundary() throws SQLException, ParseException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
LineString boundary = (LineString) wktReader.read("LINESTRING(75 75,100 75,100 100,75 75)");
Query query = pm.newQuery(SamplePolygon.class, "geom != null && geom.getBoundary().equals(:boundary)");
List list = (List) query.execute(boundary);
assertEquals("Wrong number of geometries with a given boundary returned", 1, list.size());
assertTrue("Polygon 2 should be in the list of geometries with a given boundary", list.contains(getSamplePolygon(2)));
query = pm.newQuery(SamplePolygon.class, "id == :id");
query.setResult("geom.getBoundary()");
query.setUnique(true);
Geometry boundary_read = (Geometry) query.execute(new Long(getSamplePolygon(2).getId()));
boundary.normalize();
boundary_read.normalize();
assertTrue("Boundary of Polygon 2 should be equal to a given boundary", boundary_read.equalsExact(boundary));
} finally {
tx.commit();
}
}
Aggregations