Search in sources :

Example 6 with JGeometry

use of oracle.spatial.geometry.JGeometry in project querydsl by querydsl.

the class JGeometryConverter method convert.

private static JGeometry convert(MultiLineString geometry) {
    int srid = geometry.getSRID();
    int dim = geometry.getCoordinateDimension();
    double[] points = getPoints(geometry.getPoints());
    int[] elemInfo = new int[geometry.getNumGeometries() * 3];
    int offset = 0;
    int pointOffset = 1;
    for (int i = 0; i < geometry.getNumGeometries(); i++) {
        elemInfo[offset++] = pointOffset;
        elemInfo[offset++] = 2;
        elemInfo[offset++] = 1;
        pointOffset += geometry.getGeometryN(i).getNumPoints() * dim;
    }
    int gtype = dim * 1000 + (geometry.isMeasured() ? dim : 0) * 100 + GTYPE_MULTICURVE;
    return new JGeometry(gtype, srid, elemInfo, points);
}
Also used : JGeometry(oracle.spatial.geometry.JGeometry) Point(org.geolatte.geom.Point)

Example 7 with JGeometry

use of oracle.spatial.geometry.JGeometry in project ili2db by claeis.

the class OracleColumnConverter method toIomPolyline.

@Override
public IomObject toIomPolyline(Object geomobj, String sqlAttrName, boolean is3D) throws java.sql.SQLException, ConverterException {
    JGeometry geometry = JGeometry.load((oracle.sql.STRUCT) geomobj);
    if (geometry.getType() != JGeometry.GTYPE_MULTICURVE) {
        throw new ConverterException("unexpected GTYPE (" + OracleUtility.gtype2str(geometry.getType()) + ") in attribute " + sqlAttrName);
    } else {
        int dim = geometry.getDimensions();
        boolean isCurrentValue3D = (dim == 3);
        if (is3D != isCurrentValue3D) {
            throw new ConverterException("unexpected dimension (" + Integer.toString(dim) + ") in attribute " + sqlAttrName);
        } else {
            int[] elev = geometry.getElemInfo();
            double[] ordv = geometry.getOrdinatesArray();
            final int SDO_STARTING_OFFSET = 0;
            final int SDO_ETYPE = 1;
            final int SDO_INTERPRETATION = 2;
            final int NEXT_TRIPLET = 3;
            final int COMPOUND_LINESTRING = 4;
            final int LINESTRING = 2;
            final int STRAIGHT = 1;
            final int ARC = 2;
            int elei = 0;
            if (elev[elei + SDO_ETYPE] != COMPOUND_LINESTRING) {
                throw new ConverterException("unexpected SDO_ETYPE (" + Integer.toString(elev[elei + SDO_ETYPE]) + ") in attribute " + sqlAttrName);
            } else {
                elei += NEXT_TRIPLET;
                IomObject polylineValue = new Iom_jObject("POLYLINE", null);
                // unclipped polyline, add one sequence
                IomObject sequence = polylineValue.addattrobj("sequence", "SEGMENTS");
                while (elei < elev.length) {
                    if (elev[elei + SDO_ETYPE] != LINESTRING) {
                        throw new ConverterException("unexpected SDO_ETYPE (" + Integer.toString(elev[elei + SDO_ETYPE]) + ") in attribute " + sqlAttrName);
                    } else {
                        if (elev[elei + SDO_INTERPRETATION] == STRAIGHT) {
                            int start = elev[elei + SDO_STARTING_OFFSET] - 1;
                            int end;
                            if (elei + NEXT_TRIPLET >= elev.length) {
                                end = ordv.length;
                            } else {
                                end = elev[elei + NEXT_TRIPLET + SDO_STARTING_OFFSET] - 1;
                            }
                            for (int i = start; i < end; ) {
                                // add control point
                                IomObject coordValue = sequence.addattrobj("segment", "COORD");
                                coordValue.setattrvalue("C1", Double.toString(ordv[i]));
                                coordValue.setattrvalue("C2", Double.toString(ordv[i + 1]));
                                if (isCurrentValue3D) {
                                    coordValue.setattrvalue("C3", Double.toString(ordv[i + 2]));
                                    i += 3;
                                } else {
                                    i += 2;
                                }
                            }
                        } else if (elev[elei + SDO_INTERPRETATION] == ARC) {
                            int start = elev[elei + SDO_STARTING_OFFSET] - 1;
                            int end;
                            if (elei + NEXT_TRIPLET >= elev.length) {
                                end = ordv.length;
                            } else {
                                end = elev[elei + NEXT_TRIPLET + SDO_STARTING_OFFSET] - 1;
                            }
                            for (int i = start; i < end; ) {
                                // add control point
                                IomObject coordValue = sequence.addattrobj("segment", "ARC");
                                coordValue.setattrvalue("A1", Double.toString(ordv[i]));
                                coordValue.setattrvalue("A2", Double.toString(ordv[i + 1]));
                                if (isCurrentValue3D) {
                                    // no A3 in XTF!
                                    i += 3;
                                } else {
                                    i += 2;
                                }
                                coordValue.setattrvalue("C1", Double.toString(ordv[i]));
                                coordValue.setattrvalue("C2", Double.toString(ordv[i + 1]));
                                if (isCurrentValue3D) {
                                    coordValue.setattrvalue("C3", Double.toString(ordv[i + 2]));
                                    i += 3;
                                } else {
                                    i += 2;
                                }
                            }
                        } else {
                            throw new ConverterException("unexpected SDO_INTERPRETATION (" + Integer.toString(elev[elei + SDO_INTERPRETATION]) + ") in attribute " + sqlAttrName);
                        }
                    }
                    elei += NEXT_TRIPLET;
                }
                return polylineValue;
            }
        }
    }
}
Also used : ConverterException(ch.ehi.ili2db.converter.ConverterException) IomObject(ch.interlis.iom.IomObject) JGeometry(oracle.spatial.geometry.JGeometry) Iom_jObject(ch.interlis.iom_j.Iom_jObject)

