use of oracle.spatial.geometry.JGeometry in project tests by datanucleus.
the class JGeometrySpatialTest method testDistance.
public void testDistance() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
JGeometry point = new JGeometry(10.0, 10.0, 4326);
Query query = pm.newQuery(SampleGeometry.class, "id > 1000 && id < 2000 && Spatial.distance(geom, :point) > 0.0");
List list = (List) query.execute(point);
assertEquals("Wrong number of geometries with a distance > 0.0 to a given point returned", 1, list.size());
assertTrue("Point 2 should be in the list of geometries with a distance > 0 to a given point", list.contains(getSamplePoint(2)));
query = pm.newQuery(SampleGeometry.class, "id == :id");
query.setResult("Spatial.distance(geom, Spatial.geomFromText('POINT(10.0 10.0)', 4326))");
query.setResultClass(Double.class);
query.setUnique(true);
Double distance_read = (Double) query.execute(new Long(getSamplePoint(2).getId()));
assertTrue("Point 2 should be in a distance > 0.0 to the given point", distance_read.doubleValue() > 0.0);
} finally {
tx.commit();
}
}
use of oracle.spatial.geometry.JGeometry in project tests by datanucleus.
the class JGeometrySpatialTest method testAsBinary.
public void testAsBinary() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
JGeometry point = JGeometry.createPoint(new double[] { 10.0, 10.0 }, 2, 4326);
Query query = pm.newQuery(SampleGeometry.class, "id > 1000 && id < 2000 && Spatial.equals(Spatial.pointFromWKB(Spatial.asBinary(geom), Spatial.srid(geom)), :point)");
List list = (List) query.execute(point);
assertEquals("Wrong number of geometries with a given wkt returned", 1, list.size());
assertTrue("Point 1 should be in the list of geometries with a given wkt", list.contains(getSamplePoint(1)));
} finally {
tx.commit();
}
}
use of oracle.spatial.geometry.JGeometry in project tests by datanucleus.
the class JGeometryMappingTest method testMultiLineStringMapping.
public void testMultiLineStringMapping() throws SQLException {
if (!runTestsForDatastore()) {
return;
}
JGeometry multiLineString = JGeometry.createLinearMultiLineString(new Object[] { new double[] { 0, 50, 100, 50 }, new double[] { 50, 0, 50, 100 }, new double[] { 100, 25, 120, 25, 110, 10, 110, 45 } }, 2, 4326);
SampleGeometry sampleMultiLineString;
SampleGeometry sampleMultiLineString_read;
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
Object id = null;
try {
tx.begin();
sampleMultiLineString = new SampleGeometry(5001, "MultiLineString", multiLineString);
pm.makePersistent(sampleMultiLineString);
id = JDOHelper.getObjectId(sampleMultiLineString);
sampleMultiLineString = (SampleGeometry) pm.detachCopy(sampleMultiLineString);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
pm = pmf.getPersistenceManager();
tx = pm.currentTransaction();
try {
tx.begin();
sampleMultiLineString_read = (SampleGeometry) pm.getObjectById(id, true);
assertEquals(sampleMultiLineString, sampleMultiLineString_read);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
use of oracle.spatial.geometry.JGeometry in project tests by datanucleus.
the class JGeometryMappingTest method testPointMapping.
public void testPointMapping() throws SQLException {
if (!runTestsForDatastore()) {
return;
}
JGeometry point = new JGeometry(10.0, 10.0, 4326);
SampleGeometry samplePoint;
SampleGeometry samplePoint_read;
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
Object id = null;
try {
tx.begin();
samplePoint = new SampleGeometry(1001, "Point 1", point);
pm.makePersistent(samplePoint);
id = JDOHelper.getObjectId(samplePoint);
samplePoint = (SampleGeometry) pm.detachCopy(samplePoint);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
pm = pmf.getPersistenceManager();
tx = pm.currentTransaction();
try {
tx.begin();
samplePoint_read = (SampleGeometry) pm.getObjectById(id, true);
assertEquals(samplePoint, samplePoint_read);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
use of oracle.spatial.geometry.JGeometry in project tests by datanucleus.
the class JGeometryMappingTest method testGeometryCollectionMapping.
public void testGeometryCollectionMapping() throws SQLException {
if (!runTestsForDatastore()) {
return;
}
int gtype = JGeometry.GTYPE_COLLECTION;
int srid = 4326;
// Polygons with holes don't seem to work in GeometryCollections!
// int[] elemInfo = {1,1,1,3,2,1,7,1003,1,17,2003,1};
// double[] ordinates = {10,10,0,50,100,50,25,25,75,25,75,75,25,75,25,25,45,45,45,55,55,55,55,45,45,45};
int[] elemInfo = { 1, 1, 1, 3, 2, 1, 7, 1003, 1 };
double[] ordinates = { 10, 10, 0, 50, 100, 50, 25, 25, 75, 25, 75, 75, 25, 75, 25, 25 };
JGeometry geometryCollection = new JGeometry(gtype, srid, elemInfo, ordinates);
SampleGeometry sampleGeometryCollection;
SampleGeometry sampleGeometryCollection_read;
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
Object id = null;
try {
tx.begin();
sampleGeometryCollection = new SampleGeometry(7001, "Collection 1", geometryCollection);
pm.makePersistent(sampleGeometryCollection);
id = JDOHelper.getObjectId(sampleGeometryCollection);
sampleGeometryCollection = (SampleGeometry) pm.detachCopy(sampleGeometryCollection);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
pm = pmf.getPersistenceManager();
tx = pm.currentTransaction();
try {
tx.begin();
sampleGeometryCollection_read = (SampleGeometry) pm.getObjectById(id, true);
assertEquals(sampleGeometryCollection, sampleGeometryCollection_read);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
Aggregations