Search in sources :

Example 16 with Polygon

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

the class PgGeometrySpatialTest method testIntersects.

public void testIntersects() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Polygon polygon = new Polygon("SRID=4326;POLYGON((10 10,40 10,40 40,10 40,10 10))");
        Query query = pm.newQuery(SamplePolygon.class, "geom != null && Spatial.intersects(geom, :polygon)");
        List list = (List) query.execute(polygon);
        assertEquals("Wrong number of geometries which intersect with a given polygon returned", 1, list.size());
        assertTrue("Polygon 1 should be in the list of geometries which intersect with a given polygon", list.contains(getSamplePolygon(1)));
        query = pm.newQuery(SamplePolygon.class, "id == :id");
        query.setResult("Spatial.intersects(geom, Spatial.geomFromText('POLYGON((10 10,40 10,40 40,10 40,10 10))', 4326))");
        query.setResultClass(Boolean.class);
        query.setUnique(true);
        Boolean equals = (Boolean) query.execute(new Long(getSamplePolygon(1).getId()));
        assertEquals("Polygon 1 should intersect the given polygon", 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) SamplePolygon(org.datanucleus.samples.pggeometry.SamplePolygon) Polygon(org.postgis.Polygon) MultiPolygon(org.postgis.MultiPolygon)

Example 17 with Polygon

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

the class PgGeometrySpatialTest method testSymDifference.

@Datastore(POSTGRESQL)
public void testSymDifference() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Polygon polygon = new Polygon("SRID=4326;POLYGON((75 75, 125 75, 125 100, 75 100, 75 75))");
        MultiPolygon symDifference = new MultiPolygon("SRID=4326;MULTIPOLYGON(((100 75,100 100,125 100,125 75,100 75)),((100 100,75 75,75 100,100 100)))");
        Query query = pm.newQuery(SamplePolygon.class, "geom != null && Spatial.equals(Spatial.symDifference(geom, :polygon), :symDifference)");
        List list = (List) query.execute(polygon, symDifference);
        assertEquals("Wrong number of geometries whose symDifference to a given polygon is equal to a given multipolygon returned", 1, list.size());
        assertTrue("Polygon 2 should be in the list of geometries whose symDifference to a given polygon is equal to a given multipolygon", list.contains(getSamplePolygon(2)));
        query = pm.newQuery(SamplePolygon.class, "id == :id");
        query.setResult("Spatial.symDifference(geom, Spatial.geomFromText('POLYGON((75 75, 125 75, 125 100, 75 100, 75 75))', 4326))");
        query.setUnique(true);
        Geometry symDifference_read = (Geometry) query.execute(new Long(getSamplePolygon(2).getId()));
        assertEquals("Returned symDifference should be equal to the given multipolygon", symDifference, symDifference_read);
    } finally {
        tx.commit();
    }
}
Also used : Geometry(org.postgis.Geometry) Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) MultiPolygon(org.postgis.MultiPolygon) 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 18 with Polygon

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

the class PgGeometrySpatialTest method testEquals.

public void testEquals() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Polygon polygon = new Polygon("SRID=4326;POLYGON((25 25,75 25,75 75,25 75,25 25),(45 45,55 45,55 55,45 55,45 45))");
        Query query = pm.newQuery(SamplePolygon.class, "geom != null && Spatial.equals(geom, :polygon)");
        List list = (List) query.execute(polygon);
        assertEquals("Wrong number of geometries which are equal to a given polygon returned", 1, list.size());
        assertTrue("Polygon 1 should be in the list of geometries which are equal to a given polygon", list.contains(getSamplePolygon(1)));
        query = pm.newQuery(SamplePolygon.class, "id == :id");
        query.setResult("Spatial.equals(geom, Spatial.geomFromText('POLYGON((25 25,75 25,75 75,25 75,25 25),(45 45,55 45,55 55,45 55,45 45))', 4326))");
        query.setResultClass(Boolean.class);
        query.setUnique(true);
        Boolean equals = (Boolean) query.execute(new Long(getSamplePolygon(1).getId()));
        assertEquals("Polygon 1 should be equal to the given polygon", 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) SamplePolygon(org.datanucleus.samples.pggeometry.SamplePolygon) Polygon(org.postgis.Polygon) MultiPolygon(org.postgis.MultiPolygon)

Example 19 with Polygon

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

the class PgGeometrySpatialTest method testOverlaps.

public void testOverlaps() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Polygon polygon = new Polygon("SRID=4326;POLYGON((10 10,50 10,50 50,10 50,10 10))");
        Query query = pm.newQuery(SamplePolygon.class, "geom != null && Spatial.overlaps(geom, :polygon)");
        List list = (List) query.execute(polygon);
        assertEquals("Wrong number of geometries which overlap a given polygon returned", 1, list.size());
        assertTrue("LineString 1 should be in the list of geometries which overlap a given polygon", list.contains(getSamplePolygon(1)));
        query = pm.newQuery(SamplePolygon.class, "id == :id");
        query.setResult("Spatial.overlaps(geom, Spatial.geomFromText('POLYGON((10 10,50 10,50 50,10 50,10 10))', 4326))");
        query.setResultClass(Boolean.class);
        query.setUnique(true);
        Boolean equals = (Boolean) query.execute(new Long(getSamplePolygon(1).getId()));
        assertEquals("Polygon 1 should overlap the given polygon", 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) SamplePolygon(org.datanucleus.samples.pggeometry.SamplePolygon) Polygon(org.postgis.Polygon) MultiPolygon(org.postgis.MultiPolygon)

Aggregations

Polygon (org.postgis.Polygon)19 PersistenceManager (javax.jdo.PersistenceManager)14 Transaction (javax.jdo.Transaction)14 SamplePolygon (org.datanucleus.samples.pggeometry.SamplePolygon)14 List (java.util.List)13 Query (javax.jdo.Query)13 MultiPolygon (org.postgis.MultiPolygon)10 Geometry (org.postgis.Geometry)4 LinearRing (org.postgis.LinearRing)4 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)3 Datastore (org.datanucleus.tests.annotations.Datastore)3 Test (org.junit.Test)3 GeographyPolygon (org.umlg.sqlg.gis.GeographyPolygon)3 BaseTest (org.umlg.sqlg.test.BaseTest)3 SampleLineString (org.datanucleus.samples.pggeometry.SampleLineString)2 LineString (org.postgis.LineString)2 IOException (java.io.IOException)1 Connection (java.sql.Connection)1 Statement (java.sql.Statement)1 SampleMultiPolygon (org.datanucleus.samples.pggeometry.SampleMultiPolygon)1