Search in sources :

Example 26 with JGeometry

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

the class JGeometrySpatialTest method testGeomFromWKB.

public void testGeomFromWKB() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        JGeometry geom = new JGeometry(10.0, 10.0, 4326);
        Query query = pm.newQuery(SampleGeometry.class, "geom != null && Spatial.equals(geom, Spatial.geomFromWKB(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("Point 1 should be in the list of geometries with a given wkb", 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 27 with JGeometry

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

the class JGeometrySpatialTest method testDifference.

public void testDifference() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        JGeometry polygon = JGeometry.createLinearPolygon(new Object[] { new double[] { 20.0, 20.0, 30.0, 20.0, 30.0, 30.0, 20.0, 30.0, 20.0, 20.0 } }, 2, 4326);
        Query query = pm.newQuery(SampleGeometry.class, "id > 3000 && id < 4000 && Spatial.difference(geom, :polygon) != null");
        List list = (List) query.execute(polygon);
        assertEquals("Wrong number of geometries whose difference from a given polygon is not null returned", 2, list.size());
        assertTrue("Polygon 1 should be in the list of geometries whose difference from a given polygon is not null", list.contains(getSamplePolygon(1)));
        assertTrue("Polygon 2 should be in the list of geometries whose difference from a given polygon is not null", list.contains(getSamplePolygon(2)));
        query = pm.newQuery(SampleGeometry.class, "id == :id");
        query.setResult("Spatial.difference(geom, Spatial.geomFromText('POLYGON((20.0 20.0,30.0 20.0,30.0 30.0,20.0 30.0,20.0 20.0))', 4326))");
        query.setUnique(true);
        JGeometry difference_read = (JGeometry) query.execute(new Long(getSamplePolygon(2).getId()));
        assertTrue("Returned difference should be a polygon", difference_read.getType() == JGeometry.GTYPE_POLYGON);
    } 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 28 with JGeometry

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

the class JGeometrySpatialTest method testExteriorRingMethod.

public void testExteriorRingMethod() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        Query query = pm.newQuery(SampleGeometry.class, "id > 3000 && id < 4000 && Spatial.exteriorRing(geom) != null");
        List list = (List) query.execute();
        assertEquals("Wrong number of geometries whith have an exterior ring returned", 2, list.size());
        assertTrue("Polygon 1 should be in the list of geometries with an exterior ring", list.contains(getSamplePolygon(1)));
        assertTrue("Polygon 2 should be in the list of geometries with an exterior ring", list.contains(getSamplePolygon(2)));
        query = pm.newQuery(SampleGeometry.class, "id == :id");
        query.setResult("Spatial.exteriorRing(geom)");
        query.setUnique(true);
        JGeometry exteriorRing_read = (JGeometry) query.execute(new Long(getSamplePolygon(1).getId()));
        assertTrue("Exterior ring of Polygon 1 should be a line or curve JGeometry.GTYPE_CURVE", exteriorRing_read.getType() == JGeometry.GTYPE_CURVE);
    } 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 29 with JGeometry

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

the class JGeometrySpatialTest method getSampleGeometryCollection.

private SampleGeometry getSampleGeometryCollection(int num) throws SQLException {
    int gtype = JGeometry.GTYPE_COLLECTION;
    int srid = 4326;
    int[] elemInfo;
    double[] ordinates;
    switch(num) {
        case 0:
            return new SampleGeometry(7100, "Collection 0", null);
        case 1:
            elemInfo = new int[] { 1, 1, 1, 3, 2, 1, 7, 1003, 1 };
            ordinates = new double[] { 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 };
            return new SampleGeometry(7001, "Collection 1", new JGeometry(gtype, srid, elemInfo, ordinates));
        case 2:
            elemInfo = new int[] { 1, 1, 1, 3, 2, 1, 7, 1003, 1 };
            ordinates = new double[] { 75.0, 75.0, 50.0, 0.0, 50.0, 100.0, 75.0, 75.0, 100.0, 75.0, 100.0, 100.0, 75.0, 75.0 };
            return new SampleGeometry(7002, "Collection 2", new JGeometry(gtype, srid, elemInfo, ordinates));
        case 3:
            elemInfo = new int[] { 1, 2, 1 };
            ordinates = new double[] { 100.0, 25.0, 120.0, 25.0, 110.0, 10.0, 110.0, 45.0 };
            return new SampleGeometry(7003, "Collection 3", new JGeometry(gtype, srid, elemInfo, ordinates));
    }
    return null;
}
Also used : SampleGeometry(org.datanucleus.samples.jgeometry.SampleGeometry) JGeometry(oracle.spatial.geometry.JGeometry)

Example 30 with JGeometry

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

the class JGeometrySpatialTest method testMPolyFromWKB.

public void testMPolyFromWKB() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        int gtype = JGeometry.GTYPE_MULTIPOLYGON;
        int srid = 4326;
        int[] elemInfo = { 1, 1003, 1, 11, 1003, 1 };
        double[] ordinates = { 25.0, 25.0, 75.0, 25.0, 75.0, 75.0, 25.0, 75.0, 25.0, 25.0, 75.0, 75.0, 100.0, 75.0, 100.0, 100.0, 75.0, 75.0 };
        JGeometry geom = new JGeometry(gtype, srid, elemInfo, ordinates);
        Short n = new Short((short) 2);
        Query query = pm.newQuery(SampleGeometry.class, "id > 3000 && id < 4000 && Spatial.equals(geom, Spatial.geometryN(Spatial.mPolyFromWKB(Spatial.asBinary(:geom), Spatial.srid(:geom)), 2))");
        List list = (List) query.execute(geom, n);
        assertEquals("Wrong number of geometries with a given wkb returned", 1, list.size());
        assertTrue("Polygon 2 should be in the list of geometries with a 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)

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