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();
}
}
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();
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations