use of org.postgis.Geometry in project tests by datanucleus.
the class PgGeometrySpatialTest method testStartPoint.
public void testStartPoint() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Point point = new Point("SRID=4326;POINT(50 0)");
Query query = pm.newQuery(SampleLineString.class, "geom != null && Spatial.equals(Spatial.startPoint(geom), :point)");
List list = (List) query.execute(point);
assertEquals("Wrong number of geometries with a given start point returned", 1, list.size());
assertTrue("LineString 2 should be in the list of geometries with a given start point", list.contains(getSampleLineString(2)));
query = pm.newQuery(SampleLineString.class, "id == :id");
query.setResult("Spatial.startPoint(geom)");
query.setUnique(true);
Geometry point_read = (Geometry) query.execute(new Long(getSampleLineString(2).getId()));
assertEquals("Returned start 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 testExteriorRingMethod.
public void testExteriorRingMethod() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
LineString exteriorRing = new LineString("SRID=4326;LINESTRING(25 25,75 25,75 75,25 75,25 25)");
Query query = pm.newQuery(SamplePolygon.class, "geom != null && Spatial.asText(Spatial.exteriorRing(geom)) == Spatial.asText(:exteriorRing)");
List list = (List) query.execute(exteriorRing);
assertEquals("Wrong number of geometries with a given exterior ring returned", 1, list.size());
assertTrue("Polygon 1 should be in the list of geometries with a given exterior ring", list.contains(getSamplePolygon(1)));
query = pm.newQuery(SamplePolygon.class, "id == :id");
query.setResult("Spatial.exteriorRing(geom)");
query.setUnique(true);
Geometry exteriorRing_read = (Geometry) query.execute(new Long(getSamplePolygon(1).getId()));
assertEquals("Exterior ring of Polygon 1 should be equal to the given linestring", exteriorRing, exteriorRing_read);
} finally {
tx.commit();
}
}
use of org.postgis.Geometry in project tests by datanucleus.
the class PgGeometrySpatialTest method testBuffer.
@Datastore(POSTGRESQL)
public void testBuffer() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Point point = new Point("SRID=4326;POINT(0 0)");
Query query = pm.newQuery(SamplePoint.class, "geom != null && Spatial.within(geom, Spatial.buffer(:point, 20))");
List list = (List) query.execute(point);
assertEquals("Wrong number of geometries which are within the buffer of a given point returned", 1, list.size());
assertTrue("Point 1 should be in the list of geometries which are within the buffer of a given point", list.contains(getSamplePoint(1)));
query = pm.newQuery(SamplePoint.class, "id == :id");
query.setResult("Spatial.buffer(geom, 20)");
query.setUnique(true);
Geometry buffer = (Geometry) query.execute(new Long(getSamplePoint(1).getId()));
assertEquals("Returned buffer should be a polygon", "POLYGON", buffer.getTypeString());
assertEquals("Returned buffer should have the given srid", 4326, buffer.getSrid());
assertTrue("First point of returned buffer should have to be in a given distance from Point 1", buffer.getFirstPoint().distance(point) >= 20.0);
} finally {
tx.commit();
}
}
use of org.postgis.Geometry in project tests by datanucleus.
the class PgGeometrySpatialTest method testCentroid.
@Datastore(POSTGRESQL)
public void testCentroid() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Point centroid = new Point("SRID=4326;POINT(50 50)");
Query query = pm.newQuery(SamplePolygon.class, "geom != null && Spatial.asText(Spatial.centroid(geom)) == Spatial.asText(:centroid)");
List list = (List) query.execute(centroid);
assertEquals("Wrong number of geometries with a given centroid returned", 1, list.size());
assertTrue("Polygon 1 should be in the list of geometries with a given centroid", list.contains(getSamplePolygon(1)));
query = pm.newQuery(SamplePolygon.class, "id == :id");
query.setResult("Spatial.centroid(geom)");
query.setUnique(true);
Geometry centroid_read = (Geometry) query.execute(new Long(getSamplePolygon(1).getId()));
assertEquals("Given point shoul be centroid of Polygon 1", centroid, centroid_read);
} finally {
tx.commit();
}
}
use of org.postgis.Geometry in project tests by datanucleus.
the class PgGeometrySpatialTest method testInteriorRingNMethod.
public void testInteriorRingNMethod() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Short n = new Short((short) 1);
LineString interiorRing = new LineString("SRID=4326;LINESTRING(45 45,55 45,55 55,45 55,45 45)");
Query query = pm.newQuery(SamplePolygon.class, "geom != null && Spatial.asText(Spatial.interiorRingN(geom, :n)) == Spatial.asText(:interiorRing)");
List list = (List) query.execute(n, interiorRing);
assertEquals("Wrong number of geometries whose " + n + "th interior ring is equal to a given linestring returned", 1, list.size());
assertTrue("Polygon 1 should be in the list of geometries whose " + n + "th interior ring is equal to a given linestring", list.contains(getSamplePolygon(1)));
query = pm.newQuery(SamplePolygon.class, "id == :id");
query.setResult("Spatial.interiorRingN(geom, 1)");
query.setUnique(true);
Geometry interiorRing_read = (Geometry) query.execute(new Long(getSamplePolygon(1).getId()));
assertEquals("First interior ring of Polygon 1 should be equal to the given linestring", interiorRing, interiorRing_read);
} finally {
tx.commit();
}
}
Aggregations