use of oracle.spatial.geometry.JGeometry in project tests by datanucleus.
the class JGeometryMappingTest method testPolygonMapping.
public void testPolygonMapping() throws SQLException {
if (!runTestsForDatastore()) {
return;
}
JGeometry polygon = JGeometry.createLinearPolygon(new Object[] { new double[] { 25, 25, 75, 25, 75, 75, 25, 75, 25, 25 }, new double[] { 45, 45, 55, 45, 55, 55, 45, 55, 45, 45 } }, 2, 4326);
SampleGeometry samplePolygon;
SampleGeometry samplePolygon_read;
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
Object id = null;
try {
tx.begin();
samplePolygon = new SampleGeometry(3001, "Polygon 1", polygon);
pm.makePersistent(samplePolygon);
id = JDOHelper.getObjectId(samplePolygon);
samplePolygon = (SampleGeometry) pm.detachCopy(samplePolygon);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
pm = pmf.getPersistenceManager();
tx = pm.currentTransaction();
try {
tx.begin();
samplePolygon_read = (SampleGeometry) pm.getObjectById(id, true);
assertEquals(samplePolygon, samplePolygon_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 testLineStringMapping.
public void testLineStringMapping() throws SQLException {
if (!runTestsForDatastore()) {
return;
}
JGeometry lineString = JGeometry.createLinearLineString(new double[] { 0, 50, 100, 50 }, 2, 4326);
SampleGeometry sampleLineString;
SampleGeometry sampleLineString_read;
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
Object id = null;
try {
tx.begin();
sampleLineString = new SampleGeometry(2001, "LineString 1", lineString);
pm.makePersistent(sampleLineString);
id = JDOHelper.getObjectId(sampleLineString);
sampleLineString = (SampleGeometry) pm.detachCopy(sampleLineString);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
pm = pmf.getPersistenceManager();
tx = pm.currentTransaction();
try {
tx.begin();
sampleLineString_read = (SampleGeometry) pm.getObjectById(id, true);
assertEquals(sampleLineString, sampleLineString_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 testMultiPolygonMapping.
public void testMultiPolygonMapping() throws SQLException {
if (!runTestsForDatastore()) {
return;
}
int gtype = JGeometry.GTYPE_MULTIPOLYGON;
int srid = 4326;
int[] elemInfo = { 1, 1003, 1, 11, 2003, 1, 21, 1003, 1 };
double[] ordinates = { 25, 25, 75, 25, 75, 75, 25, 75, 25, 25, 45, 45, 45, 55, 55, 55, 55, 45, 45, 45, 75, 75, 100, 75, 100, 100, 75, 75 };
JGeometry multiPolygon = new JGeometry(gtype, srid, elemInfo, ordinates);
SampleGeometry sampleMultiPolygon;
SampleGeometry sampleMultiPolygon_read;
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
Object id = null;
try {
tx.begin();
sampleMultiPolygon = new SampleGeometry(6001, "MultiPolygon", multiPolygon);
pm.makePersistent(sampleMultiPolygon);
id = JDOHelper.getObjectId(sampleMultiPolygon);
sampleMultiPolygon = (SampleGeometry) pm.detachCopy(sampleMultiPolygon);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
pm = pmf.getPersistenceManager();
tx = pm.currentTransaction();
try {
tx.begin();
sampleMultiPolygon_read = (SampleGeometry) pm.getObjectById(id, true);
assertEquals(sampleMultiPolygon, sampleMultiPolygon_read);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
use of oracle.spatial.geometry.JGeometry in project querydsl by querydsl.
the class JGeometryType method setValue.
@Override
public void setValue(PreparedStatement st, int startIndex, Geometry value) throws SQLException {
try {
JGeometry geo = JGeometryConverter.convert(value);
STRUCT struct = JGeometry.store(st.getConnection(), geo);
st.setObject(startIndex, struct);
} catch (Exception e) {
throw new SQLException(e);
}
}
use of oracle.spatial.geometry.JGeometry in project querydsl by querydsl.
the class JGeometryConverterTest method multiLineString.
@Test
public void multiLineString() {
MultiLineString multiLineString = (org.geolatte.geom.MultiLineString) Wkt.fromWkt("MULTILINESTRING (" + "(30 10, 40 40, 20 40, 10 20, 30 10), " + "(20 30, 35 35, 30 20, 20 30))");
JGeometry geo = JGeometryConverter.convert(multiLineString);
double[] line1 = new double[] { 30, 10, 40, 40, 20, 40, 10, 20, 30, 10 };
double[] line2 = new double[] { 20, 30, 35, 35, 30, 20, 20, 30 };
JGeometry geo2 = JGeometry.createLinearMultiLineString(new Object[] { line1, line2 }, multiLineString.getCoordinateDimension(), multiLineString.getSRID());
// System.err.println(Arrays.toString(geo.getElemInfo()));
// System.err.println(Arrays.toString(geo.getOrdinatesArray()));
// System.err.println(Arrays.toString(geo2.getElemInfo()));
// System.err.println(Arrays.toString(geo2.getOrdinatesArray()));
assertEquals(geo2, geo);
}
Aggregations