use of org.postgis.Polygon in project tests by datanucleus.
the class PgGeometryMappingTest method testPolygonMapping.
public void testPolygonMapping() throws SQLException {
if (!runTestsForDatastore()) {
return;
}
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))");
SamplePolygon samplePolygon;
SamplePolygon samplePolygon_read;
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
Object id = null;
try {
tx.begin();
samplePolygon = new SamplePolygon(3001, "Polygon 1", polygon);
pm.makePersistent(samplePolygon);
id = JDOHelper.getObjectId(samplePolygon);
samplePolygon = (SamplePolygon) pm.detachCopy(samplePolygon);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
pm = pmf.getPersistenceManager();
tx = pm.currentTransaction();
try {
tx.begin();
samplePolygon_read = (SamplePolygon) pm.getObjectById(id, true);
assertEquals(samplePolygon, samplePolygon_read);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
use of org.postgis.Polygon in project tests by datanucleus.
the class PgGeometryMySQLTest method testMbrIntersects.
public void testMbrIntersects() throws SQLException {
if (!runTestsForDatastore()) {
return;
}
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 && MySQL.mbrIntersects(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)));
} finally {
tx.commit();
}
}
use of org.postgis.Polygon in project tests by datanucleus.
the class PgGeometryMySQLTest method testMbrDisjoint.
public void testMbrDisjoint() throws SQLException {
if (!runTestsForDatastore()) {
return;
}
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 && MySQL.mbrDisjoint(geom, :polygon)");
List list = (List) query.execute(polygon);
assertEquals("Wrong number of geometries which are disjoint from a given polygon returned", 1, list.size());
assertTrue("Polygon 2 should be in the list of geometries which are disjoint from a given polygon", list.contains(getSamplePolygon(2)));
} finally {
tx.commit();
}
}
use of org.postgis.Polygon 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();
}
}
use of org.postgis.Polygon in project tests by datanucleus.
the class PgGeometrySpatialTest method testDisjoint.
public void testDisjoint() 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.disjoint(geom, :polygon)");
List list = (List) query.execute(polygon);
assertEquals("Wrong number of geometries which are disjoint from a given polygon returned", 1, list.size());
assertTrue("Polygon 2 should be in the list of geometries which are disjoint from a given polygon", list.contains(getSamplePolygon(2)));
query = pm.newQuery(SamplePolygon.class, "id == :id");
query.setResult("Spatial.disjoint(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(2).getId()));
assertEquals("Polygon 2 should be disjoint from the given polygon", true, equals.booleanValue());
} finally {
tx.commit();
}
}
Aggregations