use of org.postgis.Point in project tests by datanucleus.
the class PgGeometrySpatialTest method testPointN.
public void testPointN() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Point point = new Point("SRID=4326;POINT(110 10)");
Short n = new Short((short) 3);
Query query = pm.newQuery(SampleLineString.class, "geom != null && Spatial.asText(Spatial.pointN(geom, :n)) == Spatial.asText(:point)");
List list = (List) query.execute(n, point);
assertEquals("Wrong number of geometries whose point no. " + n + " equals a given point returned", 1, list.size());
assertTrue("LineString 3 should be in the list of geometries whose point no. " + n + " equals a given point", list.contains(getSampleLineString(3)));
query = pm.newQuery(SampleLineString.class, "id == :id");
query.setResult("Spatial.pointN(geom, 3)");
query.setUnique(true);
Geometry point_read = (Geometry) query.execute(new Long(getSampleLineString(3).getId()));
assertEquals("Returned third point should be equal to the given point", point, point_read);
} finally {
tx.commit();
}
}
use of org.postgis.Point 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.postgis.Point in project tests by datanucleus.
the class PgGeometrySpatialTest method testWithin.
public void testWithin() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Point point = new Point("SRID=4326;POINT(30 30)");
Query query = pm.newQuery(SamplePolygon.class, "geom != null && Spatial.within(:point, geom)");
List list = (List) query.execute(point);
assertEquals("Wrong number of geometries where a given point is within returned", 1, list.size());
assertTrue("Polygon 1 should be in the list of geometries where a given point is within", list.contains(getSamplePolygon(1)));
query = pm.newQuery(SamplePolygon.class, "id == :id");
query.setResult("Spatial.within(Spatial.geomFromText('POINT(30 30)', 4326), geom)");
query.setResultClass(Boolean.class);
query.setUnique(true);
Boolean equals = (Boolean) query.execute(new Long(getSamplePolygon(1).getId()));
assertEquals("Given point should be in Polygon 1", true, equals.booleanValue());
} finally {
tx.commit();
}
}
Aggregations