Search in sources :

Example 56 with JGeometry

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

the class JGeometrySpatialTest method testContains.

public void testContains() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        JGeometry point = new JGeometry(30.0, 30.0, 4326);
        Query query = pm.newQuery(SampleGeometry.class, "id > 3000 && id < 4000 && Spatial.contains(geom, :point)");
        List list = (List) query.execute(point);
        assertEquals("Wrong number of geometries which contain a given point returned", 1, list.size());
        assertTrue("Polygon 1 should be in the list of geometries which contain a given point", list.contains(getSamplePolygon(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 57 with JGeometry

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

the class JGeometrySpatialTest method testGeometryN.

public void testGeometryN() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Query query = pm.newQuery(SampleGeometry.class, "id > 7000 && id < 8000 && Spatial.geometryType(Spatial.geometryN(geom, 1)).toUpperCase() == 'ST_POINT'");
        List list = (List) query.execute();
        assertEquals("Wrong number of collections whose first geometry is equal to a given point returned", 2, list.size());
        assertTrue("Collection 1 should be in the list of collections whose first geometry is a point", list.contains(getSampleGeometryCollection(2)));
        assertTrue("Collection 2 should be in the list of collections whose first geometry is a point", list.contains(getSampleGeometryCollection(2)));
        query = pm.newQuery(SampleGeometry.class, "id == :id");
        query.setResult("Spatial.geometryN(geom, 1)");
        query.setUnique(true);
        JGeometry point_read = (JGeometry) query.execute(new Long(getSampleGeometryCollection(2).getId()));
        assertTrue("First geometry of Collection 2 should be a point", point_read.getType() == JGeometry.GTYPE_POINT);
    } 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 58 with JGeometry

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

the class JGeometrySpatialTest method testDisjoint.

public void testDisjoint() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        JGeometry polygon = JGeometry.createLinearPolygon(new Object[] { new double[] { 10.0, 10.0, 40.0, 10.0, 40.0, 40.0, 10.0, 40.0, 10.0, 10.0 } }, 2, 4326);
        Query query = pm.newQuery(SampleGeometry.class, "id > 3000 && id < 4000 && Spatial.disjoint(geom, :polygon)");
        List list = (List) query.execute(polygon);
        assertEquals("Wrong number of geometries which are disjoint from a given polygon returned", 1, list.size());
        assertTrue("Polygon 2 should be in the list of geometries which are disjoint from a given polygon", 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 59 with JGeometry

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

the class JGeometrySpatialTest method testPointOnSurfaceMethod.

public void testPointOnSurfaceMethod() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        double tolerance = 0.005;
        Query query = pm.newQuery(SampleGeometry.class, "id > 3000 && id < 4000 && Spatial.pointOnSurface(geom, :tolerance) != null");
        List list = (List) query.execute(tolerance);
        assertEquals("Wrong number of geometries with a point on the surface returned", 2, list.size());
        assertTrue("Polygon 1 should be in the list of geometries with a point on the surface", list.contains(getSamplePolygon(1)));
        assertTrue("Polygon 2 should be in the list of geometries with a point on the surface", list.contains(getSamplePolygon(2)));
        query = pm.newQuery(SampleGeometry.class, "id == :id");
        query.setResult("Spatial.pointOnSurface(geom, 0.005)");
        query.setUnique(true);
        JGeometry pointOnSurface = (JGeometry) query.execute(new Long(getSamplePolygon(1).getId()));
        assertNotNull("Polygon 1 should have a point on the surface", pointOnSurface);
        assertTrue("Returned geometry should be a point", pointOnSurface.getType() == JGeometry.GTYPE_POINT);
    } 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 60 with JGeometry

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

the class JGeometrySpatialTest method testEndPoint.

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