Search in sources :

Example 1 with Geometry

use of org.postgis.Geometry in project tests by datanucleus.

the class PgGeometrySpatialTest method testEndPoint.

public void testEndPoint() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Point point = new Point("SRID=4326;POINT(110 45)");
        Query query = pm.newQuery(SampleLineString.class, "geom != null && Spatial.equals(Spatial.endPoint(geom), :point)");
        List list = (List) query.execute(point);
        assertEquals("Wrong number of geometries with a given end point returned", 1, list.size());
        assertTrue("LineString 3 should be in the list of geometries with a given end point", list.contains(getSampleLineString(3)));
        query = pm.newQuery(SampleLineString.class, "id == :id");
        query.setResult("Spatial.endPoint(geom)");
        query.setUnique(true);
        Geometry point_read = (Geometry) query.execute(new Long(getSampleLineString(3).getId()));
        assertEquals("Returned end point should be equal to the given point", point, point_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) List(java.util.List) MultiPoint(org.postgis.MultiPoint) SamplePoint(org.datanucleus.samples.pggeometry.SamplePoint) Point(org.postgis.Point)

Example 2 with Geometry

use of org.postgis.Geometry 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)

Example 3 with Geometry

use of org.postgis.Geometry 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 4 with Geometry

use of org.postgis.Geometry 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)

Example 5 with Geometry

use of org.postgis.Geometry in project tests by datanucleus.

the class PgGeometrySpatialTest method testEnvelope.

public void testEnvelope() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Polygon envelope = new Polygon("SRID=4326;POLYGON((100 10,120 10,120 45,100 45,100 10))");
        Query query = pm.newQuery(SampleLineString.class, "geom != null && Spatial.equals(Spatial.envelope(geom), :envelope)");
        List list = (List) query.execute(envelope);
        assertEquals("Wrong number of geometries with a given envelope returned", 1, list.size());
        assertTrue("LineString 3 should be in the list of geometries with a given envelope", list.contains(getSampleLineString(3)));
        query = pm.newQuery(SampleLineString.class, "id == :id");
        query.setResult("Spatial.envelope(geom)");
        query.setUnique(true);
        Geometry envelope_read = (Geometry) query.execute(new Long(getSampleLineString(3).getId()));
        assertEquals("Returned envelope should be equal to a given envelope (geometry type)", envelope.getType(), envelope_read.getType());
        assertEquals("Returned envelope should be equal to a given envelope (srid)", envelope.getSrid(), envelope_read.getSrid());
        assertEquals("Returned envelope should be equal to a given envelope (no. points)", envelope.numPoints(), envelope_read.numPoints());
        assertTrue("Returned envelope should be equal to a given envelope (minx, miny)", envelope.getPoint(0).equals(envelope_read.getPoint(0)));
        assertTrue("Returned envelope should be equal to a given envelope (maxx, maxy)", envelope.getPoint(2).equals(envelope_read.getPoint(2)));
    } 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)

Aggregations

List (java.util.List)16 PersistenceManager (javax.jdo.PersistenceManager)16 Query (javax.jdo.Query)16 Transaction (javax.jdo.Transaction)16 Geometry (org.postgis.Geometry)16 SampleLineString (org.datanucleus.samples.pggeometry.SampleLineString)10 SamplePolygon (org.datanucleus.samples.pggeometry.SamplePolygon)9 Datastore (org.datanucleus.tests.annotations.Datastore)9 SamplePoint (org.datanucleus.samples.pggeometry.SamplePoint)7 MultiPoint (org.postgis.MultiPoint)7 Point (org.postgis.Point)7 LineString (org.postgis.LineString)5 MultiLineString (org.postgis.MultiLineString)5 MultiPolygon (org.postgis.MultiPolygon)4 Polygon (org.postgis.Polygon)4 SampleGeometryCollection (org.datanucleus.samples.pggeometry.SampleGeometryCollection)1