use of org.datanucleus.tests.annotations.Datastore in project tests by datanucleus.
the class JtsGeometrySpatialTest method testCrosses.
@Datastore(POSTGRESQL)
public void testCrosses() 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 && :lineString.crosses(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 JtsGeometrySpatialTest method testDifference.
@Datastore(POSTGRESQL)
public void testDifference() throws SQLException, ParseException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Polygon polygon = (Polygon) wktReader.read("POLYGON((75 75,100 75,100 80,80 80,75 75))");
Polygon difference = (Polygon) wktReader.read("POLYGON((80 80,100 100,100 80,80 80))");
Query query = pm.newQuery(SamplePolygon.class, "geom != null && geom.difference(:polygon).equals(:difference)");
List list = (List) query.execute(polygon, difference);
assertEquals("Wrong number of geometries whose difference from a given polygon is equal to a given polygon returned", 1, list.size());
assertTrue("Polygon 2 should be in the list of geometries whose difference from a given polygon is equal to a given polygon", list.contains(getSamplePolygon(2)));
query = pm.newQuery(SamplePolygon.class, "id == :id");
query.setResult("geom.difference(Spatial.geomFromText('POLYGON((75 75,100 75,100 80,80 80,75 75))', 4326))");
query.setUnique(true);
Geometry difference_read = (Geometry) query.execute(new Long(getSamplePolygon(2).getId()));
difference.normalize();
difference_read.normalize();
assertTrue("Returned difference should be equal to the given polygon", difference_read.equalsExact(difference));
} finally {
tx.commit();
}
}
use of org.datanucleus.tests.annotations.Datastore in project tests by datanucleus.
the class JtsGeometrySpatialTest method testBuffer.
@Datastore(POSTGRESQL)
public void testBuffer() throws SQLException, ParseException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Point point = (Point) wktReader.read("POINT(0 0)");
Query query = pm.newQuery(SamplePoint.class, "geom != null && geom.within(:point.buffer(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("geom.buffer(20)");
query.setUnique(true);
Geometry buffer = (Geometry) query.execute(new Long(getSamplePoint(1).getId()));
assertEquals("Returned buffer should be a polygon", "POLYGON", buffer.getGeometryType().toUpperCase());
assertEquals("Returned buffer should have the given srid", 4326, buffer.getSRID());
assertTrue("Given point should be within the returned buffer", point.within(buffer));
} finally {
tx.commit();
}
}
use of org.datanucleus.tests.annotations.Datastore in project tests by datanucleus.
the class PgGeometrySpatialTest method testIsSimple.
@Datastore(POSTGRESQL)
public void testIsSimple() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Query query = pm.newQuery(SampleLineString.class, "geom != null && Spatial.isSimple(geom)");
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("Spatial.isSimple(geom)");
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();
}
}
use of org.datanucleus.tests.annotations.Datastore in project tests by datanucleus.
the class PgGeometrySpatialTest method testDifference.
@Datastore(POSTGRESQL)
public void testDifference() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Polygon polygon = new Polygon("SRID=4326;POLYGON((75 75,100 75,100 80,80 80,75 75))");
Polygon difference = new Polygon("SRID=4326;POLYGON((80 80,100 100,100 80,80 80))");
Query query = pm.newQuery(SamplePolygon.class, "geom != null && Spatial.equals(Spatial.difference(geom, :polygon), :difference)");
List list = (List) query.execute(polygon, difference);
assertEquals("Wrong number of geometries whose difference from a given polygon is equal to a given polygon returned", 1, list.size());
assertTrue("Polygon 2 should be in the list of geometries whose difference from a given polygon is equal to a given polygon", list.contains(getSamplePolygon(2)));
query = pm.newQuery(SamplePolygon.class, "id == :id");
query.setResult("Spatial.difference(geom, Spatial.geomFromText('POLYGON((75 75,100 75,100 80,80 80,75 75))', 4326))");
query.setUnique(true);
Geometry difference_read = (Geometry) query.execute(new Long(getSamplePolygon(2).getId()));
assertEquals("Returned difference should be equal to the given polygon", difference, difference_read);
} finally {
tx.commit();
}
}
Aggregations