Example 8 with JGeometry

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

the class JGeometrySpatialTest method testIntersects.

public void testIntersects() 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.intersects(geom, :polygon)");
        List list = (List) query.execute(polygon);
        assertEquals("Wrong number of geometries which intersect with a given polygon returned", 1, list.size());
        assertTrue("Polygon 1 should be in the list of geometries which intersect with a given polygon", 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 9 with JGeometry

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

the class JGeometrySpatialTest method testOverlaps.

public void testOverlaps() 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, 50.0, 10.0, 50.0, 50.0, 10.0, 50.0, 10.0, 10.0 } }, 2, 4326);
        Query query = pm.newQuery(SampleGeometry.class, "id > 3000 && id < 4000 && Spatial.overlaps(geom, :polygon)");
        List list = (List) query.execute(polygon);
        assertEquals("Wrong number of geometries which overlap a given polygon returned", 1, list.size());
        assertTrue("LineString 1 should be in the list of geometries which overlap a given polygon", 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 10 with JGeometry

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

the class JGeometrySpatialTest method testSymDifference.

public void testSymDifference() 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.symDifference(geom, :polygon) != null");
        List list = (List) query.execute(polygon);
        assertEquals("Wrong number of geometries whose symDifference to a given polygon is not null returned", 2, list.size());
        assertTrue("Polygon 1 should be in the list of geometries whose symDifference to a given polygon is not null", list.contains(getSamplePolygon(1)));
        assertTrue("Polygon 2 should be in the list of geometries whose symDifference to a given polygon is not null", list.contains(getSamplePolygon(2)));
        query = pm.newQuery(SampleGeometry.class, "id == :id");
        query.setResult("Spatial.symDifference(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 symDifference_read = (JGeometry) query.execute(new Long(getSamplePolygon(1).getId()));
        assertTrue("Returned symDifference should be a multipolygon", symDifference_read.getType() == JGeometry.GTYPE_MULTIPOLYGON);
    } 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