use of org.postgis.Polygon in project tests by datanucleus.
the class PgGeometrySpatialTest method testIntersects.
public void testIntersects() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Polygon polygon = new Polygon("SRID=4326;POLYGON((10 10,40 10,40 40,10 40,10 10))");
Query query = pm.newQuery(SamplePolygon.class, "geom != null && Spatial.intersects(geom, :polygon)");
List list = (List) query.execute(polygon);
assertEquals("Wrong number of geometries which intersect with a given polygon returned", 1, list.size());
assertTrue("Polygon 1 should be in the list of geometries which intersect with a given polygon", list.contains(getSamplePolygon(1)));
query = pm.newQuery(SamplePolygon.class, "id == :id");
query.setResult("Spatial.intersects(geom, Spatial.geomFromText('POLYGON((10 10,40 10,40 40,10 40,10 10))', 4326))");
query.setResultClass(Boolean.class);
query.setUnique(true);
Boolean equals = (Boolean) query.execute(new Long(getSamplePolygon(1).getId()));
assertEquals("Polygon 1 should intersect the given polygon", true, equals.booleanValue());
} finally {
tx.commit();
}
}
use of org.postgis.Polygon 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();
}
}
use of org.postgis.Polygon in project tests by datanucleus.
the class PgGeometrySpatialTest method testEquals.
public void testEquals() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Polygon polygon = new Polygon("SRID=4326;POLYGON((25 25,75 25,75 75,25 75,25 25),(45 45,55 45,55 55,45 55,45 45))");
Query query = pm.newQuery(SamplePolygon.class, "geom != null && Spatial.equals(geom, :polygon)");
List list = (List) query.execute(polygon);
assertEquals("Wrong number of geometries which are equal to a given polygon returned", 1, list.size());
assertTrue("Polygon 1 should be in the list of geometries which are equal to a given polygon", list.contains(getSamplePolygon(1)));
query = pm.newQuery(SamplePolygon.class, "id == :id");
query.setResult("Spatial.equals(geom, Spatial.geomFromText('POLYGON((25 25,75 25,75 75,25 75,25 25),(45 45,55 45,55 55,45 55,45 45))', 4326))");
query.setResultClass(Boolean.class);
query.setUnique(true);
Boolean equals = (Boolean) query.execute(new Long(getSamplePolygon(1).getId()));
assertEquals("Polygon 1 should be equal to the given polygon", true, equals.booleanValue());
} finally {
tx.commit();
}
}
use of org.postgis.Polygon in project tests by datanucleus.
the class PgGeometrySpatialTest method testOverlaps.
public void testOverlaps() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Polygon polygon = new Polygon("SRID=4326;POLYGON((10 10,50 10,50 50,10 50,10 10))");
Query query = pm.newQuery(SamplePolygon.class, "geom != null && Spatial.overlaps(geom, :polygon)");
List list = (List) query.execute(polygon);
assertEquals("Wrong number of geometries which overlap a given polygon returned", 1, list.size());
assertTrue("LineString 1 should be in the list of geometries which overlap a given polygon", list.contains(getSamplePolygon(1)));
query = pm.newQuery(SamplePolygon.class, "id == :id");
query.setResult("Spatial.overlaps(geom, Spatial.geomFromText('POLYGON((10 10,50 10,50 50,10 50,10 10))', 4326))");
query.setResultClass(Boolean.class);
query.setUnique(true);
Boolean equals = (Boolean) query.execute(new Long(getSamplePolygon(1).getId()));
assertEquals("Polygon 1 should overlap the given polygon", true, equals.booleanValue());
} finally {
tx.commit();
}
}
Aggregations