Search in sources :

Example 11 with JGeometry

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

the class JGeometrySpatialTest method testMPointFromWKB.

public void testMPointFromWKB() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        JGeometry geom = JGeometry.createMultiPoint(new Object[] { new double[] { 80.0, 76.0 }, new double[] { 90.0, 77.0 } }, 2, 4326);
        Query query = pm.newQuery(SampleGeometry.class, "id > 3000 && id < 4000 && Spatial.contains(geom, Spatial.mPointFromWKB(Spatial.asBinary(:geom), Spatial.srid(:geom)))");
        List list = (List) query.execute(geom);
        assertEquals("Wrong number of geometries whitch overlap a multipoint constructed from given wkb returned", 1, list.size());
        assertTrue("Polygon 2 should be in the list of geometries whitch overlap a multipoint constructed from given wkb", 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 12 with JGeometry

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

the class JGeometrySpatialTest method testRelate.

public void testRelate() 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);
        // crosses
        String pattern = "T*T******";
        Query query = pm.newQuery(SampleGeometry.class, "id > 2000 && id < 3000 && Spatial.relate(geom, :lineString, :pattern)");
        List list = (List) query.execute(lineString, pattern);
        assertEquals("Wrong number of geometries which are related to a given linestring returned (crosses)", 1, list.size());
        assertTrue("LineString 1 should be in the list of geometries which are related to a given linestring (crosses)", 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 13 with JGeometry

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

the class JGeometrySpatialTest method testPointN.

public void testPointN() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        JGeometry point = new JGeometry(110.0, 10.0, 4326);
        Short n = new Short((short) 3);
        Query query = pm.newQuery(SampleGeometry.class, "id > 2000 && id < 3000 && Spatial.numPoints(geom) >= :n && Spatial.equals(Spatial.pointN(geom, :n), :point)");
        List list = (List) query.execute(n, point);
        assertEquals("Wrong number of geometries whose point no. " + n + " equals a given point returned", 1, list.size());
        assertTrue("LineString 3 should be in the list of geometries whose point no. " + n + " equals a given point", list.contains(getSampleLineString(3)));
        query = pm.newQuery(SampleGeometry.class, "id == :id");
        query.setResult("Spatial.pointN(geom, 3)");
        query.setUnique(true);
        JGeometry point_read = (JGeometry) query.execute(new Long(getSampleLineString(3).getId()));
        assertEquals("Returned third point should be equal to the given point", point, point_read);
    } 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 14 with JGeometry

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

the class JGeometrySpatialTest method testIsEmpty.

public void testIsEmpty() 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.isEmpty(Spatial.intersection(geom, :linestring))");
        List list = (List) query.execute(lineString);
        assertEquals("Wrong number of geometries that do not intersect with a given linestring returned", 2, list.size());
        assertTrue("LineString 2 should be in the list of geometries that do not intersect with a given linestring", list.contains(getSampleLineString(2)));
        assertTrue("LineString 3 should be in the list of geometries that do not intersect with a given linestring", list.contains(getSampleLineString(3)));
    } 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 15 with JGeometry

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

the class JGeometrySpatialTest method testStartPoint.

public void testStartPoint() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        JGeometry point = new JGeometry(50.0, 0.0, 4326);
        Query query = pm.newQuery(SampleGeometry.class, "id > 2000 && id < 3000 && Spatial.equals(Spatial.startPoint(geom), :point)");
        List list = (List) query.execute(point);
        assertEquals("Wrong number of geometries with a given start point returned", 1, list.size());
        assertTrue("LineString 2 should be in the list of geometries with a given start point", list.contains(getSampleLineString(2)));
        query = pm.newQuery(SampleGeometry.class, "id == :id");
        query.setResult("Spatial.startPoint(geom)");
        query.setUnique(true);
        JGeometry point_read = (JGeometry) query.execute(new Long(getSampleLineString(2).getId()));
        assertEquals("Returned start point should be equal to the given point", point, point_read);
    } 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)

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