Search in sources :

Example 51 with IomObject

use of ch.interlis.iom.IomObject in project ili2db by claeis.

the class OracleColumnConverter method toIomCoord.

@Override
public IomObject toIomCoord(Object geomobj, String sqlAttrName, boolean is3D) throws java.sql.SQLException, ConverterException {
    JGeometry geometry = JGeometry.load((oracle.sql.STRUCT) geomobj);
    if (geometry.getType() != JGeometry.GTYPE_POINT) {
        throw new ConverterException("unexpected GTYPE (" + OracleUtility.gtype2str(geometry.getType()) + ")");
    } else {
        int dim = geometry.getDimensions();
        boolean isCurrentValue3D = (dim == 3);
        if (isCurrentValue3D != is3D) {
            throw new ConverterException("unexpected dimension (" + Integer.toString(dim) + ")");
        } else {
            double[] valuev = geometry.getFirstPoint();
            IomObject coord = new Iom_jObject("COORD", null);
            coord.setattrvalue("C1", Double.toString(valuev[0]));
            coord.setattrvalue("C2", Double.toString(valuev[1]));
            if (dim == 3) {
                coord.setattrvalue("C3", Double.toString(valuev[2]));
            }
            return coord;
        }
    }
}
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 52 with IomObject

use of ch.interlis.iom.IomObject 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 53 with IomObject

use of ch.interlis.iom.IomObject in project ili2db by claeis.

the class OracleColumnConverter method fromIomSurface.

@Override
public java.lang.Object fromIomSurface(IomObject obj, int srid, boolean hasLineAttr, boolean is3D, double p) throws java.sql.SQLException, ConverterException {
    is3D = false;
    if (obj != null) {
        ArrayList elemInfo = new ArrayList();
        ArrayList ordinates = new ArrayList();
        // (must be specified in counterclockwise order)
        final int EXTERIOR_POLYGON_RING = 1005;
        // (must be specified in clockwise order)
        final int INTERIOR_POLYGON_RING = 2005;
        boolean clipped = obj.getobjectconsistency() == IomConstants.IOM_INCOMPLETE;
        for (int surfacei = 0; surfacei < obj.getattrvaluecount("surface"); surfacei++) {
            if (clipped) {
            // out.startElement("CLIPPED",0,0);
            } else {
                // an unclipped surface should have only one surface element
                if (surfacei > 0) {
                    EhiLogger.logError("unclipped surface with multi 'surface' elements");
                    break;
                }
            }
            IomObject surface = obj.getattrobj("surface", surfacei);
            for (int boundaryi = 0; boundaryi < surface.getattrvaluecount("boundary"); boundaryi++) {
                int eleInfoStartPos = elemInfo.size();
                if (boundaryi == 0) {
                    addElemInfo(elemInfo, ordinates.size(), EXTERIOR_POLYGON_RING, 0);
                } else {
                    addElemInfo(elemInfo, ordinates.size(), INTERIOR_POLYGON_RING, 0);
                }
                IomObject boundary = surface.getattrobj("boundary", boundaryi);
                for (int polylinei = 0; polylinei < boundary.getattrvaluecount("polyline"); polylinei++) {
                    IomObject polyline = boundary.getattrobj("polyline", polylinei);
                    addPolyline(elemInfo, ordinates, polyline, true, is3D);
                }
                // patch counter in head triplet
                int elemInfoCount = (elemInfo.size() - eleInfoStartPos) / 3 - 1;
                elemInfo.set(eleInfoStartPos + 2, new Integer(elemInfoCount));
            }
            if (clipped) {
            // out.endElement(/*CLIPPED*/);
            }
        }
        int[] elemInfov = new int[elemInfo.size()];
        for (int i = 0; i < elemInfov.length; i++) {
            elemInfov[i] = ((Integer) elemInfo.get(i)).intValue();
        }
        double[] ordinatesv = new double[ordinates.size()];
        for (int i = 0; i < ordinatesv.length; i++) {
            ordinatesv[i] = ((Double) ordinates.get(i)).doubleValue();
        }
        JGeometry geom = new JGeometry(JGeometry.GTYPE_POLYGON, 0, elemInfov, ordinatesv);
        return JGeometry.store(geom, conn);
    }
    return null;
}
Also used : IomObject(ch.interlis.iom.IomObject) JGeometry(oracle.spatial.geometry.JGeometry) ArrayList(java.util.ArrayList)

Example 54 with IomObject

use of ch.interlis.iom.IomObject in project ili2db by claeis.

the class Iox2gpkg method multiline2wkb.

public byte[] multiline2wkb(IomObject obj, boolean asCompoundCurve, double p, int srsId) throws Iox2wkbException {
    if (obj == null) {
        return null;
    }
    try {
        os.reset();
        int polylinec = obj.getattrvaluecount(Wkb2iox.ATTR_POLYLINE);
        Envelope env = new Envelope();
        for (int polylinei = 0; polylinei < polylinec; polylinei++) {
            IomObject polyline = obj.getattrobj(Wkb2iox.ATTR_POLYLINE, polylinei);
            CompoundCurve curve = Iox2jtsext.polyline2JTS(polyline, false, p);
            env.expandToInclude(curve.getEnvelopeInternal());
        }
        writeGeoPackageBinaryHeader(srsId, env);
        Iox2wkb helper = new Iox2wkb(outputDimension, os.order());
        for (int polylinei = 0; polylinei < polylinec; polylinei++) {
            IomObject polyline = obj.getattrobj(Wkb2iox.ATTR_POLYLINE, polylinei);
            os.write(helper.polyline2wkb(polyline, false, asCompoundCurve, p));
        }
    } catch (IOException e) {
        throw new RuntimeException("Unexpected IO exception: " + e.getMessage());
    } catch (IoxException e) {
        throw new RuntimeException("Unexpected exception: " + e.getMessage());
    }
    return os.toByteArray();
}
Also used : IomObject(ch.interlis.iom.IomObject) CompoundCurve(ch.interlis.iom_j.itf.impl.jtsext.geom.CompoundCurve) Iox2wkb(ch.interlis.iox_j.wkb.Iox2wkb) IOException(java.io.IOException) Envelope(com.vividsolutions.jts.geom.Envelope) IoxException(ch.interlis.iox.IoxException)

