use of org.datanucleus.tests.annotations.Datastore in project tests by datanucleus.
the class JtsGeometrySpatialTest method testConvexHull.
@Datastore(POSTGRESQL)
public void testConvexHull() throws SQLException, ParseException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Polygon convexHull = (Polygon) wktReader.read("POLYGON((110 10,120 25,110 45,100 25,110 10))");
Query query = pm.newQuery(SampleLineString.class, "geom != null && geom.convexHull().equals(: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("geom.convexHull()");
query.setUnique(true);
Geometry convexHull_read = (Geometry) query.execute(new Long(getSampleLineString(3).getId()));
convexHull.normalize();
convexHull_read.normalize();
assertTrue("Returned convex hull should be equal to the given polygon", convexHull_read.equalsExact(convexHull));
} finally {
tx.commit();
}
}
use of org.datanucleus.tests.annotations.Datastore in project tests by datanucleus.
the class JtsGeometrySpatialTest method testIsEmpty.
@Datastore(POSTGRESQL)
public void testIsEmpty() throws SQLException, ParseException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
LineString lineString = (LineString) wktReader.read("LINESTRING(25 25, 25 75)");
Query query = pm.newQuery(SampleLineString.class, "geom != null && geom.intersection(:linestring).isEmpty()");
List list = (List) query.execute(lineString);
assertEquals("Wrong number of geometries that do not intersect with a given linestring returned", 2, list.size());
assertTrue("LineString 2 should be in the list of geometries that do not intersect with a given linestring", list.contains(getSampleLineString(2)));
assertTrue("LineString 3 should be in the list of geometries that do not intersect with a given linestring", list.contains(getSampleLineString(3)));
query = pm.newQuery(SampleLineString.class, "geom != null");
query.setResult("geom.intersection(Spatial.geomFromText('LINESTRING(25 25, 25 75)', 4326)).isEmpty()");
query.setResultClass(Boolean.class);
list = (List) query.execute();
assertEquals("Wrong number of geometries returned", 3, list.size());
assertEquals("The intersection of LineString 1 with a given linestring should not be empty", false, ((Boolean) list.get(0)).booleanValue());
assertEquals("The intersection of LineString 2 with a given linestring should be empty", true, ((Boolean) list.get(1)).booleanValue());
assertEquals("The intersection of LineString 3 with a given linestring should be empty", true, ((Boolean) list.get(2)).booleanValue());
} finally {
tx.commit();
}
}
use of org.datanucleus.tests.annotations.Datastore in project tests by datanucleus.
the class JtsGeometrySpatialTest method testRelate.
@Datastore(POSTGRESQL)
public void testRelate() throws SQLException, ParseException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
LineString lineString = (LineString) wktReader.read("LINESTRING(25 25,25 75)");
// crosses
String pattern = "T*T******";
Query query = pm.newQuery(SampleLineString.class, "geom != null && geom.relate(: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("geom.relate(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 JtsGeometrySpatialTest method testSymDifference.
@Datastore(POSTGRESQL)
public void testSymDifference() throws SQLException, ParseException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Polygon polygon = (Polygon) wktReader.read("POLYGON((75 75, 125 75, 125 100, 75 100, 75 75))");
MultiPolygon symDifference = (MultiPolygon) wktReader.read("MULTIPOLYGON(((100 75,100 100,125 100,125 75,100 75)),((100 100,75 75,75 100,100 100)))");
Query query = pm.newQuery(SamplePolygon.class, "geom != null && geom.symDifference(:polygon).equals(:symDifference)");
List list = (List) query.execute(polygon, symDifference);
assertEquals("Wrong number of geometries whose symDifference to a given polygon is equal to a given multipolygon returned", 1, list.size());
assertTrue("Polygon 2 should be in the list of geometries whose symDifference to a given polygon is equal to a given multipolygon", list.contains(getSamplePolygon(2)));
query = pm.newQuery(SamplePolygon.class, "id == :id");
query.setResult("geom.symDifference(Spatial.geomFromText('POLYGON((75 75, 125 75, 125 100, 75 100, 75 75))', 4326))");
query.setUnique(true);
Geometry symDifference_read = (Geometry) query.execute(new Long(getSamplePolygon(2).getId()));
symDifference.normalize();
symDifference_read.normalize();
assertTrue("Returned symDifference should be equal to the given multipolygon", symDifference_read.equalsExact(symDifference));
} finally {
tx.commit();
}
}
use of org.datanucleus.tests.annotations.Datastore in project tests by datanucleus.
the class PgGeometrySpatialTest method testBuffer.
@Datastore(POSTGRESQL)
public void testBuffer() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Point point = new Point("SRID=4326;POINT(0 0)");
Query query = pm.newQuery(SamplePoint.class, "geom != null && Spatial.within(geom, Spatial.buffer(:point, 20))");
List list = (List) query.execute(point);
assertEquals("Wrong number of geometries which are within the buffer of a given point returned", 1, list.size());
assertTrue("Point 1 should be in the list of geometries which are within the buffer of a given point", list.contains(getSamplePoint(1)));
query = pm.newQuery(SamplePoint.class, "id == :id");
query.setResult("Spatial.buffer(geom, 20)");
query.setUnique(true);
Geometry buffer = (Geometry) query.execute(new Long(getSamplePoint(1).getId()));
assertEquals("Returned buffer should be a polygon", "POLYGON", buffer.getTypeString());
assertEquals("Returned buffer should have the given srid", 4326, buffer.getSrid());
assertTrue("First point of returned buffer should have to be in a given distance from Point 1", buffer.getFirstPoint().distance(point) >= 20.0);
} finally {
tx.commit();
}
}
Aggregations