Search in sources :

Example 1 with Datastore

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

the class JtsGeometrySpatialTest method testCrosses.

@Datastore(POSTGRESQL)
public void testCrosses() throws SQLException, ParseException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        LineString lineString = (LineString) wktReader.read("LINESTRING(25 25,25 75)");
        Query query = pm.newQuery(SampleLineString.class, "geom != null && :lineString.crosses(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.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) Datastore(org.datanucleus.tests.annotations.Datastore)

Example 2 with Datastore

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

the class JtsGeometrySpatialTest method testDifference.

@Datastore(POSTGRESQL)
public void testDifference() throws SQLException, ParseException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Polygon polygon = (Polygon) wktReader.read("POLYGON((75 75,100 75,100 80,80 80,75 75))");
        Polygon difference = (Polygon) wktReader.read("POLYGON((80 80,100 100,100 80,80 80))");
        Query query = pm.newQuery(SamplePolygon.class, "geom != null && geom.difference(:polygon).equals(:difference)");
        List list = (List) query.execute(polygon, difference);
        assertEquals("Wrong number of geometries whose difference from a given polygon is equal to a given polygon returned", 1, list.size());
        assertTrue("Polygon 2 should be in the list of geometries whose difference from a given polygon is equal to a given polygon", list.contains(getSamplePolygon(2)));
        query = pm.newQuery(SamplePolygon.class, "id == :id");
        query.setResult("geom.difference(Spatial.geomFromText('POLYGON((75 75,100 75,100 80,80 80,75 75))', 4326))");
        query.setUnique(true);
        Geometry difference_read = (Geometry) query.execute(new Long(getSamplePolygon(2).getId()));
        difference.normalize();
        difference_read.normalize();
        assertTrue("Returned difference should be equal to the given polygon", difference_read.equalsExact(difference));
    } 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) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) SamplePolygon(org.datanucleus.samples.jtsgeometry.SamplePolygon) Polygon(com.vividsolutions.jts.geom.Polygon) Datastore(org.datanucleus.tests.annotations.Datastore)

Example 3 with Datastore

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

the class JtsGeometrySpatialTest method testBuffer.

@Datastore(POSTGRESQL)
public void testBuffer() throws SQLException, ParseException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Point point = (Point) wktReader.read("POINT(0 0)");
        Query query = pm.newQuery(SamplePoint.class, "geom != null && geom.within(:point.buffer(20))");
        List list = (List) query.execute(point);
        assertEquals("Wrong number of geometries which are within the buffer of a given point returned", 1, list.size());
        assertTrue("Point 1 should be in the list of geometries which are within the buffer of a given point", list.contains(getSamplePoint(1)));
        query = pm.newQuery(SamplePoint.class, "id == :id");
        query.setResult("geom.buffer(20)");
        query.setUnique(true);
        Geometry buffer = (Geometry) query.execute(new Long(getSamplePoint(1).getId()));
        assertEquals("Returned buffer should be a polygon", "POLYGON", buffer.getGeometryType().toUpperCase());
        assertEquals("Returned buffer should have the given srid", 4326, buffer.getSRID());
        assertTrue("Given point should be within the returned buffer", point.within(buffer));
    } finally {
        tx.commit();
    }
}
Also used : 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 4 with Datastore

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

the class PgGeometrySpatialTest method testIsSimple.

@Datastore(POSTGRESQL)
public void testIsSimple() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Query query = pm.newQuery(SampleLineString.class, "geom != null && Spatial.isSimple(geom)");
        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("Spatial.isSimple(geom)");
        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.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 5 with Datastore

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

the class PgGeometrySpatialTest method testDifference.

@Datastore(POSTGRESQL)
public void testDifference() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Polygon polygon = new Polygon("SRID=4326;POLYGON((75 75,100 75,100 80,80 80,75 75))");
        Polygon difference = new Polygon("SRID=4326;POLYGON((80 80,100 100,100 80,80 80))");
        Query query = pm.newQuery(SamplePolygon.class, "geom != null && Spatial.equals(Spatial.difference(geom, :polygon), :difference)");
        List list = (List) query.execute(polygon, difference);
        assertEquals("Wrong number of geometries whose difference from a given polygon is equal to a given polygon returned", 1, list.size());
        assertTrue("Polygon 2 should be in the list of geometries whose difference from a given polygon is equal to a given polygon", list.contains(getSamplePolygon(2)));
        query = pm.newQuery(SamplePolygon.class, "id == :id");
        query.setResult("Spatial.difference(geom, Spatial.geomFromText('POLYGON((75 75,100 75,100 80,80 80,75 75))', 4326))");
        query.setUnique(true);
        Geometry difference_read = (Geometry) query.execute(new Long(getSamplePolygon(2).getId()));
        assertEquals("Returned difference should be equal to the given polygon", difference, difference_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) 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