Search in sources :

Example 21 with ConverterException

use of ch.ehi.ili2db.converter.ConverterException in project ili2db by claeis.

the class OracleColumnConverter method fromIomCoord.

@Override
public java.lang.Object fromIomCoord(IomObject value, int srid, boolean is3D) throws java.sql.SQLException, ConverterException {
    if (value != null) {
        String c1 = value.getattrvalue("C1");
        String c2 = value.getattrvalue("C2");
        String c3 = value.getattrvalue("C3");
        double[] ordArray = { 0, 0, 0 };
        ordArray[0] = Double.parseDouble(c1);
        ordArray[1] = Double.parseDouble(c2);
        JGeometry geom = null;
        if (is3D) {
            if (c3 == null) {
                throw new ConverterException("unexpected dimension");
            } else {
                ordArray[2] = Double.parseDouble(c3);
                geom = JGeometry.createPoint(ordArray, 3, 0);
            }
        } else {
            geom = JGeometry.createPoint(ordArray, 2, 0);
        }
        return JGeometry.store(geom, conn);
    }
    return null;
}
Also used : ConverterException(ch.ehi.ili2db.converter.ConverterException) JGeometry(oracle.spatial.geometry.JGeometry)

Example 22 with ConverterException

use of ch.ehi.ili2db.converter.ConverterException in project ili2db by claeis.

the class OracleColumnConverter method toIomSurface.

@Override
public IomObject toIomSurface(Object geomobj, String sqlAttrName, boolean is3D) throws java.sql.SQLException, ConverterException {
    JGeometry geometry = JGeometry.load((oracle.sql.STRUCT) geomobj);
    if (geometry.getType() != JGeometry.GTYPE_POLYGON) {
        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;
            // (must be specified in counterclockwise order)
            final int EXTERIOR_POLYGON_RING = 1005;
            // (must be specified in clockwise order)
            final int INTERIOR_POLYGON_RING = 2005;
            final int LINESTRING = 2;
            final int STRAIGHT = 1;
            final int ARC = 2;
            int elei = 0;
            IomObject multisurface = new Iom_jObject("MULTISURFACE", null);
            IomObject surface = multisurface.addattrobj("surface", "SURFACE");
            while (elei < elev.length) {
                if (elev[elei + SDO_ETYPE] != EXTERIOR_POLYGON_RING && elev[elei + SDO_ETYPE] != INTERIOR_POLYGON_RING) {
                    throw new ConverterException("unexpected SDO_ETYPE (" + Integer.toString(elev[elei + SDO_ETYPE]) + ") in attribute " + sqlAttrName);
                } else {
                    int nTriplet = elev[elei + SDO_INTERPRETATION];
                    elei += NEXT_TRIPLET;
                    IomObject boundary = surface.addattrobj("boundary", "BOUNDARY");
                    IomObject polylineValue = boundary.addattrobj("polyline", "POLYLINE");
                    IomObject sequence = polylineValue.addattrobj("sequence", "SEGMENTS");
                    for (int iTriplet = 0; iTriplet < nTriplet; iTriplet++) {
                        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 multisurface;
        }
    }
}
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 23 with ConverterException

use of ch.ehi.ili2db.converter.ConverterException in project ili2db by claeis.

the class PostgisColumnConverter method toIomCoord.

@Override
public IomObject toIomCoord(Object geomobj, String sqlAttrName, boolean is3D) throws SQLException, ConverterException {
    byte[] bv = (byte[]) geomobj;
    Wkb2iox conv = new Wkb2iox();
    try {
        return conv.read(bv);
    } catch (ParseException e) {
        throw new ConverterException(e);
    }
}
Also used : ConverterException(ch.ehi.ili2db.converter.ConverterException) ParseException(com.vividsolutions.jts.io.ParseException) Wkb2iox(ch.interlis.iox_j.wkb.Wkb2iox)

Example 24 with ConverterException

use of ch.ehi.ili2db.converter.ConverterException in project ili2db by claeis.

the class PostgisColumnConverter method toIomMultiPolyline.

@Override
public IomObject toIomMultiPolyline(Object geomobj, String sqlAttrName, boolean is3D) throws SQLException, ConverterException {
    byte[] bv = (byte[]) geomobj;
    // String v=((org.postgresql.util.PGobject)geomobj).getValue();
    // byte bv[]=WKBReader.hexToBytes(v);
    Wkb2iox conv = new Wkb2iox();
    try {
        return conv.read(bv);
    } catch (ParseException e) {
        throw new ConverterException(e);
    }
}
Also used : ConverterException(ch.ehi.ili2db.converter.ConverterException) ParseException(com.vividsolutions.jts.io.ParseException) Wkb2iox(ch.interlis.iox_j.wkb.Wkb2iox)

Example 25 with ConverterException

use of ch.ehi.ili2db.converter.ConverterException in project ili2db by claeis.

the class PostgisColumnConverter method toIomSurface.

@Override
public IomObject toIomSurface(Object geomobj, String sqlAttrName, boolean is3D) throws SQLException, ConverterException {
    byte[] bv = (byte[]) geomobj;
    Wkb2iox conv = new Wkb2iox();
    try {
        return conv.read(bv);
    } catch (ParseException e) {
        throw new ConverterException(e);
    }
}
Also used : ConverterException(ch.ehi.ili2db.converter.ConverterException) ParseException(com.vividsolutions.jts.io.ParseException) Wkb2iox(ch.interlis.iox_j.wkb.Wkb2iox)

Aggregations

ConverterException (ch.ehi.ili2db.converter.ConverterException)32 ParseException (com.vividsolutions.jts.io.ParseException)17 IomObject (ch.interlis.iom.IomObject)8 IoxException (ch.interlis.iox.IoxException)8 Wkb2iox (ch.interlis.iox_j.wkb.Wkb2iox)6 SQLException (java.sql.SQLException)6 Iom_jObject (ch.interlis.iom_j.Iom_jObject)5 AttributeDef (ch.interlis.ili2c.metamodel.AttributeDef)3 BlackboxType (ch.interlis.ili2c.metamodel.BlackboxType)3 CoordType (ch.interlis.ili2c.metamodel.CoordType)3 EnumerationType (ch.interlis.ili2c.metamodel.EnumerationType)3 SurfaceOrAreaType (ch.interlis.ili2c.metamodel.SurfaceOrAreaType)3 SurfaceType (ch.interlis.ili2c.metamodel.SurfaceType)3 Viewable (ch.interlis.ili2c.metamodel.Viewable)3 JGeometry (oracle.spatial.geometry.JGeometry)3 ArrayMapping (ch.ehi.ili2db.mapping.ArrayMapping)2 MultiLineMapping (ch.ehi.ili2db.mapping.MultiLineMapping)2 MultiPointMapping (ch.ehi.ili2db.mapping.MultiPointMapping)2 MultiSurfaceMapping (ch.ehi.ili2db.mapping.MultiSurfaceMapping)2 AbstractClassDef (ch.interlis.ili2c.metamodel.AbstractClassDef)2