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