Search in sources :

Example 11 with Datastore

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

the class PgGeometrySpatialTest method testGeographicMethods.

@Datastore(POSTGRESQL)
public void testGeographicMethods() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        String strGeom = "SRID=4326;POINT(10 10)";
        Query query = pm.newQuery(SamplePoint.class, "geom != null && Spatial.distance(Spatial.geogFromText(:strGeom), Spatial.geogFromWKB(Spatial.asBinary(geom))) == 0");
        List list = (List) query.execute(strGeom);
        assertEquals("Wrong number of g" + "eometries 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 : Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) List(java.util.List) SampleLineString(org.datanucleus.samples.pggeometry.SampleLineString) MultiLineString(org.postgis.MultiLineString) LineString(org.postgis.LineString) Datastore(org.datanucleus.tests.annotations.Datastore)

Example 12 with Datastore

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

the class JtsGeometrySpatialTest method testBboxTest.

@Datastore(POSTGRESQL)
public void testBboxTest() throws SQLException, ParseException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Point point = (Point) wktReader.read("POINT(90 90)");
        Query query = pm.newQuery(SamplePolygon.class, "geom != null && Spatial.bboxTest(:point, geom)");
        List list = (List) query.execute(point);
        assertEquals("Wrong number of geometries which pass the bbox test with a given point returned", 1, list.size());
        assertTrue("Polygon 2 should be in the list of geometries which pass the bbox test with a given point", list.contains(getSamplePolygon(2)));
        query = pm.newQuery(SamplePolygon.class, "id == :id");
        query.setResult("Spatial.bboxTest(Spatial.geomFromText('POINT(90 90)', 4326), geom)");
        query.setResultClass(Boolean.class);
        query.setUnique(true);
        Boolean equals = (Boolean) query.execute(new Long(getSamplePolygon(2).getId()));
        assertEquals("Polygon 2 should pass bbox test with the given point", true, equals.booleanValue());
    } finally {
        tx.commit();
    }
}
Also used : Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) SamplePolygon(org.datanucleus.samples.jtsgeometry.SamplePolygon) List(java.util.List) Point(com.vividsolutions.jts.geom.Point) SamplePoint(org.datanucleus.samples.jtsgeometry.SamplePoint) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) Datastore(org.datanucleus.tests.annotations.Datastore)

Example 13 with Datastore

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

the class JtsGeometrySpatialTest method testPointOnSurfaceMethod.

@Datastore(POSTGRESQL)
public void testPointOnSurfaceMethod() throws SQLException, ParseException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Query query = pm.newQuery(SamplePolygon.class, "geom != null && Spatial.pointOnSurface(geom) != null");
        List list = (List) query.execute();
        assertEquals("Wrong number of geometries with a point on the surface returned", 2, list.size());
        assertTrue("Polygon 1 should be in the list of geometries with a point on the surface", list.contains(getSamplePolygon(1)));
        assertTrue("Polygon 2 should be in the list of geometries with a point on the surface", list.contains(getSamplePolygon(2)));
        query = pm.newQuery(SamplePolygon.class, "id == :id");
        query.setResult("Spatial.pointOnSurface(geom)");
        query.setUnique(true);
        Geometry pointOnSurface = (Geometry) query.execute(new Long(getSamplePolygon(1).getId()));
        assertNotNull("Polygon 1 should have a point on the surface", pointOnSurface);
        assertEquals("Polygon 1 should have a point on the surface", "POINT", pointOnSurface.getGeometryType().toUpperCase());
    } finally {
        tx.commit();
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) SamplePolygon(org.datanucleus.samples.jtsgeometry.SamplePolygon) List(java.util.List) Datastore(org.datanucleus.tests.annotations.Datastore)

Example 14 with Datastore

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

the class JtsGeometrySpatialTest method testIsRing.

@Datastore(POSTGRESQL)
public void testIsRing() throws SQLException, ParseException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Query query = pm.newQuery(SampleLineString.class, "geom != null && geom.isRing()");
        List list = (List) query.execute();
        assertEquals("Wrong number of rings returned", 0, list.size());
        query = pm.newQuery(SampleLineString.class, "id == :id");
        query.setResult("geom.isRing()");
        query.setResultClass(Boolean.class);
        query.setUnique(true);
        Boolean isRing = (Boolean) query.execute(new Long(getSampleLineString(3).getId()));
        assertEquals("LineString 3 should not be a ring", false, isRing.booleanValue());
    } finally {
        tx.commit();
    }
}
Also used : SampleLineString(org.datanucleus.samples.jtsgeometry.SampleLineString) Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) List(java.util.List) Datastore(org.datanucleus.tests.annotations.Datastore)

Example 15 with Datastore

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

the class JtsGeometrySpatialTest method testCentroid.

@Datastore(POSTGRESQL)
public void testCentroid() throws SQLException, ParseException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Point centroid = (Point) wktReader.read("POINT(50 50)");
        Query query = pm.newQuery(SamplePolygon.class, "geom != null && geom.getCentroid().toText() == 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("geom.getCentroid()");
        query.setUnique(true);
        Geometry centroid_read = (Geometry) query.execute(new Long(getSamplePolygon(1).getId()));
        assertTrue("Given point shoul be centroid of Polygon 1", centroid_read.equalsExact(centroid));
    } finally {
        tx.commit();
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) SamplePolygon(org.datanucleus.samples.jtsgeometry.SamplePolygon) List(java.util.List) Point(com.vividsolutions.jts.geom.Point) SamplePoint(org.datanucleus.samples.jtsgeometry.SamplePoint) MultiPoint(com.vividsolutions.jts.geom.MultiPoint) 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