use of org.postgis.Point in project tests by datanucleus.
the class PgGeometryPostGISExtMappingTest method testBoxMapping.
public void testBoxMapping() throws SQLException {
if (!runTestsForDatastore()) {
return;
}
PGbox2d pgbox2d = new PGbox2d(new Point(10, 10), new Point(20, 20));
PGbox3d pgbox3d = new PGbox3d(new Point(20, 20, 100), new Point(30, 30, 100));
SampleBox sampleBox;
SampleBox sampleBox_read;
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
Object id = null;
try {
tx.begin();
sampleBox = new SampleBox(1001, "PGboxes", pgbox2d, pgbox3d);
pm.makePersistent(sampleBox);
id = JDOHelper.getObjectId(sampleBox);
sampleBox = (SampleBox) pm.detachCopy(sampleBox);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
pm = pmf.getPersistenceManager();
tx = pm.currentTransaction();
try {
tx.begin();
sampleBox_read = (SampleBox) pm.getObjectById(id, true);
assertEquals(sampleBox, sampleBox_read);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
use of org.postgis.Point 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.Point 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.Point in project tests by datanucleus.
the class PgGeometrySpatialTest method testUnion.
@Datastore(POSTGRESQL)
public void testUnion() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Point point = new Point("SRID=4326;POINT(50 50)");
MultiPoint union = new MultiPoint("SRID=4326;MULTIPOINT(10 10,50 50)");
Query query = pm.newQuery(SamplePoint.class, "geom != null && Spatial.asText(Spatial.union(geom, :point)) == Spatial.asText(:union)");
List list = (List) query.execute(point, union);
assertEquals("Wrong number of geometries whose union with a given point is equal to a given multipoint returned", 1, list.size());
assertTrue("Point 1 should be in the list of geometries whose union with a given point is equal to a given multipoint", list.contains(getSamplePoint(1)));
query = pm.newQuery(SamplePoint.class, "id == :id");
query.setResult("Spatial.union(geom, Spatial.geomFromText('POINT(50 50)', 4326))");
query.setUnique(true);
Geometry union_read = (Geometry) query.execute(new Long(getSamplePoint(1).getId()));
assertEquals("Returned union should be equal to the given multipoint", union, union_read);
} finally {
tx.commit();
}
}
use of org.postgis.Point in project tests by datanucleus.
the class PgGeometrySpatialTest method testIntersection.
@Datastore(POSTGRESQL)
public void testIntersection() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
LineString lineString = new LineString("SRID=4326;LINESTRING(25 25, 25 75)");
Point intersection = new Point("SRID=4326;POINT(25 50)");
Query query = pm.newQuery(SampleLineString.class, "geom != null && Spatial.asText(Spatial.intersection(geom, :lineString)) == Spatial.asText(:intersection)");
List list = (List) query.execute(lineString, intersection);
assertEquals("Wrong number of geometries which intersect a given linestring at a given point returned", 1, list.size());
assertTrue("LineSting 1 should be in the list of geometries which intersect a given linestring at a given point", list.contains(getSampleLineString(1)));
query = pm.newQuery(SampleLineString.class, "id == :id");
query.setResult("Spatial.intersection(geom, Spatial.geomFromText('LINESTRING(25 25, 25 75)', 4326))");
query.setUnique(true);
Geometry intersection_read = (Geometry) query.execute(new Long(getSampleLineString(1).getId()));
assertEquals("Returned intersection should be equal to the given point", intersection, intersection_read);
} finally {
tx.commit();
}
}
Aggregations