Search in sources :

Example 21 with Datastore

use of org.datanucleus.tests.annotations.Datastore in project tests by datanucleus.

the class PgGeometrySpatialTest method testCentroid.

@Datastore(POSTGRESQL)
public void testCentroid() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Point centroid = new Point("SRID=4326;POINT(50 50)");
        Query query = pm.newQuery(SamplePolygon.class, "geom != null && Spatial.asText(Spatial.centroid(geom)) == Spatial.asText(:centroid)");
        List list = (List) query.execute(centroid);
        assertEquals("Wrong number of geometries with a given centroid returned", 1, list.size());
        assertTrue("Polygon 1 should be in the list of geometries with a given centroid", list.contains(getSamplePolygon(1)));
        query = pm.newQuery(SamplePolygon.class, "id == :id");
        query.setResult("Spatial.centroid(geom)");
        query.setUnique(true);
        Geometry centroid_read = (Geometry) query.execute(new Long(getSamplePolygon(1).getId()));
        assertEquals("Given point shoul be centroid of Polygon 1", centroid, centroid_read);
    } finally {
        tx.commit();
    }
}
Also used : Geometry(org.postgis.Geometry) Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) SamplePolygon(org.datanucleus.samples.pggeometry.SamplePolygon) List(java.util.List) MultiPoint(org.postgis.MultiPoint) SamplePoint(org.datanucleus.samples.pggeometry.SamplePoint) Point(org.postgis.Point) Datastore(org.datanucleus.tests.annotations.Datastore)

Example 22 with Datastore

use of org.datanucleus.tests.annotations.Datastore in project tests by datanucleus.

the class PgGeometrySpatialTest method testIsEmpty.

@Datastore(POSTGRESQL)
public void testIsEmpty() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        LineString lineString = new LineString("SRID=4326;LINESTRING(25 25, 25 75)");
        Query query = pm.newQuery(SampleLineString.class, "geom != null && Spatial.isEmpty(Spatial.intersection(geom, :linestring))");
        List list = (List) query.execute(lineString);
        assertEquals("Wrong number of geometries that do not intersect with a given linestring returned", 2, list.size());
        assertTrue("LineString 2 should be in the list of geometries that do not intersect with a given linestring", list.contains(getSampleLineString(2)));
        assertTrue("LineString 3 should be in the list of geometries that do not intersect with a given linestring", list.contains(getSampleLineString(3)));
        query = pm.newQuery(SampleLineString.class, "geom != null");
        query.setResult("Spatial.isEmpty(Spatial.intersection(geom, Spatial.geomFromText('LINESTRING(25 25, 25 75)', 4326))) AS isEmpty");
        query.setResultClass(Boolean.class);
        list = (List) query.execute();
        assertEquals("Wrong number of geometries returned", 3, list.size());
        assertEquals("The intersection of LineString 1 with a given linestring should not be empty", false, ((Boolean) list.get(0)).booleanValue());
        assertEquals("The intersection of LineString 2 with a given linestring should be empty", true, ((Boolean) list.get(1)).booleanValue());
        assertEquals("The intersection of LineString 3 with a given linestring should be empty", true, ((Boolean) list.get(2)).booleanValue());
    } finally {
        tx.commit();
    }
}
Also used : SampleLineString(org.datanucleus.samples.pggeometry.SampleLineString) 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) List(java.util.List) Datastore(org.datanucleus.tests.annotations.Datastore)

Example 23 with Datastore

use of org.datanucleus.tests.annotations.Datastore in project tests by datanucleus.

the class PgGeometrySpatialTest method testCrosses.

@Datastore(POSTGRESQL)
public void testCrosses() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        LineString lineString = new LineString("SRID=4326;LINESTRING(25 25,25 75)");
        Query query = pm.newQuery(SampleLineString.class, "geom != null && Spatial.crosses(:lineString, geom)");
        List list = (List) query.execute(lineString);
        assertEquals("Wrong number of geometries which are crossed by a given linestring returned", 1, list.size());
        assertTrue("LineString 1 should be in the list of geometries which are crossed by a given linestring", list.contains(getSampleLineString(1)));
        query = pm.newQuery(SampleLineString.class, "id == :id");
        query.setResult("Spatial.crosses(Spatial.geomFromText('LINESTRING(25 25,25 75)', 4326), geom)");
        query.setResultClass(Boolean.class);
        query.setUnique(true);
        Boolean equals = (Boolean) query.execute(new Long(getSampleLineString(1).getId()));
        assertEquals("LineString 1 should be crossed by the given linestring", true, equals.booleanValue());
    } finally {
        tx.commit();
    }
}
Also used : SampleLineString(org.datanucleus.samples.pggeometry.SampleLineString) 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) List(java.util.List) Datastore(org.datanucleus.tests.annotations.Datastore)

Example 24 with Datastore

use of org.datanucleus.tests.annotations.Datastore 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)

Example 25 with Datastore

use of org.datanucleus.tests.annotations.Datastore 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)

Aggregations

List (java.util.List)33 PersistenceManager (javax.jdo.PersistenceManager)33 Query (javax.jdo.Query)33 Transaction (javax.jdo.Transaction)33 Datastore (org.datanucleus.tests.annotations.Datastore)33 MultiLineString (org.postgis.MultiLineString)11 Geometry (com.vividsolutions.jts.geom.Geometry)9 SampleLineString (org.datanucleus.samples.pggeometry.SampleLineString)9 Geometry (org.postgis.Geometry)9 SampleLineString (org.datanucleus.samples.jtsgeometry.SampleLineString)8 SamplePolygon (org.datanucleus.samples.jtsgeometry.SamplePolygon)7 SamplePoint (org.datanucleus.samples.pggeometry.SamplePoint)7 SamplePolygon (org.datanucleus.samples.pggeometry.SamplePolygon)7 MultiPoint (org.postgis.MultiPoint)7 Point (org.postgis.Point)7 LineString (org.postgis.LineString)6 LineString (com.vividsolutions.jts.geom.LineString)5 MultiPoint (com.vividsolutions.jts.geom.MultiPoint)5 Point (com.vividsolutions.jts.geom.Point)5 SamplePoint (org.datanucleus.samples.jtsgeometry.SamplePoint)5