use of oracle.spatial.geometry.JGeometry in project tests by datanucleus.
the class JGeometrySpatialTest method testBuffer.
public void testBuffer() 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.within(geom, Spatial.buffer(:point, 1000.0))");
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(SampleGeometry.class, "id == :id");
query.setResult("Spatial.buffer(geom, 1000.0)");
query.setUnique(true);
JGeometry buffer = (JGeometry) query.execute(new Long(getSamplePoint(1).getId()));
assertEquals("Returned buffer should be a polygon", 3, buffer.getType());
assertEquals("Returned buffer should have the given srid", 4326, buffer.getSRID());
} finally {
tx.commit();
}
}
use of oracle.spatial.geometry.JGeometry in project tests by datanucleus.
the class JGeometrySpatialTest method testMLineFromWKB.
public void testMLineFromWKB() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
JGeometry geom = JGeometry.createLinearMultiLineString(new Object[] { new double[] { 0.0, 50.0, 100.0, 50.0 }, new double[] { 50.0, 0.0, 50.0, 100.0 }, new double[] { 100.0, 25.0, 120.0, 25.0, 110.0, 10.0, 110.0, 45.0 } }, 2, 4326);
Short n = new Short((short) 2);
Query query = pm.newQuery(SampleGeometry.class, "geom != null && Spatial.equals(geom, Spatial.geometryN(Spatial.mLineFromWKB(Spatial.asBinary(:geom), Spatial.srid(:geom)), :n))");
List list = (List) query.execute(geom, n);
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 oracle.spatial.geometry.JGeometry in project tests by datanucleus.
the class JGeometrySpatialTest method testEnvelope.
public void testEnvelope() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
int gtype = JGeometry.GTYPE_POLYGON;
int srid = 4326;
int[] elemInfo = new int[] { 1, 1003, 3 };
double[] ordinates = new double[] { 100.0, 10.0, 120.0, 45.0 };
JGeometry envelope = new JGeometry(gtype, srid, elemInfo, ordinates);
Query query = pm.newQuery(SampleGeometry.class, "id > 2000 && id < 3000 && Spatial.equals(Spatial.envelope(geom), :envelope)");
List list = (List) query.execute(envelope);
assertEquals("Wrong number of geometries with a given envelope returned", 1, list.size());
assertTrue("LineString 3 should be in the list of geometries with a given envelope", list.contains(getSampleLineString(3)));
query = pm.newQuery(SampleGeometry.class, "id == :id");
query.setResult("Spatial.envelope(geom)");
query.setUnique(true);
JGeometry envelope_read = (JGeometry) query.execute(new Long(getSampleLineString(3).getId()));
assertEquals("Returned envelope should be equal to a given envelope", envelope, envelope_read);
} finally {
tx.commit();
}
}
use of oracle.spatial.geometry.JGeometry in project tests by datanucleus.
the class JGeometrySpatialTest method testBoundary.
public void testBoundary() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
JGeometry boundary = JGeometry.createLinearLineString(new double[] { 75.0, 75.0, 100.0, 75.0, 100.0, 100.0, 75.0, 75.0 }, 2, 4326);
Query query = pm.newQuery(SampleGeometry.class, "id > 3000 && id < 4000 && 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(SampleGeometry.class, "id == :id");
query.setResult("Spatial.boundary(geom)");
query.setUnique(true);
JGeometry boundary_read = (JGeometry) 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();
}
}
use of oracle.spatial.geometry.JGeometry in project tests by datanucleus.
the class JGeometrySpatialTest method testWithin.
public void testWithin() throws SQLException {
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
JGeometry point = new JGeometry(30.0, 30.0, 4326);
Query query = pm.newQuery(SampleGeometry.class, "id > 3000 && id < 4000 && Spatial.within(:point, geom)");
List list = (List) query.execute(point);
assertEquals("Wrong number of geometries where a given point is within returned", 1, list.size());
assertTrue("Polygon 1 should be in the list of geometries where a given point is within", list.contains(getSamplePolygon(1)));
} finally {
tx.commit();
}
}
Aggregations