use of org.postgis.MultiPolygon in project tests by datanucleus.
the class PgGeometryMappingTest method testMultiPolygonMapping.
public void testMultiPolygonMapping() throws SQLException {
if (!runTestsForDatastore()) {
return;
}
MultiPolygon multiPolygon = new MultiPolygon("SRID=4326;MULTIPOLYGON(((25 25,75 25,75 75,25 75,25 25),(45 45,55 45,55 55,45 55,45 45)),((75 75,100 75,100 100,75 75)))");
SampleMultiPolygon sampleMultiPolygon;
SampleMultiPolygon sampleMultiPolygon_read;
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
Object id = null;
try {
tx.begin();
sampleMultiPolygon = new SampleMultiPolygon(6001, "MultiPolygon", multiPolygon);
pm.makePersistent(sampleMultiPolygon);
id = JDOHelper.getObjectId(sampleMultiPolygon);
sampleMultiPolygon = (SampleMultiPolygon) pm.detachCopy(sampleMultiPolygon);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
pm = pmf.getPersistenceManager();
tx = pm.currentTransaction();
try {
tx.begin();
sampleMultiPolygon_read = (SampleMultiPolygon) pm.getObjectById(id, true);
assertEquals(sampleMultiPolygon, sampleMultiPolygon_read);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
use of org.postgis.MultiPolygon 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.MultiPolygon in project tests by datanucleus.
the class PgGeometrySpatialTest method testMPolyFromWKB.
public void testMPolyFromWKB() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
MultiPolygon geom = new MultiPolygon("SRID=4326;MULTIPOLYGON(((25 25,75 25,75 75,25 75,25 25),(45 45,55 45,55 55,45 55,45 45)),((75 75,100 75,100 100,75 75)))");
Short n = new Short((short) 2);
Query query = pm.newQuery(SamplePolygon.class, "geom != null && Spatial.equals(geom, Spatial.geometryN(Spatial.mPolyFromWKB(Spatial.asBinary(:geom), Spatial.srid(:geom)), :n))");
List list = (List) query.execute(geom, n);
assertEquals("Wrong number of geometries with a given wkb returned", 1, list.size());
assertTrue("Polygon 2 should be in the list of geometries with a given wkb", list.contains(getSamplePolygon(2)));
} finally {
tx.commit();
}
}
Aggregations