use of org.datanucleus.tests.annotations.Datastore in project tests by datanucleus.
the class JtsGeometrySpatialTest method testIntersection.
@Datastore(POSTGRESQL)
public void testIntersection() throws SQLException, ParseException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
LineString lineString = (LineString) wktReader.read("LINESTRING(25 25, 25 75)");
Point intersection = (Point) wktReader.read("POINT(25 50)");
Query query = pm.newQuery(SampleLineString.class, "geom != null && geom.intersection(:lineString).toText() == 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("geom.intersection(Spatial.geomFromText('LINESTRING(25 25, 25 75)', 4326))");
query.setUnique(true);
Geometry intersection_read = (Geometry) query.execute(new Long(getSampleLineString(1).getId()));
assertTrue("Returned intersection should be equal to the given point", intersection_read.equalsExact(intersection));
} finally {
tx.commit();
}
}
use of org.datanucleus.tests.annotations.Datastore in project tests by datanucleus.
the class JtsGeometrySpatialTest method testUnion.
@Datastore(POSTGRESQL)
public void testUnion() throws SQLException, ParseException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Point point = (Point) wktReader.read("POINT(50 50)");
MultiPoint union = (MultiPoint) wktReader.read("MULTIPOINT(10 10,50 50)");
Query query = pm.newQuery(SamplePoint.class, "geom != null && geom.union(:point).toText() == :union.toText()");
List list = (List) query.execute(point, union);
assertEquals("Wrong number of geometries whose union with a given point is equal to a given multipoint returned", 1, list.size());
assertTrue("Point 1 should be in the list of geometries whose union with a given point is equal to a given multipoint", list.contains(getSamplePoint(1)));
query = pm.newQuery(SamplePoint.class, "id == :id");
query.setResult("geom.union(Spatial.geomFromText('POINT(50 50)', 4326))");
query.setUnique(true);
Geometry union_read = (Geometry) query.execute(new Long(getSamplePoint(1).getId()));
union.normalize();
union_read.normalize();
assertTrue("Returned union should be equal to the given multipoint", union_read.equalsExact(union));
} finally {
tx.commit();
}
}
use of org.datanucleus.tests.annotations.Datastore in project tests by datanucleus.
the class JtsGeometrySpatialTest method testIsSimple.
@Datastore(POSTGRESQL)
public void testIsSimple() throws SQLException, ParseException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Query query = pm.newQuery(SampleLineString.class, "geom != null && geom.isSimple()");
List list = (List) query.execute();
assertEquals("Wrong number of simple geometries returned", 2, list.size());
assertTrue("LineString 1 should be in the list of simple geometries", list.contains(getSampleLineString(1)));
assertTrue("LineString 2 should be in the list of simple geometries", list.contains(getSampleLineString(2)));
query = pm.newQuery(SampleLineString.class, "id == :id");
query.setResult("geom.isSimple()");
query.setResultClass(Boolean.class);
query.setUnique(true);
Boolean isSimple = (Boolean) query.execute(new Long(getSampleLineString(2).getId()));
assertEquals("LineString 2 is simple", true, isSimple.booleanValue());
} finally {
tx.commit();
}
}
Aggregations