Search in sources :

Example 1 with MultiPolygon

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();
    }
}
Also used : SampleMultiPolygon(org.datanucleus.samples.pggeometry.SampleMultiPolygon) Transaction(javax.jdo.Transaction) MultiPolygon(org.postgis.MultiPolygon) SampleMultiPolygon(org.datanucleus.samples.pggeometry.SampleMultiPolygon) PersistenceManager(javax.jdo.PersistenceManager)

Example 2 with MultiPolygon

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();
    }
}
Also used : Geometry(org.postgis.Geometry) Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) MultiPolygon(org.postgis.MultiPolygon) SamplePolygon(org.datanucleus.samples.pggeometry.SamplePolygon) List(java.util.List) SamplePolygon(org.datanucleus.samples.pggeometry.SamplePolygon) Polygon(org.postgis.Polygon) MultiPolygon(org.postgis.MultiPolygon) Datastore(org.datanucleus.tests.annotations.Datastore)

Example 3 with MultiPolygon

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();
    }
}
Also used : Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) MultiPolygon(org.postgis.MultiPolygon) List(java.util.List)

Aggregations

PersistenceManager (javax.jdo.PersistenceManager)3 Transaction (javax.jdo.Transaction)3 MultiPolygon (org.postgis.MultiPolygon)3 List (java.util.List)2 Query (javax.jdo.Query)2 SampleMultiPolygon (org.datanucleus.samples.pggeometry.SampleMultiPolygon)1 SamplePolygon (org.datanucleus.samples.pggeometry.SamplePolygon)1 Datastore (org.datanucleus.tests.annotations.Datastore)1 Geometry (org.postgis.Geometry)1 Polygon (org.postgis.Polygon)1