Search in sources :

Example 61 with JGeometry

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

Example 62 with JGeometry

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();
    }
}
Also used : Transaction(javax.jdo.Transaction) Query(javax.jdo.Query) PersistenceManager(javax.jdo.PersistenceManager) JGeometry(oracle.spatial.geometry.JGeometry) List(java.util.List)

Example 63 with JGeometry

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

Example 64 with JGeometry

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

Example 65 with JGeometry

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();
    }
}
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