Search in sources :

Example 16 with JGeometry

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

the class JGeometrySpatialTest method testGeomCollFromWKB.

public void testGeomCollFromWKB() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        int gtype = JGeometry.GTYPE_COLLECTION;
        int srid = 4326;
        int[] elemInfo = { 1, 1, 1, 3, 2, 1, 7, 1003, 1 };
        double[] ordinates = { 10.0, 10.0, 0.0, 50.0, 100.0, 50.0, 25.0, 25.0, 75.0, 25.0, 75.0, 75.0, 25.0, 75.0, 25.0, 25.0 };
        JGeometry geom = new JGeometry(gtype, srid, elemInfo, ordinates);
        Query query = pm.newQuery(SampleGeometry.class, "id > 7000 && id < 8000 && Spatial.equals(geom, Spatial.geomCollFromWKB(Spatial.asBinary(:geom), Spatial.srid(:geom)))");
        List list = (List) query.execute(geom);
        assertEquals("Wrong number of geometries with a given wkb returned", 1, list.size());
        assertTrue("Collection 1 should be in the list of geometries with a given wkb", list.contains(getSampleGeometryCollection(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 17 with JGeometry

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

the class JGeometrySpatialTest method testEquals.

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

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

the class JGeometrySpatialTest method testCentroid.

public void testCentroid() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Query query = pm.newQuery(SampleGeometry.class, "id > 3000 && id < 4000 && Spatial.centroid(geom) != null");
        List list = (List) query.execute();
        assertEquals("Wrong number of geometries whith have a centroid returned", 2, list.size());
        assertTrue("Polygon 1 should be in the list of geometries with a centroid", list.contains(getSamplePolygon(1)));
        assertTrue("Polygon 2 should be in the list of geometries with a centroid", list.contains(getSamplePolygon(2)));
        query = pm.newQuery(SampleGeometry.class, "id == :id");
        query.setResult("Spatial.centroid(geom)");
        query.setUnique(true);
        JGeometry centroid_read = (JGeometry) query.execute(new Long(getSamplePolygon(1).getId()));
        assertTrue("Centroid of Polygon 1 should be a point", centroid_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 19 with JGeometry

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

the class JGeometrySpatialTest method testConvexHull.

public void testConvexHull() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Query query = pm.newQuery(SampleGeometry.class, "id > 2000 && id < 3000 && !Spatial.isEmpty(Spatial.convexHull(geom))");
        List list = (List) query.execute();
        assertEquals("Wrong number of geometries for which a convex hull can be calculated returned", 1, list.size());
        assertTrue("LineSting 3 should be in the list of geometries with a given convex hull", list.contains(getSampleLineString(3)));
        query = pm.newQuery(SampleGeometry.class, "id == :id");
        query.setResult("Spatial.convexHull(geom)");
        query.setUnique(true);
        JGeometry convexHull_read = (JGeometry) query.execute(new Long(getSampleLineString(3).getId()));
        assertEquals("Returned convex hull should be of type polygon", JGeometry.GTYPE_POLYGON, convexHull_read.getType());
    } 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 20 with JGeometry

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

the class JGeometrySpatialTest method testLineFromWKB.

public void testLineFromWKB() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        JGeometry geom = JGeometry.createLinearLineString(new double[] { 0, 50, 100, 50 }, 2, 4326);
        Query query = pm.newQuery(SampleGeometry.class, "geom != null && Spatial.equals(geom, Spatial.lineFromWKB(Spatial.asBinary(:geom), Spatial.srid(:geom)))");
        List list = (List) query.execute(geom);
        assertEquals("Wrong number of geometries with a given wkb returned", 1, list.size());
        assertTrue("LineString 1 should be in the list of geometries with a given wkb", 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)

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