Search in sources :

Example 1 with GeometryCollection

use of org.postgis.GeometryCollection in project tests by datanucleus.

the class PgGeometrySpatialTest method testGeomCollFromWKB.

public void testGeomCollFromWKB() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        GeometryCollection geom = new GeometryCollection("SRID=4326;GEOMETRYCOLLECTION(POINT(10 10),LINESTRING(0 50, 100 50),POLYGON((25 25,75 25,75 75,25 75,25 25),(45 45,55 45,55 55,45 55,45 45)))");
        Short n = new Short((short) 1);
        Query query = pm.newQuery(SamplePoint.class, "geom != null && Spatial.equals(geom, Spatial.geometryN(Spatial.geomCollFromWKB(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("Point 1 should be in the list of geometries with a given wkb", list.contains(getSamplePoint(1)));
    } finally {
        tx.commit();
    }
}
Also used : SampleGeometryCollection(org.datanucleus.samples.pggeometry.SampleGeometryCollection) GeometryCollection(org.postgis.GeometryCollection) Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) List(java.util.List)

Example 2 with GeometryCollection

use of org.postgis.GeometryCollection in project tests by datanucleus.

the class PgGeometryMappingTest method testGeometryCollectionMapping.

public void testGeometryCollectionMapping() throws SQLException {
    if (!runTestsForDatastore()) {
        return;
    }
    GeometryCollection geometryCollection = new GeometryCollection("SRID=4326;GEOMETRYCOLLECTION(POINT(10 10),LINESTRING(0 50, 100 50),POLYGON((25 25,75 25,75 75,25 75,25 25),(45 45,55 45,55 55,45 55,45 45)))");
    SampleGeometryCollection sampleGeometryCollection;
    SampleGeometryCollection sampleGeometryCollection_read;
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    Object id = null;
    try {
        tx.begin();
        sampleGeometryCollection = new SampleGeometryCollection(7001, "Collection 1", geometryCollection);
        pm.makePersistent(sampleGeometryCollection);
        id = JDOHelper.getObjectId(sampleGeometryCollection);
        sampleGeometryCollection = (SampleGeometryCollection) pm.detachCopy(sampleGeometryCollection);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
    pm = pmf.getPersistenceManager();
    tx = pm.currentTransaction();
    try {
        tx.begin();
        sampleGeometryCollection_read = (SampleGeometryCollection) pm.getObjectById(id, true);
        assertEquals(sampleGeometryCollection, sampleGeometryCollection_read);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
}
Also used : SampleGeometryCollection(org.datanucleus.samples.pggeometry.SampleGeometryCollection) GeometryCollection(org.postgis.GeometryCollection) SampleGeometryCollection(org.datanucleus.samples.pggeometry.SampleGeometryCollection) Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager)

Example 3 with GeometryCollection

use of org.postgis.GeometryCollection in project tests by datanucleus.

the class PgGeometryPostGISExtMappingTest method testGeometryCollection3DMapping.

public void testGeometryCollection3DMapping() throws SQLException {
    if (!runTestsForDatastore()) {
        return;
    }
    SampleGeometryCollection3D sampleGeometryCollection;
    SampleGeometryCollection3D sampleGeometryCollection_read;
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    Object id = null;
    try {
        tx.begin();
        sampleGeometryCollection = new SampleGeometryCollection3D(7101, "Collection of 3-dimensional geometries", new GeometryCollection("SRID=-1;GEOMETRYCOLLECTION(POINT(10 10 100),LINESTRING(0 50 100, 100 50 100),POLYGON((25 25 100,75 25 100,75 75 100,25 75 100,25 25 100),(45 45 100,55 45 100,55 55 100,45 55 100,45 45 100)))"));
        pm.makePersistent(sampleGeometryCollection);
        id = JDOHelper.getObjectId(sampleGeometryCollection);
        sampleGeometryCollection = (SampleGeometryCollection3D) pm.detachCopy(sampleGeometryCollection);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
    pm = pmf.getPersistenceManager();
    tx = pm.currentTransaction();
    try {
        tx.begin();
        sampleGeometryCollection_read = (SampleGeometryCollection3D) pm.getObjectById(id, true);
        assertEquals(sampleGeometryCollection, sampleGeometryCollection_read);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
}
Also used : GeometryCollection(org.postgis.GeometryCollection) Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager) SampleGeometryCollection3D(org.datanucleus.samples.pggeometry.SampleGeometryCollection3D)

Example 4 with GeometryCollection

use of org.postgis.GeometryCollection in project tests by datanucleus.

the class PgGeometryPostGISExtMappingTest method testGeometryCollectionMMapping.

// TODO this test should be running successfully after using
// 2.1.3 or alter postgis jdbc jars from OSSRH rep
// when they are available.
public void testGeometryCollectionMMapping() throws SQLException {
    if (!runTestsForDatastore()) {
        return;
    }
    SampleGeometryCollectionM sampleGeometryCollection;
    SampleGeometryCollectionM sampleGeometryCollection_read;
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    Object id = null;
    try {
        tx.begin();
        sampleGeometryCollection = new SampleGeometryCollectionM(7201, "Collection of geometries with measure", new GeometryCollection("SRID=-1;GEOMETRYCOLLECTIONM(POINTM(10 10 100),LINESTRINGM(0 50 100, 100 50 100),POLYGONM((25 25 100,75 25 100,75 75 100,25 75 100,25 25 100),(45 45 100,55 45 100,55 55 100,45 55 100,45 45 100)))"));
        pm.makePersistent(sampleGeometryCollection);
        id = JDOHelper.getObjectId(sampleGeometryCollection);
        sampleGeometryCollection = (SampleGeometryCollectionM) pm.detachCopy(sampleGeometryCollection);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
    pm = pmf.getPersistenceManager();
    tx = pm.currentTransaction();
    try {
        tx.begin();
        sampleGeometryCollection_read = (SampleGeometryCollectionM) pm.getObjectById(id, true);
        assertEquals(sampleGeometryCollection, sampleGeometryCollection_read);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
}
Also used : GeometryCollection(org.postgis.GeometryCollection) Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager) SampleGeometryCollectionM(org.datanucleus.samples.pggeometry.SampleGeometryCollectionM)

Aggregations

PersistenceManager (javax.jdo.PersistenceManager)4 Transaction (javax.jdo.Transaction)4 GeometryCollection (org.postgis.GeometryCollection)4 SampleGeometryCollection (org.datanucleus.samples.pggeometry.SampleGeometryCollection)2 List (java.util.List)1 Query (javax.jdo.Query)1 SampleGeometryCollection3D (org.datanucleus.samples.pggeometry.SampleGeometryCollection3D)1 SampleGeometryCollectionM (org.datanucleus.samples.pggeometry.SampleGeometryCollectionM)1