Search in sources :

Example 26 with Datastore

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

the class PgGeometrySpatialTest method testIntersection.

@Datastore(POSTGRESQL)
public void testIntersection() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        LineString lineString = new LineString("SRID=4326;LINESTRING(25 25, 25 75)");
        Point intersection = new Point("SRID=4326;POINT(25 50)");
        Query query = pm.newQuery(SampleLineString.class, "geom != null && Spatial.asText(Spatial.intersection(geom, :lineString)) == Spatial.asText(:intersection)");
        List list = (List) query.execute(lineString, intersection);
        assertEquals("Wrong number of geometries which intersect a given linestring at a given point returned", 1, list.size());
        assertTrue("LineSting 1 should be in the list of geometries which intersect a given linestring at a given point", list.contains(getSampleLineString(1)));
        query = pm.newQuery(SampleLineString.class, "id == :id");
        query.setResult("Spatial.intersection(geom, Spatial.geomFromText('LINESTRING(25 25, 25 75)', 4326))");
        query.setUnique(true);
        Geometry intersection_read = (Geometry) query.execute(new Long(getSampleLineString(1).getId()));
        assertEquals("Returned intersection should be equal to the given point", intersection, intersection_read);
    } finally {
        tx.commit();
    }
}
Also used : Geometry(org.postgis.Geometry) 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) MultiPoint(org.postgis.MultiPoint) SamplePoint(org.datanucleus.samples.pggeometry.SamplePoint) Point(org.postgis.Point) Datastore(org.datanucleus.tests.annotations.Datastore)

Example 27 with Datastore

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

the class PgGeometrySpatialTest method testBboxTest.

@Datastore(POSTGRESQL)
public void testBboxTest() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Point point = new Point("SRID=4326;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.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 28 with Datastore

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

the class PgGeometrySpatialTest method testIsRing.

@Datastore(POSTGRESQL)
public void testIsRing() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Query query = pm.newQuery(SampleLineString.class, "geom != null && Spatial.isRing(geom)");
        List list = (List) query.execute();
        assertEquals("Wrong number of rings returned", 0, list.size());
        query = pm.newQuery(SampleLineString.class, "id == :id");
        query.setResult("Spatial.isRing(geom)");
        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.pggeometry.SampleLineString) Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) List(java.util.List) Datastore(org.datanucleus.tests.annotations.Datastore)

Example 29 with Datastore

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

Example 30 with Datastore

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

the class JtsGeometrySpatialTest method testBoundary.

@Datastore(POSTGRESQL)
public void testBoundary() throws SQLException, ParseException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        LineString boundary = (LineString) wktReader.read("LINESTRING(75 75,100 75,100 100,75 75)");
        Query query = pm.newQuery(SamplePolygon.class, "geom != null && geom.getBoundary().equals(: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("geom.getBoundary()");
        query.setUnique(true);
        Geometry boundary_read = (Geometry) query.execute(new Long(getSamplePolygon(2).getId()));
        boundary.normalize();
        boundary_read.normalize();
        assertTrue("Boundary of Polygon 2 should be equal to a given boundary", boundary_read.equalsExact(boundary));
    } finally {
        tx.commit();
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) LineString(com.vividsolutions.jts.geom.LineString) SampleLineString(org.datanucleus.samples.jtsgeometry.SampleLineString) MultiLineString(org.postgis.MultiLineString) SamplePolygon(org.datanucleus.samples.jtsgeometry.SamplePolygon) List(java.util.List) 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