Search in sources :

Example 36 with JGeometry

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();
    }
}
Also used : SampleGeometry(org.datanucleus.samples.jgeometry.SampleGeometry) Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager) JGeometry(oracle.spatial.geometry.JGeometry)

Example 37 with JGeometry

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();
    }
}
Also used : SampleGeometry(org.datanucleus.samples.jgeometry.SampleGeometry) Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager) JGeometry(oracle.spatial.geometry.JGeometry)

Example 38 with JGeometry

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();
    }
}
Also used : SampleGeometry(org.datanucleus.samples.jgeometry.SampleGeometry) Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager) JGeometry(oracle.spatial.geometry.JGeometry)

Example 39 with JGeometry

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);
    }
}
Also used : SQLException(java.sql.SQLException) JGeometry(oracle.spatial.geometry.JGeometry) STRUCT(oracle.sql.STRUCT) SQLException(java.sql.SQLException)

Example 40 with JGeometry

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);
}
Also used : JGeometry(oracle.spatial.geometry.JGeometry) Test(org.junit.Test)

Aggregations

JGeometry (oracle.spatial.geometry.JGeometry)65 PersistenceManager (javax.jdo.PersistenceManager)46 Transaction (javax.jdo.Transaction)46 List (java.util.List)37 Query (javax.jdo.Query)37 SampleGeometry (org.datanucleus.samples.jgeometry.SampleGeometry)25 Point (org.geolatte.geom.Point)8 ConverterException (ch.ehi.ili2db.converter.ConverterException)4 IomObject (ch.interlis.iom.IomObject)4 Iom_jObject (ch.interlis.iom_j.Iom_jObject)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 CrsId (org.geolatte.geom.crs.CrsId)2 SQLException (java.sql.SQLException)1 STRUCT (oracle.sql.STRUCT)1 SampleGeometry3D (org.datanucleus.samples.jgeometry.SampleGeometry3D)1 SampleGeometryM (org.datanucleus.samples.jgeometry.SampleGeometryM)1