Search in sources :

Example 16 with Geometry

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

the class PgGeometrySpatialTest method testBoundary.

@Datastore(POSTGRESQL)
public void testBoundary() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        LineString boundary = new LineString("SRID=4326;LINESTRING(75 75,100 75,100 100,75 75)");
        Query query = pm.newQuery(SamplePolygon.class, "geom != null && Spatial.equals(Spatial.boundary(geom), :boundary)");
        List list = (List) query.execute(boundary);
        assertEquals("Wrong number of geometries with a given boundary returned", 1, list.size());
        assertTrue("Polygon 2 should be in the list of geometries with a given boundary", list.contains(getSamplePolygon(2)));
        query = pm.newQuery(SamplePolygon.class, "id == :id");
        query.setResult("Spatial.boundary(geom)");
        query.setUnique(true);
        Geometry boundary_read = (Geometry) query.execute(new Long(getSamplePolygon(2).getId()));
        assertEquals("Boundary of Polygon 2 should be equal to a given boundary", boundary, boundary_read);
    } finally {
        tx.commit();
    }
}
Also used : Geometry(org.postgis.Geometry) Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) SampleLineString(org.datanucleus.samples.pggeometry.SampleLineString) MultiLineString(org.postgis.MultiLineString) LineString(org.postgis.LineString) SamplePolygon(org.datanucleus.samples.pggeometry.SamplePolygon) List(java.util.List) Datastore(org.datanucleus.tests.annotations.Datastore)

Aggregations

List (java.util.List)16 PersistenceManager (javax.jdo.PersistenceManager)16 Query (javax.jdo.Query)16 Transaction (javax.jdo.Transaction)16 Geometry (org.postgis.Geometry)16 SampleLineString (org.datanucleus.samples.pggeometry.SampleLineString)10 SamplePolygon (org.datanucleus.samples.pggeometry.SamplePolygon)9 Datastore (org.datanucleus.tests.annotations.Datastore)9 SamplePoint (org.datanucleus.samples.pggeometry.SamplePoint)7 MultiPoint (org.postgis.MultiPoint)7 Point (org.postgis.Point)7 LineString (org.postgis.LineString)5 MultiLineString (org.postgis.MultiLineString)5 MultiPolygon (org.postgis.MultiPolygon)4 Polygon (org.postgis.Polygon)4 SampleGeometryCollection (org.datanucleus.samples.pggeometry.SampleGeometryCollection)1