Search in sources :

Example 6 with Datastore

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

the class PgGeometrySpatialTest method testTransform.

@Datastore(POSTGRESQL)
public void testTransform() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Point geom = new Point("SRID=4326;POINT(10 10)");
        Query query = pm.newQuery(SamplePoint.class, "geom != null && Spatial.equals(geom, Spatial.transform(Spatial.geomFromWKB(Spatial.asBinary(:geom), Spatial.srid(:geom)), 4326))");
        List list = (List) query.execute(geom);
        assertEquals("Wrong number of geometries 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) MultiPoint(org.postgis.MultiPoint) SamplePoint(org.datanucleus.samples.pggeometry.SamplePoint) Point(org.postgis.Point) Datastore(org.datanucleus.tests.annotations.Datastore)

Example 7 with Datastore

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

the class PgGeometrySpatialTest method testDistance.

@Datastore(POSTGRESQL)
public void testDistance() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Point point = new Point("SRID=4326;POINT(0 10)");
        Double distance = new Double(10.0);
        Query query = pm.newQuery(SamplePoint.class, "geom != null && Spatial.distance(geom, :point) == :distance");
        List list = (List) query.execute(point, distance);
        assertEquals("Wrong number of geometries with a distance of " + distance + " to a given point returned", 1, list.size());
        assertTrue("Point 1 should be in the list of geometries with a distance of " + distance + " to a given point", list.contains(getSamplePoint(1)));
        query = pm.newQuery(SamplePoint.class, "id == :id");
        query.setResult("Spatial.distance(geom, Spatial.geomFromText('POINT(0 10)', 4326))");
        query.setResultClass(Double.class);
        query.setUnique(true);
        Double distance_read = (Double) query.execute(new Long(getSamplePoint(1).getId()));
        assertEquals("Point 1 should be in the given distance from the given point", distance, distance_read);
    } finally {
        tx.commit();
    }
}
Also used : SamplePoint(org.datanucleus.samples.pggeometry.SamplePoint) 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 8 with Datastore

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

the class PgGeometrySpatialTest method testRelate.

@Datastore(POSTGRESQL)
public void testRelate() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        LineString lineString = new LineString("SRID=4326;LINESTRING(25 25,25 75)");
        // crosses
        String pattern = "T*T******";
        Query query = pm.newQuery(SampleLineString.class, "geom != null && Spatial.relate(geom, :lineString, :pattern)");
        List list = (List) query.execute(lineString, pattern);
        assertEquals("Wrong number of geometries which are related to a given linestring returned (crosses)", 1, list.size());
        assertTrue("LineString 1 should be in the list of geometries which are related to a given linestring (crosses)", list.contains(getSampleLineString(1)));
        query = pm.newQuery(SampleLineString.class, "id == :id");
        query.setResult("Spatial.relate(geom, Spatial.geomFromText('LINESTRING(25 25,25 75)', 4326), 'T*T******')");
        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 (relate mask T*T******)", 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) SampleLineString(org.datanucleus.samples.pggeometry.SampleLineString) MultiLineString(org.postgis.MultiLineString) LineString(org.postgis.LineString) Datastore(org.datanucleus.tests.annotations.Datastore)

Example 9 with Datastore

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

the class PgGeometrySpatialTest method testConvexHull.

@Datastore(POSTGRESQL)
public void testConvexHull() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Polygon convexHull = new Polygon("SRID=4326;POLYGON((110 10,120 25,110 45,100 25,110 10))");
        Query query = pm.newQuery(SampleLineString.class, "geom != null && Spatial.equals(Spatial.convexHull(geom), :convexHull)");
        List list = (List) query.execute(convexHull);
        assertEquals("Wrong number of geometries with a given convex hull returned", 1, list.size());
        assertTrue("LineSting 3 should be in the list of geometries with a given convex hull", list.contains(getSampleLineString(3)));
        query = pm.newQuery(SampleLineString.class, "id == :id");
        query.setResult("Spatial.convexHull(geom)");
        query.setUnique(true);
        Geometry convexHull_read = (Geometry) query.execute(new Long(getSampleLineString(3).getId()));
        assertEquals("Returned convex hull should be a polygon", "POLYGON", convexHull.getTypeString());
        assertEquals("Returned convex hull should have the given srid", 4326, convexHull.getSrid());
        assertTrue("First point of returned convex hull should be equal to given point", convexHull.getFirstPoint().equals(convexHull_read.getFirstPoint()));
    } 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) List(java.util.List) SamplePolygon(org.datanucleus.samples.pggeometry.SamplePolygon) Polygon(org.postgis.Polygon) MultiPolygon(org.postgis.MultiPolygon) Datastore(org.datanucleus.tests.annotations.Datastore)

Example 10 with Datastore

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

the class PgGeometrySpatialTest method testPointOnSurfaceMethod.

@Datastore(POSTGRESQL)
public void testPointOnSurfaceMethod() throws SQLException {
    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.getTypeString());
    } 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) 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