use of org.postgis.LineString in project tests by datanucleus.
the class PgGeometryMappingTest method testLineStringMapping.
public void testLineStringMapping() throws SQLException {
if (!runTestsForDatastore()) {
return;
}
LineString lineString = new LineString("SRID=4326;LINESTRING(0 50,100 50)");
SampleLineString sampleLineString;
SampleLineString sampleLineString_read;
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
Object id = null;
try {
tx.begin();
sampleLineString = new SampleLineString(2001, "LineString 1", lineString);
pm.makePersistent(sampleLineString);
id = JDOHelper.getObjectId(sampleLineString);
sampleLineString = (SampleLineString) pm.detachCopy(sampleLineString);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
pm = pmf.getPersistenceManager();
tx = pm.currentTransaction();
try {
tx.begin();
sampleLineString_read = (SampleLineString) pm.getObjectById(id, true);
assertEquals(sampleLineString, sampleLineString_read);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
use of org.postgis.LineString in project tests by datanucleus.
the class PgGeometrySpatialTest method testIsEmpty.
@Datastore(POSTGRESQL)
public void testIsEmpty() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
LineString lineString = new LineString("SRID=4326;LINESTRING(25 25, 25 75)");
Query query = pm.newQuery(SampleLineString.class, "geom != null && Spatial.isEmpty(Spatial.intersection(geom, :linestring))");
List list = (List) query.execute(lineString);
assertEquals("Wrong number of geometries that do not intersect with a given linestring returned", 2, list.size());
assertTrue("LineString 2 should be in the list of geometries that do not intersect with a given linestring", list.contains(getSampleLineString(2)));
assertTrue("LineString 3 should be in the list of geometries that do not intersect with a given linestring", list.contains(getSampleLineString(3)));
query = pm.newQuery(SampleLineString.class, "geom != null");
query.setResult("Spatial.isEmpty(Spatial.intersection(geom, Spatial.geomFromText('LINESTRING(25 25, 25 75)', 4326))) AS isEmpty");
query.setResultClass(Boolean.class);
list = (List) query.execute();
assertEquals("Wrong number of geometries returned", 3, list.size());
assertEquals("The intersection of LineString 1 with a given linestring should not be empty", false, ((Boolean) list.get(0)).booleanValue());
assertEquals("The intersection of LineString 2 with a given linestring should be empty", true, ((Boolean) list.get(1)).booleanValue());
assertEquals("The intersection of LineString 3 with a given linestring should be empty", true, ((Boolean) list.get(2)).booleanValue());
} finally {
tx.commit();
}
}
use of org.postgis.LineString in project tests by datanucleus.
the class PgGeometrySpatialTest method testCrosses.
@Datastore(POSTGRESQL)
public void testCrosses() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
LineString lineString = new LineString("SRID=4326;LINESTRING(25 25,25 75)");
Query query = pm.newQuery(SampleLineString.class, "geom != null && Spatial.crosses(:lineString, geom)");
List list = (List) query.execute(lineString);
assertEquals("Wrong number of geometries which are crossed by a given linestring returned", 1, list.size());
assertTrue("LineString 1 should be in the list of geometries which are crossed by a given linestring", list.contains(getSampleLineString(1)));
query = pm.newQuery(SampleLineString.class, "id == :id");
query.setResult("Spatial.crosses(Spatial.geomFromText('LINESTRING(25 25,25 75)', 4326), geom)");
query.setResultClass(Boolean.class);
query.setUnique(true);
Boolean equals = (Boolean) query.execute(new Long(getSampleLineString(1).getId()));
assertEquals("LineString 1 should be crossed by the given linestring", true, equals.booleanValue());
} finally {
tx.commit();
}
}
use of org.postgis.LineString 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();
}
}
use of org.postgis.LineString 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