Example 55 with IomObject

use of ch.interlis.iom.IomObject in project ili2db by claeis.

the class Iox2fgdb method multiline2wkb.

public byte[] multiline2wkb(IomObject obj, boolean asCompoundCurve, double p, int srsId) throws IoxException {
    if (obj == null) {
        return null;
    }
    os.reset();
    int polylinec = obj.getattrvaluecount(Wkb2iox.ATTR_POLYLINE);
    if (asCompoundCurve) {
        int shapeType = EsriShpConstants.ShapeGeneralPolyline;
        shapeType |= EsriShpConstants.shapeHasCurves;
        shapeType |= (outputDimension == 3 ? EsriShpConstants.shapeHasZs : 0);
        os.writeInt(shapeType);
    } else {
        if (outputDimension == 3) {
            os.writeInt(EsriShpConstants.ShapePolylineZ);
        } else {
            os.writeInt(EsriShpConstants.ShapePolyline);
        }
    }
    java.util.ArrayList<CompoundCurve> curves = new java.util.ArrayList<CompoundCurve>();
    // boundingBox
    Envelope env = new Envelope();
    for (int polylinei = 0; polylinei < polylinec; polylinei++) {
        IomObject polyline = obj.getattrobj(Wkb2iox.ATTR_POLYLINE, polylinei);
        CompoundCurve curve = Iox2jtsext.polyline2JTS(polyline, false, p);
        curves.add(curve);
        env.expandToInclude(curve.getEnvelopeInternal());
    }
    os.writeDouble(env.getMinX());
    os.writeDouble(env.getMinY());
    os.writeDouble(env.getMaxX());
    os.writeDouble(env.getMaxY());
    // cParts The number of Lines in the Multiline.
    // cPoints The total number of points for all lines.
    int cPart = curves.size();
    int cPoints = 0;
    for (CompoundCurve curve : curves) {
        cPoints += getNumPoints(curve);
    }
    os.writeInt(cPart);
    os.writeInt(cPoints);
    // parts[cParts] An array of length NumParts. Stores, for each Line, the index of its
    // first point in the points array. Array indexes are with respect to 0.
    int partStart = 0;
    for (CompoundCurve curve : curves) {
        os.writeInt(partStart);
        partStart += getNumPoints(curve);
    }
    java.util.ArrayList<Arc> arcs = null;
    if (asCompoundCurve) {
        arcs = new java.util.ArrayList<Arc>();
    }
    java.util.ArrayList<Double> zv = null;
    if (outputDimension == 3) {
        zv = new java.util.ArrayList<Double>();
    }
    double[] zMin = new double[1];
    double[] zMax = new double[1];
    {
        Coordinate coord = curves.get(0).getStartPoint().getCoordinate();
        if (outputDimension == 3) {
            zMin[0] = coord.z;
            zMax[0] = coord.z;
        }
    }
    int startPtIdx = 0;
    for (CompoundCurve curve : curves) {
        writePoints(curve, true, zv, zMin, zMax, startPtIdx, arcs);
        startPtIdx += getNumPoints(curve);
    }
    if (outputDimension == 3) {
        // zMin
        os.writeDouble(zMin[0]);
        // zMax
        os.writeDouble(zMax[0]);
        // Zs[cPoints]
        for (Double z : zv) {
            os.writeDouble(z);
        }
    }
    if (asCompoundCurve) {
        writeArcs(arcs);
    }
    return os.toByteArray();
}
Also used : CompoundCurve(ch.interlis.iom_j.itf.impl.jtsext.geom.CompoundCurve) ArrayList(java.util.ArrayList) Envelope(com.vividsolutions.jts.geom.Envelope) IomObject(ch.interlis.iom.IomObject) Coordinate(com.vividsolutions.jts.geom.Coordinate)

Aggregations

IomObject (ch.interlis.iom.IomObject)66 EndBasketEvent (ch.interlis.iox.EndBasketEvent)35 EndTransferEvent (ch.interlis.iox.EndTransferEvent)35 IoxEvent (ch.interlis.iox.IoxEvent)35 StartTransferEvent (ch.interlis.iox.StartTransferEvent)35 File (java.io.File)35 HashMap (java.util.HashMap)35 Config (ch.ehi.ili2db.gui.Config)34 ObjectEvent (ch.interlis.iox.ObjectEvent)34 StartBasketEvent (ch.interlis.iox.StartBasketEvent)34 Connection (java.sql.Connection)34 XtfReader (ch.interlis.iom_j.xtf.XtfReader)30 Test (org.junit.Test)29 IoxException (ch.interlis.iox.IoxException)12 AttributeDef (ch.interlis.ili2c.metamodel.AttributeDef)11 Iom_jObject (ch.interlis.iom_j.Iom_jObject)9 CompositionType (ch.interlis.ili2c.metamodel.CompositionType)8 EnumerationType (ch.interlis.ili2c.metamodel.EnumerationType)8 SurfaceOrAreaType (ch.interlis.ili2c.metamodel.SurfaceOrAreaType)8 SurfaceType (ch.interlis.ili2c.metamodel.SurfaceType)8