use of org.postgis.Geometry 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.Geometry in project tests by datanucleus.
the class PgGeometrySpatialTest method testSymDifference.
@Datastore(POSTGRESQL)
public void testSymDifference() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Polygon polygon = new Polygon("SRID=4326;POLYGON((75 75, 125 75, 125 100, 75 100, 75 75))");
MultiPolygon symDifference = new MultiPolygon("SRID=4326;MULTIPOLYGON(((100 75,100 100,125 100,125 75,100 75)),((100 100,75 75,75 100,100 100)))");
Query query = pm.newQuery(SamplePolygon.class, "geom != null && Spatial.equals(Spatial.symDifference(geom, :polygon), :symDifference)");
List list = (List) query.execute(polygon, symDifference);
assertEquals("Wrong number of geometries whose symDifference to a given polygon is equal to a given multipolygon returned", 1, list.size());
assertTrue("Polygon 2 should be in the list of geometries whose symDifference to a given polygon is equal to a given multipolygon", list.contains(getSamplePolygon(2)));
query = pm.newQuery(SamplePolygon.class, "id == :id");
query.setResult("Spatial.symDifference(geom, Spatial.geomFromText('POLYGON((75 75, 125 75, 125 100, 75 100, 75 75))', 4326))");
query.setUnique(true);
Geometry symDifference_read = (Geometry) query.execute(new Long(getSamplePolygon(2).getId()));
assertEquals("Returned symDifference should be equal to the given multipolygon", symDifference, symDifference_read);
} finally {
tx.commit();
}
}
use of org.postgis.Geometry 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();
}
}
use of org.postgis.Geometry in project tests by datanucleus.
the class PgGeometrySpatialTest method testPointN.
public void testPointN() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Point point = new Point("SRID=4326;POINT(110 10)");
Short n = new Short((short) 3);
Query query = pm.newQuery(SampleLineString.class, "geom != null && Spatial.asText(Spatial.pointN(geom, :n)) == Spatial.asText(:point)");
List list = (List) query.execute(n, point);
assertEquals("Wrong number of geometries whose point no. " + n + " equals a given point returned", 1, list.size());
assertTrue("LineString 3 should be in the list of geometries whose point no. " + n + " equals a given point", list.contains(getSampleLineString(3)));
query = pm.newQuery(SampleLineString.class, "id == :id");
query.setResult("Spatial.pointN(geom, 3)");
query.setUnique(true);
Geometry point_read = (Geometry) query.execute(new Long(getSampleLineString(3).getId()));
assertEquals("Returned third 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 testGeometryN.
public void testGeometryN() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Short n = new Short((short) 2);
LineString lineString = new LineString("SRID=4326;LINESTRING(50 0,50 100)");
Query query = pm.newQuery(SampleGeometryCollection.class, "geom != null && Spatial.asText(Spatial.geometryN(geom, :n)) == Spatial.asText(:lineString)");
List list = (List) query.execute(n, lineString);
assertEquals("Wrong number of collections whose " + n + "th geometry is equal to a given linestring returned", 1, list.size());
assertTrue("Collection 2 should be in the list of collections whose " + n + "th geometry is equal to a given linestring", list.contains(getSampleGeometryCollection(2)));
query = pm.newQuery(SampleGeometryCollection.class, "id == :id");
query.setResult("Spatial.geometryN(geom, 2)");
query.setUnique(true);
Geometry lineString_read = (Geometry) query.execute(new Long(getSampleGeometryCollection(2).getId()));
assertEquals("Second geometry of Collection 2 should be equal to the given linestring", lineString, lineString_read);
} finally {
tx.commit();
}
}
Aggregations