use of org.postgis.LineString in project tests by datanucleus.
the class PgGeometrySpatialTest method testGeomCollFromText.
public void testGeomCollFromText() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
String wkt = "GEOMETRYCOLLECTION(POINT(10 10),LINESTRING(0 50, 100 50),POLYGON((25 25,75 25,75 75,25 75,25 25),(45 45,55 45,55 55,45 55,45 45)))";
Short srid = new Short((short) 4326);
Short n = new Short((short) 1);
Query query = pm.newQuery(SamplePoint.class, "geom != null && Spatial.equals(geom, Spatial.geometryN(Spatial.geomCollFromText(:wkt, :srid), :n))");
List list = (List) query.execute(wkt, srid, n);
assertEquals("Wrong number of geometries with a given wkt returned", 1, list.size());
assertTrue("Polygon 1 should be in the list of geometries with a given wkt", list.contains(getSamplePoint(1)));
} finally {
tx.commit();
}
}
use of org.postgis.LineString in project tests by datanucleus.
the class PgGeometrySpatialTest method testLineFromWKB.
public void testLineFromWKB() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
LineString geom = new LineString("SRID=4326;LINESTRING(50 0, 50 100)");
Query query = pm.newQuery(SampleLineString.class, "geom != null && Spatial.equals(geom, Spatial.lineFromWKB(Spatial.asBinary(:geom), Spatial.srid(:geom)))");
List list = (List) query.execute(geom);
assertEquals("Wrong number of geometries with a given wkb returned", 1, list.size());
assertTrue("LineString 2 should be in the list of geometries with a given wkb", list.contains(getSampleLineString(2)));
} finally {
tx.commit();
}
}
use of org.postgis.LineString 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();
}
}
use of org.postgis.LineString in project tests by datanucleus.
the class PgGeometrySpatialTest method testBoundary.
@Datastore(POSTGRESQL)
public void testBoundary() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
LineString boundary = new LineString("SRID=4326;LINESTRING(75 75,100 75,100 100,75 75)");
Query query = pm.newQuery(SamplePolygon.class, "geom != null && Spatial.equals(Spatial.boundary(geom), :boundary)");
List list = (List) query.execute(boundary);
assertEquals("Wrong number of geometries with a given boundary returned", 1, list.size());
assertTrue("Polygon 2 should be in the list of geometries with a given boundary", list.contains(getSamplePolygon(2)));
query = pm.newQuery(SamplePolygon.class, "id == :id");
query.setResult("Spatial.boundary(geom)");
query.setUnique(true);
Geometry boundary_read = (Geometry) query.execute(new Long(getSamplePolygon(2).getId()));
assertEquals("Boundary of Polygon 2 should be equal to a given boundary", boundary, boundary_read);
} finally {
tx.commit();
}
}
Aggregations