Search in sources :

Example 1 with MultiPoint

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

the class PgGeometryMappingTest method testMultiPointMapping.

public void testMultiPointMapping() throws SQLException {
    if (!runTestsForDatastore()) {
        return;
    }
    MultiPoint multipoint = new MultiPoint("SRID=4326;MULTIPOINT(10 10,75 75)");
    SampleMultiPoint sampleMultiPoint;
    SampleMultiPoint sampleMultiPoint_read;
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    Object id = null;
    try {
        tx.begin();
        sampleMultiPoint = new SampleMultiPoint(4001, "MultiPoint", multipoint);
        pm.makePersistent(sampleMultiPoint);
        id = JDOHelper.getObjectId(sampleMultiPoint);
        sampleMultiPoint = (SampleMultiPoint) pm.detachCopy(sampleMultiPoint);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
    pm = pmf.getPersistenceManager();
    tx = pm.currentTransaction();
    try {
        tx.begin();
        sampleMultiPoint_read = (SampleMultiPoint) pm.getObjectById(id, true);
        assertEquals(sampleMultiPoint, sampleMultiPoint_read);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
}
Also used : MultiPoint(org.postgis.MultiPoint) SampleMultiPoint(org.datanucleus.samples.pggeometry.SampleMultiPoint) SampleMultiPoint(org.datanucleus.samples.pggeometry.SampleMultiPoint) Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager)

Example 2 with MultiPoint

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

the class PgGeometrySpatialTest method testMPointFromWKB.

public void testMPointFromWKB() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        MultiPoint geom = new MultiPoint("SRID=4326;MULTIPOINT(10 10,75 75)");
        Short n = new Short((short) 1);
        Query query = pm.newQuery(SamplePoint.class, "geom != null && Spatial.equals(geom, Spatial.geometryN(Spatial.mPointFromWKB(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 : MultiPoint(org.postgis.MultiPoint) Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) List(java.util.List)

Example 3 with MultiPoint

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

the class PgGeometrySpatialTest method testUnion.

@Datastore(POSTGRESQL)
public void testUnion() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Point point = new Point("SRID=4326;POINT(50 50)");
        MultiPoint union = new MultiPoint("SRID=4326;MULTIPOINT(10 10,50 50)");
        Query query = pm.newQuery(SamplePoint.class, "geom != null && Spatial.asText(Spatial.union(geom, :point)) == Spatial.asText(:union)");
        List list = (List) query.execute(point, union);
        assertEquals("Wrong number of geometries whose union with a given point is equal to a given multipoint returned", 1, list.size());
        assertTrue("Point 1 should be in the list of geometries whose union with a given point is equal to a given multipoint", list.contains(getSamplePoint(1)));
        query = pm.newQuery(SamplePoint.class, "id == :id");
        query.setResult("Spatial.union(geom, Spatial.geomFromText('POINT(50 50)', 4326))");
        query.setUnique(true);
        Geometry union_read = (Geometry) query.execute(new Long(getSamplePoint(1).getId()));
        assertEquals("Returned union should be equal to the given multipoint", union, union_read);
    } finally {
        tx.commit();
    }
}
Also used : MultiPoint(org.postgis.MultiPoint) SamplePoint(org.datanucleus.samples.pggeometry.SamplePoint) Geometry(org.postgis.Geometry) Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) List(java.util.List) MultiPoint(org.postgis.MultiPoint) SamplePoint(org.datanucleus.samples.pggeometry.SamplePoint) Point(org.postgis.Point) Datastore(org.datanucleus.tests.annotations.Datastore)

Aggregations

PersistenceManager (javax.jdo.PersistenceManager)3 Transaction (javax.jdo.Transaction)3 MultiPoint (org.postgis.MultiPoint)3 List (java.util.List)2 Query (javax.jdo.Query)2 SampleMultiPoint (org.datanucleus.samples.pggeometry.SampleMultiPoint)1 SamplePoint (org.datanucleus.samples.pggeometry.SamplePoint)1 Datastore (org.datanucleus.tests.annotations.Datastore)1 Geometry (org.postgis.Geometry)1 Point (org.postgis.Point)1