use of org.datanucleus.tests.annotations.Datastore in project tests by datanucleus.
the class PgGeometrySpatialTest method testCentroid.
@Datastore(POSTGRESQL)
public void testCentroid() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Point centroid = new Point("SRID=4326;POINT(50 50)");
Query query = pm.newQuery(SamplePolygon.class, "geom != null && Spatial.asText(Spatial.centroid(geom)) == 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("Spatial.centroid(geom)");
query.setUnique(true);
Geometry centroid_read = (Geometry) query.execute(new Long(getSamplePolygon(1).getId()));
assertEquals("Given point shoul be centroid of Polygon 1", centroid, centroid_read);
} finally {
tx.commit();
}
}
use of org.datanucleus.tests.annotations.Datastore in project tests by datanucleus.
the class PgGeometrySpatialTest method testIsEmpty.
@Datastore(POSTGRESQL)
public void testIsEmpty() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
LineString lineString = new LineString("SRID=4326;LINESTRING(25 25, 25 75)");
Query query = pm.newQuery(SampleLineString.class, "geom != null && Spatial.isEmpty(Spatial.intersection(geom, :linestring))");
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("Spatial.isEmpty(Spatial.intersection(geom, Spatial.geomFromText('LINESTRING(25 25, 25 75)', 4326))) AS 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 PgGeometrySpatialTest method testCrosses.
@Datastore(POSTGRESQL)
public void testCrosses() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
LineString lineString = new LineString("SRID=4326;LINESTRING(25 25,25 75)");
Query query = pm.newQuery(SampleLineString.class, "geom != null && Spatial.crosses(:lineString, geom)");
List list = (List) query.execute(lineString);
assertEquals("Wrong number of geometries which are crossed by a given linestring returned", 1, list.size());
assertTrue("LineString 1 should be in the list of geometries which are crossed by a given linestring", list.contains(getSampleLineString(1)));
query = pm.newQuery(SampleLineString.class, "id == :id");
query.setResult("Spatial.crosses(Spatial.geomFromText('LINESTRING(25 25,25 75)', 4326), geom)");
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", true, equals.booleanValue());
} finally {
tx.commit();
}
}
use of org.datanucleus.tests.annotations.Datastore in project tests by datanucleus.
the class PgGeometrySpatialTest method testUnion.
@Datastore(POSTGRESQL)
public void testUnion() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Point point = new Point("SRID=4326;POINT(50 50)");
MultiPoint union = new MultiPoint("SRID=4326;MULTIPOINT(10 10,50 50)");
Query query = pm.newQuery(SamplePoint.class, "geom != null && Spatial.asText(Spatial.union(geom, :point)) == Spatial.asText(:union)");
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("Spatial.union(geom, Spatial.geomFromText('POINT(50 50)', 4326))");
query.setUnique(true);
Geometry union_read = (Geometry) query.execute(new Long(getSamplePoint(1).getId()));
assertEquals("Returned union should be equal to the given multipoint", union, union_read);
} finally {
tx.commit();
}
}
use of org.datanucleus.tests.annotations.Datastore in project tests by datanucleus.
the class PgGeometrySpatialTest method testSymDifference.
@Datastore(POSTGRESQL)
public void testSymDifference() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Polygon polygon = new Polygon("SRID=4326;POLYGON((75 75, 125 75, 125 100, 75 100, 75 75))");
MultiPolygon symDifference = new MultiPolygon("SRID=4326;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 && Spatial.equals(Spatial.symDifference(geom, :polygon), :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("Spatial.symDifference(geom, 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()));
assertEquals("Returned symDifference should be equal to the given multipolygon", symDifference, symDifference_read);
} finally {
tx.commit();
}
}
Aggregations