Search in sources :

Example 31 with Datastore

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

the class JtsGeometrySpatialTest method testIntersection.

@Datastore(POSTGRESQL)
public void testIntersection() throws SQLException, ParseException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        LineString lineString = (LineString) wktReader.read("LINESTRING(25 25, 25 75)");
        Point intersection = (Point) wktReader.read("POINT(25 50)");
        Query query = pm.newQuery(SampleLineString.class, "geom != null && geom.intersection(:lineString).toText() == 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("geom.intersection(Spatial.geomFromText('LINESTRING(25 25, 25 75)', 4326))");
        query.setUnique(true);
        Geometry intersection_read = (Geometry) query.execute(new Long(getSampleLineString(1).getId()));
        assertTrue("Returned intersection should be equal to the given point", intersection_read.equalsExact(intersection));
    } finally {
        tx.commit();
    }
}
Also used : Geometry(com.vividsolutions.jts.geom.Geometry) SampleLineString(org.datanucleus.samples.jtsgeometry.SampleLineString) 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) 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 32 with Datastore

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

the class JtsGeometrySpatialTest method testUnion.

@Datastore(POSTGRESQL)
public void testUnion() throws SQLException, ParseException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Point point = (Point) wktReader.read("POINT(50 50)");
        MultiPoint union = (MultiPoint) wktReader.read("MULTIPOINT(10 10,50 50)");
        Query query = pm.newQuery(SamplePoint.class, "geom != null && geom.union(:point).toText() == :union.toText()");
        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("geom.union(Spatial.geomFromText('POINT(50 50)', 4326))");
        query.setUnique(true);
        Geometry union_read = (Geometry) query.execute(new Long(getSamplePoint(1).getId()));
        union.normalize();
        union_read.normalize();
        assertTrue("Returned union should be equal to the given multipoint", union_read.equalsExact(union));
    } finally {
        tx.commit();
    }
}
Also used : MultiPoint(com.vividsolutions.jts.geom.MultiPoint) SamplePoint(org.datanucleus.samples.jtsgeometry.SamplePoint) Geometry(com.vividsolutions.jts.geom.Geometry) Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) 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 33 with Datastore

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

the class JtsGeometrySpatialTest method testIsSimple.

@Datastore(POSTGRESQL)
public void testIsSimple() throws SQLException, ParseException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Query query = pm.newQuery(SampleLineString.class, "geom != null && geom.isSimple()");
        List list = (List) query.execute();
        assertEquals("Wrong number of simple geometries returned", 2, list.size());
        assertTrue("LineString 1 should be in the list of simple geometries", list.contains(getSampleLineString(1)));
        assertTrue("LineString 2 should be in the list of simple geometries", list.contains(getSampleLineString(2)));
        query = pm.newQuery(SampleLineString.class, "id == :id");
        query.setResult("geom.isSimple()");
        query.setResultClass(Boolean.class);
        query.setUnique(true);
        Boolean isSimple = (Boolean) query.execute(new Long(getSampleLineString(2).getId()));
        assertEquals("LineString 2 is simple", true, isSimple.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)

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