Search in sources :

Example 21 with JGeometry

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

the class JGeometrySpatialTest method testBuffer.

public void testBuffer() 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.within(geom, Spatial.buffer(:point, 1000.0))");
        List list = (List) query.execute(point);
        assertEquals("Wrong number of geometries which are within the buffer of a given point returned", 1, list.size());
        assertTrue("Point 1 should be in the list of geometries which are within the buffer of a given point", list.contains(getSamplePoint(1)));
        query = pm.newQuery(SampleGeometry.class, "id == :id");
        query.setResult("Spatial.buffer(geom, 1000.0)");
        query.setUnique(true);
        JGeometry buffer = (JGeometry) query.execute(new Long(getSamplePoint(1).getId()));
        assertEquals("Returned buffer should be a polygon", 3, buffer.getType());
        assertEquals("Returned buffer should have the given srid", 4326, buffer.getSRID());
    } 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 22 with JGeometry

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

the class JGeometrySpatialTest method testMLineFromWKB.

public void testMLineFromWKB() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        JGeometry geom = JGeometry.createLinearMultiLineString(new Object[] { new double[] { 0.0, 50.0, 100.0, 50.0 }, new double[] { 50.0, 0.0, 50.0, 100.0 }, new double[] { 100.0, 25.0, 120.0, 25.0, 110.0, 10.0, 110.0, 45.0 } }, 2, 4326);
        Short n = new Short((short) 2);
        Query query = pm.newQuery(SampleGeometry.class, "geom != null && Spatial.equals(geom, Spatial.geometryN(Spatial.mLineFromWKB(Spatial.asBinary(:geom), Spatial.srid(:geom)), :n))");
        List list = (List) query.execute(geom, n);
        assertEquals("Wrong number of geometries with a given wkb returned", 1, list.size());
        assertTrue("LineString 2 should be in the list of geometries with a given wkb", list.contains(getSampleLineString(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 23 with JGeometry

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

the class JGeometrySpatialTest method testEnvelope.

public void testEnvelope() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        int gtype = JGeometry.GTYPE_POLYGON;
        int srid = 4326;
        int[] elemInfo = new int[] { 1, 1003, 3 };
        double[] ordinates = new double[] { 100.0, 10.0, 120.0, 45.0 };
        JGeometry envelope = new JGeometry(gtype, srid, elemInfo, ordinates);
        Query query = pm.newQuery(SampleGeometry.class, "id > 2000 && id < 3000 && Spatial.equals(Spatial.envelope(geom), :envelope)");
        List list = (List) query.execute(envelope);
        assertEquals("Wrong number of geometries with a given envelope returned", 1, list.size());
        assertTrue("LineString 3 should be in the list of geometries with a given envelope", list.contains(getSampleLineString(3)));
        query = pm.newQuery(SampleGeometry.class, "id == :id");
        query.setResult("Spatial.envelope(geom)");
        query.setUnique(true);
        JGeometry envelope_read = (JGeometry) query.execute(new Long(getSampleLineString(3).getId()));
        assertEquals("Returned envelope should be equal to a given envelope", envelope, envelope_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 24 with JGeometry

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

the class JGeometrySpatialTest method testBoundary.

public void testBoundary() throws SQLException {
    PersistenceManager pm = pmf.getPersistenceManager();
    Transaction tx = pm.currentTransaction();
    try {
        tx.begin();
        JGeometry boundary = JGeometry.createLinearLineString(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(Spatial.boundary(geom), :boundary)");
        List list = (List) query.execute(boundary);
        assertEquals("Wrong number of geometries with a given boundary returned", 1, list.size());
        assertTrue("Polygon 2 should be in the list of geometries with a given boundary", list.contains(getSamplePolygon(2)));
        query = pm.newQuery(SampleGeometry.class, "id == :id");
        query.setResult("Spatial.boundary(geom)");
        query.setUnique(true);
        JGeometry boundary_read = (JGeometry) query.execute(new Long(getSamplePolygon(2).getId()));
        assertEquals("Boundary of Polygon 2 should be equal to a given boundary", boundary, boundary_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 25 with JGeometry

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

the class JGeometrySpatialTest method testWithin.

public void testWithin() 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.within(:point, geom)");
        List list = (List) query.execute(point);
        assertEquals("Wrong number of geometries where a given point is within returned", 1, list.size());
        assertTrue("Polygon 1 should be in the list of geometries where a given point is within", 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)

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