Search in sources :

Example 31 with JGeometry

use of oracle.spatial.geometry.JGeometry in project tests by datanucleus.

the class JGeometrySpatialTest method testCrosses.

public void testCrosses() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        JGeometry lineString = JGeometry.createLinearLineString(new double[] { 25.0, 25.0, 25.0, 75.0 }, 2, 4326);
        Query query = pm.newQuery(SampleGeometry.class, "id > 2000 && id < 3000 && Spatial.crosses(geom, :lineString)");
        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)));
    } finally {
        tx.commit();
    }
}
Also used : Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) JGeometry(oracle.spatial.geometry.JGeometry) List(java.util.List)

Example 32 with JGeometry

use of oracle.spatial.geometry.JGeometry in project tests by datanucleus.

the class JGeometrySpatialTest method testTouches.

public void testTouches() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        JGeometry point = new JGeometry(75.0, 75.0, 4326);
        Query query = pm.newQuery(SampleGeometry.class, "id > 3000 && id < 4000 && Spatial.touches(:point, geom)");
        List list = (List) query.execute(point);
        assertEquals("Wrong number of geometries which are touched by a given point returned", 2, list.size());
        assertTrue("Polygon 1 should be in the list of geometries which are touched by a given point", list.contains(getSamplePolygon(1)));
        assertTrue("Polygon 2 should be in the list of geometries which are touched by a given point", list.contains(getSamplePolygon(2)));
    } finally {
        tx.commit();
    }
}
Also used : Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) JGeometry(oracle.spatial.geometry.JGeometry) List(java.util.List)

Example 33 with JGeometry

use of oracle.spatial.geometry.JGeometry in project tests by datanucleus.

the class JGeometry3dMMappingTest method testPoint3DMapping.

public void testPoint3DMapping() throws SQLException {
    if (!runTestsForDatastore()) {
        return;
    }
    JGeometry point = new JGeometry(10.0, 10.0, 100.0, 4326);
    SampleGeometryM samplePoint;
    SampleGeometryM samplePoint_read;
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    Object id = null;
    try {
        tx.begin();
        samplePoint = new SampleGeometryM(1201, "Point 3D", point);
        pm.makePersistent(samplePoint);
        id = JDOHelper.getObjectId(samplePoint);
        samplePoint = (SampleGeometryM) pm.detachCopy(samplePoint);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
    pm = pmf.getPersistenceManager();
    tx = pm.currentTransaction();
    try {
        tx.begin();
        samplePoint_read = (SampleGeometryM) pm.getObjectById(id, true);
        assertEquals(samplePoint, samplePoint_read);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
}
Also used : Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager) JGeometry(oracle.spatial.geometry.JGeometry) SampleGeometryM(org.datanucleus.samples.jgeometry.SampleGeometryM)

Example 34 with JGeometry

use of oracle.spatial.geometry.JGeometry in project tests by datanucleus.

the class JGeometry3dMMappingTest method testPointMMapping.

public void testPointMMapping() throws SQLException {
    if (!runTestsForDatastore()) {
        return;
    }
    // point with measure in third dimension
    int gtype = 3301;
    int srid = 4326;
    int[] elemInfo = { 1, 1, 1 };
    double[] ordinates = { 10.0, 10.0, 100.0 };
    JGeometry point = new JGeometry(gtype, srid, elemInfo, ordinates);
    SampleGeometry3D samplePoint;
    SampleGeometry3D samplePoint_read;
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    Object id = null;
    try {
        tx.begin();
        samplePoint = new SampleGeometry3D(1101, "Point with measure", point);
        pm.makePersistent(samplePoint);
        id = JDOHelper.getObjectId(samplePoint);
        samplePoint = (SampleGeometry3D) pm.detachCopy(samplePoint);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
    pm = pmf.getPersistenceManager();
    tx = pm.currentTransaction();
    try {
        tx.begin();
        samplePoint_read = (SampleGeometry3D) pm.getObjectById(id, true);
        assertEquals(samplePoint, samplePoint_read);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
}
Also used : Transaction(javax.jdo.Transaction) PersistenceManager(javax.jdo.PersistenceManager) JGeometry(oracle.spatial.geometry.JGeometry) SampleGeometry3D(org.datanucleus.samples.jgeometry.SampleGeometry3D)

Example 35 with JGeometry

use of oracle.spatial.geometry.JGeometry in project tests by datanucleus.

the class JGeometryMappingTest method testMultiPointMapping.

public void testMultiPointMapping() throws SQLException {
    if (!runTestsForDatastore()) {
        return;
    }
    JGeometry multipoint = JGeometry.createMultiPoint(new Object[] { new double[] { 10, 10 }, new double[] { 75, 75 } }, 2, 4326);
    SampleGeometry sampleMultiPoint;
    SampleGeometry sampleMultiPoint_read;
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    Object id = null;
    try {
        tx.begin();
        sampleMultiPoint = new SampleGeometry(4001, "MultiPoint", multipoint);
        pm.makePersistent(sampleMultiPoint);
        id = JDOHelper.getObjectId(sampleMultiPoint);
        sampleMultiPoint = (SampleGeometry) pm.detachCopy(sampleMultiPoint);
        tx.commit();
    } finally {
        if (tx.isActive()) {
            tx.rollback();
        }
        pm.close();
    }
    pm = pmf.getPersistenceManager();
    tx = pm.currentTransaction();
    try {
        tx.begin();
        sampleMultiPoint_read = (SampleGeometry) pm.getObjectById(id, true);
        assertEquals(sampleMultiPoint, sampleMultiPoint_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)

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