Search in sources :

Example 56 with Polygon

use of com.vividsolutions.jts.geom.Polygon in project tests by datanucleus.

the class JtsGeometryMySQLTest method testMbrEqual.

public void testMbrEqual() throws SQLException, ParseException {
    if (!runTestsForDatastore()) {
        return;
    }
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Polygon polygon = (Polygon) wktReader.read("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 && MySQL.mbrEqual(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)));
    } finally {
        tx.commit();
    }
}
Also used : Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) List(java.util.List) SamplePolygon(org.datanucleus.samples.jtsgeometry.SamplePolygon) Polygon(com.vividsolutions.jts.geom.Polygon)

Example 57 with Polygon

use of com.vividsolutions.jts.geom.Polygon in project tests by datanucleus.

the class JtsGeometryMySQLTest method testMbrOverlaps.

public void testMbrOverlaps() throws SQLException, ParseException {
    if (!runTestsForDatastore()) {
        return;
    }
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Polygon polygon = (Polygon) wktReader.read("POLYGON((10 10,50 10,50 50,10 50,10 10))");
        Query query = pm.newQuery(SamplePolygon.class, "geom != null && MySQL.mbrOverlaps(geom, :polygon)");
        List list = (List) query.execute(polygon);
        assertEquals("Wrong number of geometries which overlap a given linestring returned", 1, list.size());
        assertTrue("LineString 1 should be in the list of geometries which overlap a given linestring", list.contains(getSamplePolygon(1)));
    } finally {
        tx.commit();
    }
}
Also used : Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) List(java.util.List) SamplePolygon(org.datanucleus.samples.jtsgeometry.SamplePolygon) Polygon(com.vividsolutions.jts.geom.Polygon)

Example 58 with Polygon

use of com.vividsolutions.jts.geom.Polygon in project tests by datanucleus.

the class JtsGeometryMySQLTest method testMbrDisjoint.

public void testMbrDisjoint() throws SQLException, ParseException {
    if (!runTestsForDatastore()) {
        return;
    }
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Polygon polygon = (Polygon) wktReader.read("POLYGON((10 10,40 10,40 40,10 40,10 10))");
        Query query = pm.newQuery(SamplePolygon.class, "geom != null && MySQL.mbrDisjoint(geom, :polygon)");
        List list = (List) query.execute(polygon);
        assertEquals("Wrong number of geometries which are disjoint from a given polygon returned", 1, list.size());
        assertTrue("Polygon 2 should be in the list of geometries which are disjoint from a given polygon", list.contains(getSamplePolygon(2)));
    } finally {
        tx.commit();
    }
}
Also used : Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) List(java.util.List) SamplePolygon(org.datanucleus.samples.jtsgeometry.SamplePolygon) Polygon(com.vividsolutions.jts.geom.Polygon)

Example 59 with Polygon

use of com.vividsolutions.jts.geom.Polygon in project tests by datanucleus.

the class JtsGeometrySpatialTest method testIntersects.

public void testIntersects() throws SQLException, ParseException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Polygon polygon = (Polygon) wktReader.read("POLYGON((10 10,40 10,40 40,10 40,10 10))");
        Query query = pm.newQuery(SamplePolygon.class, "geom != null && geom.intersects(: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("geom.intersects(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.jtsgeometry.SamplePolygon) List(java.util.List) MultiPolygon(com.vividsolutions.jts.geom.MultiPolygon) SamplePolygon(org.datanucleus.samples.jtsgeometry.SamplePolygon) Polygon(com.vividsolutions.jts.geom.Polygon)

Example 60 with Polygon

use of com.vividsolutions.jts.geom.Polygon in project tests by datanucleus.

the class JtsGeometrySpatialTest method testConvexHull.

@Datastore(POSTGRESQL)
public void testConvexHull() throws SQLException, ParseException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Polygon convexHull = (Polygon) wktReader.read("POLYGON((110 10,120 25,110 45,100 25,110 10))");
        Query query = pm.newQuery(SampleLineString.class, "geom != null && geom.convexHull().equals(: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("geom.convexHull()");
        query.setUnique(true);
        Geometry convexHull_read = (Geometry) query.execute(new Long(getSampleLineString(3).getId()));
        convexHull.normalize();
        convexHull_read.normalize();
        assertTrue("Returned convex hull should be equal to the given polygon", convexHull_read.equalsExact(convexHull));
    } 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) 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)

Aggregations

Polygon (com.vividsolutions.jts.geom.Polygon)114 LinearRing (com.vividsolutions.jts.geom.LinearRing)50 MultiPolygon (com.vividsolutions.jts.geom.MultiPolygon)34 Test (org.junit.Test)32 Coordinate (com.vividsolutions.jts.geom.Coordinate)30 Point (com.vividsolutions.jts.geom.Point)29 PackedCoordinateSequence (com.vividsolutions.jts.geom.impl.PackedCoordinateSequence)27 ArrayList (java.util.ArrayList)26 RdfToRyaConversions.convertStatement (org.apache.rya.api.resolver.RdfToRyaConversions.convertStatement)24 Resource (org.openrdf.model.Resource)24 Statement (org.openrdf.model.Statement)24 URI (org.openrdf.model.URI)24 Value (org.openrdf.model.Value)24 ValueFactory (org.openrdf.model.ValueFactory)24 ContextStatementImpl (org.openrdf.model.impl.ContextStatementImpl)24 ValueFactoryImpl (org.openrdf.model.impl.ValueFactoryImpl)24 Geometry (com.vividsolutions.jts.geom.Geometry)22 LineString (com.vividsolutions.jts.geom.LineString)21 List (java.util.List)20 PersistenceManager (javax.jdo.PersistenceManager)15