Search in sources :

Example 1 with IomObject

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

the class Fgdb2iox method readGeometry.

private IomObject readGeometry() throws IOException, ParseException, IoxException {
    dis.setOrder(ByteOrderValues.LITTLE_ENDIAN);
    int typeInt = dis.readInt();
    int geometryType = typeInt & EsriShpConstants.shapeBasicTypeMask;
    if (geometryType == EsriShpConstants.ShapeNull) {
        return null;
    }
    // determine if Z values are present
    hasZ = geometryType == EsriShpConstants.ShapePointZM || geometryType == EsriShpConstants.ShapePointZ || geometryType == EsriShpConstants.ShapeMultiPointZM || geometryType == EsriShpConstants.ShapeMultiPointZ || geometryType == EsriShpConstants.ShapePolylineZM || geometryType == EsriShpConstants.ShapePolylineZ || geometryType == EsriShpConstants.ShapePolygonZM || geometryType == EsriShpConstants.ShapePolygonZ || (geometryType == EsriShpConstants.ShapeGeneralPoint || geometryType == EsriShpConstants.ShapeGeneralPolyline || geometryType == EsriShpConstants.ShapeGeneralPolygon || geometryType == EsriShpConstants.ShapeGeneralMultiPoint || geometryType == EsriShpConstants.ShapeGeneralMultiPatch) && ((typeInt & EsriShpConstants.shapeHasZs) != 0);
    boolean hasM = geometryType == EsriShpConstants.ShapePointZM || geometryType == EsriShpConstants.ShapePointM || geometryType == EsriShpConstants.ShapeMultiPointZM || geometryType == EsriShpConstants.ShapeMultiPointM || geometryType == EsriShpConstants.ShapePolylineZM || geometryType == EsriShpConstants.ShapePolylineM || geometryType == EsriShpConstants.ShapePolygonZM || geometryType == EsriShpConstants.ShapePolygonM || (geometryType == EsriShpConstants.ShapeGeneralPoint || geometryType == EsriShpConstants.ShapeGeneralPolyline || geometryType == EsriShpConstants.ShapeGeneralPolygon || geometryType == EsriShpConstants.ShapeGeneralMultiPoint || geometryType == EsriShpConstants.ShapeGeneralMultiPatch) && ((typeInt & EsriShpConstants.shapeHasMs) != 0);
    boolean hasCurves = (geometryType == EsriShpConstants.ShapeGeneralPolyline || geometryType == EsriShpConstants.ShapeGeneralPolygon) && (typeInt & EsriShpConstants.shapeNonBasicModifierMask) != 0 || (typeInt & EsriShpConstants.shapeHasCurves) != 0;
    inputDimension = hasZ ? 3 : 2;
    // only allocate ordValues buffer if necessary
    if (ordValues == null || ordValues.length < inputDimension)
        ordValues = new double[inputDimension];
    if (geometryType == EsriShpConstants.ShapePoint || geometryType == EsriShpConstants.ShapePointZM || geometryType == EsriShpConstants.ShapePointZ || geometryType == EsriShpConstants.ShapeGeneralPoint) {
        double x = dis.readDouble();
        double y = dis.readDouble();
        IomObject ret = new ch.interlis.iom_j.Iom_jObject("COORD", null);
        ret.setattrvalue("C1", Double.toString(x));
        ret.setattrvalue("C2", Double.toString(y));
        if (hasZ) {
            double z = dis.readDouble();
            ret.setattrvalue("C3", Double.toString(z));
        }
        return ret;
    }
    if (geometryType == EsriShpConstants.ShapeGeneralMultiPatch) {
        throw new IoxException("unexpected geometryType " + geometryType);
    }
    // boundingBox
    double min_x = dis.readDouble();
    double min_y = dis.readDouble();
    double max_x = dis.readDouble();
    double max_y = dis.readDouble();
    // cParts
    int cParts = 0;
    int[] partStart = null;
    if (geometryType == EsriShpConstants.ShapeMultiPoint || geometryType == EsriShpConstants.ShapeMultiPointZM || geometryType == EsriShpConstants.ShapeMultiPointZ || geometryType == EsriShpConstants.ShapeGeneralMultiPoint) {
    } else {
        cParts = dis.readInt();
        partStart = new int[cParts];
    }
    // cPoints
    int cPoints = dis.readInt();
    // parts[cParts]
    if (cParts > 0) {
        for (int i = 0; i < cParts; i++) {
            partStart[i] = dis.readInt();
        }
    }
    // points[cPoints]
    Coordinate[] points = new Coordinate[cPoints];
    for (int i = 0; i < cPoints; i++) {
        points[i] = new Coordinate();
        points[i].x = dis.readDouble();
        points[i].y = dis.readDouble();
    }
    if (geometryType == EsriShpConstants.ShapeMultiPoint || geometryType == EsriShpConstants.ShapeMultiPointZM || geometryType == EsriShpConstants.ShapeMultiPointZ || geometryType == EsriShpConstants.ShapeGeneralMultiPoint) {
        throw new IoxException("unexpected geometryType " + geometryType);
    } else if (geometryType == EsriShpConstants.ShapePolyline || geometryType == EsriShpConstants.ShapePolylineZM || geometryType == EsriShpConstants.ShapePolylineZ || geometryType == EsriShpConstants.ShapeGeneralPolyline) {
    } else if (geometryType == EsriShpConstants.ShapePolygon || geometryType == EsriShpConstants.ShapePolygonZM || geometryType == EsriShpConstants.ShapePolygonZ || geometryType == EsriShpConstants.ShapeGeneralPolygon) {
    } else {
        throw new IoxException("unexpected geometryType " + geometryType);
    }
    if (hasZ) {
        double min_z = dis.readDouble();
        double max_z = dis.readDouble();
        // Zs[cPoints]
        for (int i = 0; i < cPoints; i++) {
            points[i].z = dis.readDouble();
        }
    }
    if (hasM) {
        double min_m = dis.readDouble();
        double max_m = dis.readDouble();
        // Ms[cPoints]
        for (int i = 0; i < cPoints; i++) {
            // ignore
            dis.readDouble();
        }
    }
    java.util.Map<Integer, Arc> arcs = null;
    if (hasCurves) {
        int cSegmentModifiers = dis.readInt();
        arcs = new java.util.HashMap<Integer, Arc>();
        for (int i = 0; i < cSegmentModifiers; i++) {
            int startPointIndex = dis.readInt();
            int segmentType = dis.readInt();
            if (segmentType == EsriShpConstants.segmentArc) {
                double v1 = dis.readDouble();
                double v2 = dis.readDouble();
                int bits = dis.readInt();
                // int skip1=dis.readInt();
                if ((bits & EsriShpConstants.arcIsEmpty) != 0) {
                // skip it
                } else if ((bits & EsriShpConstants.arcIsLine) != 0) {
                // straight line, skip it
                } else if ((bits & EsriShpConstants.arcIsPoint) != 0) {
                    throw new IoxException("not supported SegmentArc.Bits " + bits);
                } else if ((bits & EsriShpConstants.arcDefinedIP) != 0) {
                // throw new IoxException("not supported SegmentArc.Bits "+bits);
                } else {
                    if ((bits & EsriShpConstants.arcIsCCW) != 0) {
                    // counterclockwise
                    } else {
                    // clockwise
                    }
                }
                // double skip1=dis.readDouble();
                // double skip2=dis.readDouble();
                // double skip3=dis.readDouble();
                arcs.put(startPointIndex, new Arc(startPointIndex, v1, v2, bits));
            } else if (segmentType == EsriShpConstants.segmentLine) {
            // will never appear; should be ignored
            } else if (segmentType == EsriShpConstants.segmentSpiral) {
            } else if (segmentType == EsriShpConstants.segmentBezier3Curve) {
                // two middle control points
                double skip1 = dis.readDouble();
                double skip2 = dis.readDouble();
                double skip3 = dis.readDouble();
                double skip4 = dis.readDouble();
            } else if (segmentType == EsriShpConstants.segmentEllipticArc) {
                // center
                double skip1 = dis.readDouble();
                double skip2 = dis.readDouble();
                // rotation or fromV
                double skip3 = dis.readDouble();
                // semiMajor
                double skip4 = dis.readDouble();
                // minorMajorRatio or deltaV
                double skip5 = dis.readDouble();
                // bits
                int skip6 = dis.readInt();
            } else if (segmentType == 0) {
                break;
            } else {
                throw new IoxException("unexpected segmentType " + segmentType);
            // EhiLogger.traceState(("unexpected segmentType "+segmentType));
            // continue;
            }
        }
    }
    JtsextGeometryFactory fact = new JtsextGeometryFactory();
    if (geometryType == EsriShpConstants.ShapePolyline || geometryType == EsriShpConstants.ShapePolylineZM || geometryType == EsriShpConstants.ShapePolylineZ || geometryType == EsriShpConstants.ShapeGeneralPolyline) {
        if (cParts == 1) {
            LineString line = getPolyline(fact, 0, points, partStart, arcs, false);
            IomObject ret;
            try {
                ret = Jtsext2iox.JTS2polyline(line);
            } catch (Iox2jtsException e) {
                throw new IoxException(e);
            }
            return ret;
        }
        IomObject ret = new Iom_jObject(Wkb2iox.OBJ_MULTIPOLYLINE, null);
        for (int i = 0; i < cParts; i++) {
            LineString line = getPolyline(fact, i, points, partStart, arcs, false);
            try {
                IomObject lineObj = Jtsext2iox.JTS2polyline(line);
                ret.addattrobj(Wkb2iox.ATTR_POLYLINE, lineObj);
            } catch (Iox2jtsException e) {
                throw new IoxException(e);
            }
        }
        return ret;
    } else if (geometryType == EsriShpConstants.ShapePolygon || geometryType == EsriShpConstants.ShapePolygonZM || geometryType == EsriShpConstants.ShapePolygonZ || geometryType == EsriShpConstants.ShapeGeneralPolygon) {
        if (cParts == 1) {
            LineString line = getPolyline(fact, 0, points, partStart, arcs, true);
            if (line.getCoordinateSequence().size() <= 3) {
                throw new IoxException("Not a Ring");
            }
            Polygon polygon = fact.createCurvePolygon(fact.createRing(line));
            IomObject ret;
            try {
                ret = Jtsext2iox.JTS2surface(polygon);
            } catch (Iox2jtsException e) {
                throw new IoxException(e);
            }
            return ret;
        }
        ArrayList<LineString> shells = new ArrayList<LineString>();
        ArrayList<LineString> holes = new ArrayList<LineString>();
        for (int i = 0; i < cParts; i++) {
            LineString line = getPolyline(fact, i, points, partStart, arcs, true);
            if (line.getCoordinateSequence().size() <= 3) {
                throw new IoxException("Not a Ring");
            }
            if (CGAlgorithms.isCCW(line.getCoordinates())) {
                holes.add(line);
            } else {
                shells.add(line);
            }
        }
        if (shells.size() == 0) {
            throw new IoxException("polygon without shell");
        } else if (shells.size() == 1) {
            LinearRing shell = fact.createRing(shells.get(0));
            Polygon polygon = null;
            if (holes.size() == 0) {
                polygon = fact.createPolygon(shell);
            } else {
                LinearRing[] hole = new LinearRing[holes.size()];
                int i = 0;
                for (LineString line : holes) {
                    hole[i] = fact.createRing(line);
                    i++;
                }
                polygon = fact.createPolygon(shell, hole);
            }
            IomObject ret = null;
            try {
                ret = Jtsext2iox.JTS2surface(polygon);
            } catch (Iox2jtsException e) {
                throw new IoxException(e);
            }
            return ret;
        } else {
        // TODO  MultiSurface
        }
        return null;
    } else {
        throw new IoxException("unexpected geometryType " + geometryType);
    }
}
Also used : ArrayList(java.util.ArrayList) Iom_jObject(ch.interlis.iom_j.Iom_jObject) IomObject(ch.interlis.iom.IomObject) Coordinate(com.vividsolutions.jts.geom.Coordinate) LineString(com.vividsolutions.jts.geom.LineString) JtsextGeometryFactory(ch.interlis.iom_j.itf.impl.jtsext.geom.JtsextGeometryFactory) CurvePolygon(ch.interlis.iom_j.itf.impl.jtsext.geom.CurvePolygon) Polygon(com.vividsolutions.jts.geom.Polygon) LinearRing(com.vividsolutions.jts.geom.LinearRing) IoxException(ch.interlis.iox.IoxException) Iox2jtsException(ch.interlis.iox_j.jts.Iox2jtsException)

Example 2 with IomObject

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

the class ToXtfRecordConverter method addAttrValue.

public int addAttrValue(java.sql.ResultSet rs, int valuei, long sqlid, Iom_jObject iomObj, AttributeDef attr, ArrayList<StructWrapper> structQueue, ViewableWrapper table, FixIomObjectRefs fixref) throws SQLException {
    if (attr.getExtending() == null) {
        String attrName = attr.getName();
        String sqlAttrName = ili2sqlName.mapIliAttributeDef(attr, table.getSqlTablename(), null);
        if (attr.isDomainBoolean()) {
            boolean value = rs.getBoolean(valuei);
            valuei++;
            if (!rs.wasNull()) {
                if (value) {
                    iomObj.setattrvalue(attrName, "true");
                } else {
                    iomObj.setattrvalue(attrName, "false");
                }
            }
        } else if (attr.isDomainIli1Date()) {
            java.sql.Date value = rs.getDate(valuei);
            valuei++;
            if (!rs.wasNull()) {
                java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat("yyyyMMdd");
                GregorianCalendar date = new GregorianCalendar();
                date.setGregorianChange(PURE_GREGORIAN_CALENDAR);
                fmt.setCalendar(date);
                iomObj.setattrvalue(attrName, fmt.format(value));
            }
        } else if (attr.isDomainIli2Date()) {
            java.sql.Date value = rs.getDate(valuei);
            valuei++;
            if (!rs.wasNull()) {
                java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat("yyyy-MM-dd");
                GregorianCalendar date = new GregorianCalendar();
                date.setGregorianChange(PURE_GREGORIAN_CALENDAR);
                fmt.setCalendar(date);
                iomObj.setattrvalue(attrName, fmt.format(value));
            }
        } else if (attr.isDomainIli2Time()) {
            java.sql.Time value = rs.getTime(valuei);
            valuei++;
            if (!rs.wasNull()) {
                java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat("HH:mm:ss.SSS");
                iomObj.setattrvalue(attrName, fmt.format(value));
            }
        } else if (attr.isDomainIli2DateTime()) {
            java.sql.Timestamp value = rs.getTimestamp(valuei);
            valuei++;
            if (!rs.wasNull()) {
                // with timezone: yyyy-MM-dd'T'HH:mm:ss.SSSZ
                java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
                GregorianCalendar date = new GregorianCalendar();
                date.setGregorianChange(PURE_GREGORIAN_CALENDAR);
                fmt.setCalendar(date);
                iomObj.setattrvalue(attrName, fmt.format(value));
            }
        } else {
            Type type = attr.getDomainResolvingAliases();
            if (type instanceof CompositionType) {
                if (TrafoConfigNames.CATALOGUE_REF_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.CATALOGUE_REF_TRAFO))) {
                    Table catalogueReferenceTyp = ((CompositionType) type).getComponentType();
                    long value = rs.getLong(valuei);
                    valuei++;
                    if (!rs.wasNull()) {
                        IomObject catref = iomObj.addattrobj(attrName, catalogueReferenceTyp.getScopedName(null));
                        IomObject ref = catref.addattrobj(IliNames.CHBASE1_CATALOGUEREFERENCE_REFERENCE, "REF");
                        mapSqlid2Xtfid(fixref, value, ref, ((ReferenceType) ((AttributeDef) catalogueReferenceTyp.getAttributes().next()).getDomain()).getReferred());
                    }
                } else if (TrafoConfigNames.MULTISURFACE_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTISURFACE_TRAFO))) {
                    MultiSurfaceMapping attrMapping = multiSurfaceAttrs.getMapping(attr);
                    Table multiSurfaceType = ((CompositionType) type).getComponentType();
                    Table surfaceStructureType = ((CompositionType) ((AttributeDef) multiSurfaceType.getElement(AttributeDef.class, attrMapping.getBagOfSurfacesAttrName())).getDomain()).getComponentType();
                    String multiSurfaceQname = multiSurfaceType.getScopedName(null);
                    String surfaceStructureQname = surfaceStructureType.getScopedName(null);
                    SurfaceType surface = ((SurfaceType) ((AttributeDef) surfaceStructureType.getElement(AttributeDef.class, attrMapping.getSurfaceAttrName())).getDomainResolvingAliases());
                    CoordType coord = (CoordType) surface.getControlPointDomain().getType();
                    boolean is3D = coord.getDimensions().length == 3;
                    Object geomobj = rs.getObject(valuei);
                    valuei++;
                    if (!rs.wasNull()) {
                        try {
                            IomObject iomMultiSurface = geomConv.toIomMultiSurface(geomobj, sqlAttrName, is3D);
                            IomObject iomChbaseMultiSurface = new Iom_jObject(multiSurfaceQname, null);
                            int surfacec = iomMultiSurface.getattrvaluecount("surface");
                            for (int surfacei = 0; surfacei < surfacec; surfacei++) {
                                IomObject iomSurface = iomMultiSurface.getattrobj("surface", surfacei);
                                IomObject iomChbaseSurfaceStructure = iomChbaseMultiSurface.addattrobj(attrMapping.getBagOfSurfacesAttrName(), surfaceStructureQname);
                                IomObject iomSurfaceClone = new ch.interlis.iom_j.Iom_jObject("MULTISURFACE", null);
                                iomSurfaceClone.addattrobj("surface", iomSurface);
                                iomChbaseSurfaceStructure.addattrobj(attrMapping.getSurfaceAttrName(), iomSurfaceClone);
                            }
                            iomObj.addattrobj(attrName, iomChbaseMultiSurface);
                        } catch (ConverterException ex) {
                            EhiLogger.logError("Object " + sqlid + ": failed to convert surface/area", ex);
                        }
                    }
                } else if (TrafoConfigNames.MULTILINE_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTILINE_TRAFO))) {
                    MultiLineMapping attrMapping = multiLineAttrs.getMapping(attr);
                    Table multiLineType = ((CompositionType) type).getComponentType();
                    Table lineStructureType = ((CompositionType) ((AttributeDef) multiLineType.getElement(AttributeDef.class, attrMapping.getBagOfLinesAttrName())).getDomain()).getComponentType();
                    String multiLineQname = multiLineType.getScopedName(null);
                    String lineStructureQname = lineStructureType.getScopedName(null);
                    PolylineType surface = ((PolylineType) ((AttributeDef) lineStructureType.getElement(AttributeDef.class, attrMapping.getLineAttrName())).getDomainResolvingAliases());
                    CoordType coord = (CoordType) surface.getControlPointDomain().getType();
                    boolean is3D = coord.getDimensions().length == 3;
                    Object geomobj = rs.getObject(valuei);
                    valuei++;
                    if (!rs.wasNull()) {
                        try {
                            IomObject iomMultiPolygon = geomConv.toIomMultiPolyline(geomobj, sqlAttrName, is3D);
                            IomObject iomChbaseMultiLine = new Iom_jObject(multiLineQname, null);
                            int linec = iomMultiPolygon.getattrvaluecount(Wkb2iox.ATTR_POLYLINE);
                            for (int linei = 0; linei < linec; linei++) {
                                IomObject iomPolygon = iomMultiPolygon.getattrobj(Wkb2iox.ATTR_POLYLINE, linei);
                                IomObject iomChbaseSurfaceStructure = iomChbaseMultiLine.addattrobj(attrMapping.getBagOfLinesAttrName(), lineStructureQname);
                                iomChbaseSurfaceStructure.addattrobj(attrMapping.getLineAttrName(), iomPolygon);
                            }
                            iomObj.addattrobj(attrName, iomChbaseMultiLine);
                        } catch (ConverterException ex) {
                            EhiLogger.logError("Object " + sqlid + ": failed to convert polyline", ex);
                        }
                    }
                } else if (TrafoConfigNames.MULTIPOINT_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTIPOINT_TRAFO))) {
                    MultiPointMapping attrMapping = multiPointAttrs.getMapping(attr);
                    Table multiPointType = ((CompositionType) type).getComponentType();
                    Table pointStructureType = ((CompositionType) ((AttributeDef) multiPointType.getElement(AttributeDef.class, attrMapping.getBagOfPointsAttrName())).getDomain()).getComponentType();
                    String multiPointQname = multiPointType.getScopedName(null);
                    String pointStructureQname = pointStructureType.getScopedName(null);
                    CoordType coord = ((CoordType) ((AttributeDef) pointStructureType.getElement(AttributeDef.class, attrMapping.getPointAttrName())).getDomainResolvingAliases());
                    boolean is3D = coord.getDimensions().length == 3;
                    Object geomobj = rs.getObject(valuei);
                    valuei++;
                    if (!rs.wasNull()) {
                        try {
                            IomObject iomMultiPoint = geomConv.toIomMultiCoord(geomobj, sqlAttrName, is3D);
                            IomObject iomChbaseMultiPoint = new Iom_jObject(multiPointQname, null);
                            int pointc = iomMultiPoint.getattrvaluecount(Wkb2iox.ATTR_COORD);
                            for (int pointi = 0; pointi < pointc; pointi++) {
                                IomObject iomPoint = iomMultiPoint.getattrobj(Wkb2iox.ATTR_COORD, pointi);
                                IomObject iomChbasePointStructure = iomChbaseMultiPoint.addattrobj(attrMapping.getBagOfPointsAttrName(), pointStructureQname);
                                iomChbasePointStructure.addattrobj(attrMapping.getPointAttrName(), iomPoint);
                            }
                            iomObj.addattrobj(attrName, iomChbaseMultiPoint);
                        } catch (ConverterException ex) {
                            EhiLogger.logError("Object " + sqlid + ": failed to convert coord", ex);
                        }
                    }
                } else if (TrafoConfigNames.ARRAY_TRAFO_COALESCE.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.ARRAY_TRAFO))) {
                    ArrayMapping attrMapping = arrayAttrs.getMapping(attr);
                    Object dbValue = rs.getObject(valuei);
                    valuei++;
                    if (!rs.wasNull()) {
                        try {
                            Table valueStructType = ((CompositionType) type).getComponentType();
                            String valueStructQname = valueStructType.getScopedName(null);
                            String[] iomArray = geomConv.toIomArray(attrMapping.getValueAttr(), dbValue, enumTypes);
                            for (int elei = 0; elei < iomArray.length; elei++) {
                                IomObject iomValueStruct = new Iom_jObject(valueStructQname, null);
                                iomValueStruct.setattrvalue(attrMapping.getValueAttr().getName(), iomArray[elei]);
                                iomObj.addattrobj(attrName, iomValueStruct);
                            }
                        } catch (ConverterException ex) {
                            EhiLogger.logError("Object " + sqlid + ": failed to convert array", ex);
                        }
                    }
                } else if (TrafoConfigNames.MULTILINGUAL_TRAFO_EXPAND.equals(trafoConfig.getAttrConfig(attr, TrafoConfigNames.MULTILINGUAL_TRAFO))) {
                    IomObject iomMulti = null;
                    Table multilingualTextType = ((CompositionType) type).getComponentType();
                    String multilingualTextQname = multilingualTextType.getScopedName(null);
                    String localizedTextQname = ((CompositionType) ((AttributeDef) multilingualTextType.getAttributes().next()).getDomain()).getComponentType().getScopedName(null);
                    for (String sfx : DbNames.MULTILINGUAL_TXT_COL_SUFFIXS) {
                        String value = rs.getString(valuei);
                        valuei++;
                        if (!rs.wasNull()) {
                            if (iomMulti == null) {
                                iomMulti = new Iom_jObject(multilingualTextQname, null);
                            }
                            IomObject iomTxt = iomMulti.addattrobj(IliNames.CHBASE1_LOCALISEDTEXT, localizedTextQname);
                            iomTxt.setattrvalue(IliNames.CHBASE1_LOCALISEDTEXT_LANGUAGE, sfx.length() == 0 ? null : sfx.substring(LEN_LANG_PREFIX));
                            iomTxt.setattrvalue(IliNames.CHBASE1_LOCALISEDTEXT_TEXT, value);
                        }
                    }
                    if (iomMulti != null) {
                        iomObj.addattrobj(attrName, iomMulti);
                    }
                } else {
                    // enque iomObj as parent
                    structQueue.add(new StructWrapper(sqlid, attr, iomObj, table));
                }
            } else if (type instanceof PolylineType) {
                Object geomobj = rs.getObject(valuei);
                valuei++;
                if (!rs.wasNull()) {
                    try {
                        boolean is3D = ((CoordType) ((PolylineType) type).getControlPointDomain().getType()).getDimensions().length == 3;
                        IomObject polyline = geomConv.toIomPolyline(geomobj, sqlAttrName, is3D);
                        iomObj.addattrobj(attrName, polyline);
                    } catch (ConverterException ex) {
                        EhiLogger.logError("Object " + sqlid + ": failed to convert polyline", ex);
                    }
                }
            } else if (type instanceof SurfaceOrAreaType) {
                if (createItfLineTables) {
                } else {
                    Object geomobj = rs.getObject(valuei);
                    valuei++;
                    if (!rs.wasNull()) {
                        try {
                            boolean is3D = ((CoordType) ((SurfaceOrAreaType) type).getControlPointDomain().getType()).getDimensions().length == 3;
                            IomObject surface = geomConv.toIomSurface(geomobj, sqlAttrName, is3D);
                            iomObj.addattrobj(attrName, surface);
                        } catch (ConverterException ex) {
                            EhiLogger.logError("Object " + sqlid + ": failed to convert surface/area", ex);
                        }
                    }
                }
                if (createItfAreaRef) {
                    if (type instanceof AreaType) {
                        Object geomobj = rs.getObject(valuei);
                        valuei++;
                        if (!rs.wasNull()) {
                            try {
                                boolean is3D = false;
                                IomObject coord = geomConv.toIomCoord(geomobj, sqlAttrName, is3D);
                                iomObj.addattrobj(attrName, coord);
                            } catch (ConverterException ex) {
                                EhiLogger.logError("Object " + sqlid + ": failed to convert coord", ex);
                            }
                        }
                    }
                }
            } else if (type instanceof CoordType) {
                Object geomobj = rs.getObject(valuei);
                valuei++;
                if (!rs.wasNull()) {
                    try {
                        boolean is3D = ((CoordType) type).getDimensions().length == 3;
                        IomObject coord = geomConv.toIomCoord(geomobj, sqlAttrName, is3D);
                        iomObj.addattrobj(attrName, coord);
                    } catch (ConverterException ex) {
                        EhiLogger.logError("Object " + sqlid + ": failed to convert coord", ex);
                    }
                }
            } else if (type instanceof EnumerationType) {
                if (createEnumColAsItfCode) {
                    int value = rs.getInt(valuei);
                    valuei++;
                    if (!rs.wasNull()) {
                        iomObj.setattrvalue(attrName, mapItfCode2XtfCode((EnumerationType) type, value));
                    }
                } else {
                    String value = rs.getString(valuei);
                    valuei++;
                    if (!rs.wasNull()) {
                        iomObj.setattrvalue(attrName, value);
                    }
                }
            } else if (type instanceof ReferenceType) {
                ArrayList<ViewableWrapper> targetTables = getTargetTables(((ReferenceType) type).getReferred());
                boolean refAlreadyDefined = false;
                for (ViewableWrapper targetTable : targetTables) {
                    long value = rs.getLong(valuei);
                    valuei++;
                    if (!rs.wasNull()) {
                        if (refAlreadyDefined) {
                            sqlAttrName = ili2sqlName.mapIliAttributeDef(attr, table.getSqlTablename(), targetTable.getSqlTablename(), targetTables.size() > 1);
                            EhiLogger.logAdaption("Table " + table.getSqlTablename() + "(id " + sqlid + ") more than one value for refattr " + attrName + "; value of " + sqlAttrName + " ignored");
                        } else {
                            IomObject ref = iomObj.addattrobj(attrName, "REF");
                            mapSqlid2Xtfid(fixref, value, ref, ((ReferenceType) type).getReferred());
                            refAlreadyDefined = true;
                        }
                    }
                }
            } else if (type instanceof BlackboxType) {
                if (((BlackboxType) type).getKind() == BlackboxType.eXML) {
                    Object obj = rs.getObject(valuei);
                    valuei++;
                    if (!rs.wasNull()) {
                        try {
                            iomObj.setattrvalue(attrName, geomConv.toIomXml(obj));
                        } catch (ConverterException ex) {
                            EhiLogger.logError("Object " + sqlid + ": failed to convert blackbox xml", ex);
                        }
                    }
                } else {
                    Object obj = rs.getObject(valuei);
                    valuei++;
                    if (!rs.wasNull()) {
                        try {
                            iomObj.setattrvalue(attrName, geomConv.toIomBlob(obj));
                        } catch (ConverterException ex) {
                            EhiLogger.logError("Object " + sqlid + ": failed to convert blackbox binary", ex);
                        }
                    }
                }
            } else {
                String value = rs.getString(valuei);
                valuei++;
                if (!rs.wasNull()) {
                    iomObj.setattrvalue(attrName, value);
                }
            }
        }
    }
    return valuei;
}
Also used : ConverterException(ch.ehi.ili2db.converter.ConverterException) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) ArrayList(java.util.ArrayList) ViewableWrapper(ch.ehi.ili2db.mapping.ViewableWrapper) CompositionType(ch.interlis.ili2c.metamodel.CompositionType) AreaType(ch.interlis.ili2c.metamodel.AreaType) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) Iom_jObject(ch.interlis.iom_j.Iom_jObject) ReferenceType(ch.interlis.ili2c.metamodel.ReferenceType) IomObject(ch.interlis.iom.IomObject) AttributeDef(ch.interlis.ili2c.metamodel.AttributeDef) PolylineType(ch.interlis.ili2c.metamodel.PolylineType) Table(ch.interlis.ili2c.metamodel.Table) Iom_jObject(ch.interlis.iom_j.Iom_jObject) MultiPointMapping(ch.ehi.ili2db.mapping.MultiPointMapping) BlackboxType(ch.interlis.ili2c.metamodel.BlackboxType) GregorianCalendar(java.util.GregorianCalendar) EnumerationType(ch.interlis.ili2c.metamodel.EnumerationType) SurfaceType(ch.interlis.ili2c.metamodel.SurfaceType) MultiSurfaceMapping(ch.ehi.ili2db.mapping.MultiSurfaceMapping) SurfaceType(ch.interlis.ili2c.metamodel.SurfaceType) CompositionType(ch.interlis.ili2c.metamodel.CompositionType) PolylineType(ch.interlis.ili2c.metamodel.PolylineType) Type(ch.interlis.ili2c.metamodel.Type) EnumerationType(ch.interlis.ili2c.metamodel.EnumerationType) BlackboxType(ch.interlis.ili2c.metamodel.BlackboxType) AreaType(ch.interlis.ili2c.metamodel.AreaType) ReferenceType(ch.interlis.ili2c.metamodel.ReferenceType) SurfaceOrAreaType(ch.interlis.ili2c.metamodel.SurfaceOrAreaType) ObjectType(ch.interlis.ili2c.metamodel.ObjectType) CoordType(ch.interlis.ili2c.metamodel.CoordType) ArrayMapping(ch.ehi.ili2db.mapping.ArrayMapping) Iom_jObject(ch.interlis.iom_j.Iom_jObject) IomObject(ch.interlis.iom.IomObject) MultiLineMapping(ch.ehi.ili2db.mapping.MultiLineMapping) CoordType(ch.interlis.ili2c.metamodel.CoordType)

Example 3 with IomObject

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

the class Iox2wkbTest method addCoord.

private void addCoord(IomObject polyline, double x, double y) {
    IomObject sequence = polyline.getattrobj("sequence", 0);
    IomObject ret = new ch.interlis.iom_j.Iom_jObject("COORD", null);
    ret.setattrvalue("C1", Double.toString(x));
    ret.setattrvalue("C2", Double.toString(y));
    sequence.addattrobj("segment", ret);
}
Also used : IomObject(ch.interlis.iom.IomObject)

Example 4 with IomObject

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

the class Iox2wkbTest method addArc.

private void addArc(IomObject polyline, double xa, double ya, double x, double y) {
    IomObject sequence = polyline.getattrobj("sequence", 0);
    IomObject ret = new ch.interlis.iom_j.Iom_jObject("ARC", null);
    ret.setattrvalue("C1", Double.toString(x));
    ret.setattrvalue("C2", Double.toString(y));
    ret.setattrvalue("A1", Double.toString(xa));
    ret.setattrvalue("A2", Double.toString(ya));
    sequence.addattrobj("segment", ret);
}
Also used : IomObject(ch.interlis.iom.IomObject)

Example 5 with IomObject

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

the class Iox2wkbTest method createPolgon.

private IomObject createPolgon(IomObject polyline) {
    // MULTISURFACE {surface SURFACE {boundary BOUNDARY {polyline
    IomObject ret = new ch.interlis.iom_j.Iom_jObject("MULTISURFACE", null);
    IomObject surface = new ch.interlis.iom_j.Iom_jObject("SURFACE", null);
    IomObject boundary = new ch.interlis.iom_j.Iom_jObject("BOUNDARY", null);
    boundary.addattrobj("polyline", polyline);
    surface.addattrobj("boundary", boundary);
    ret.addattrobj("surface", surface);
    return ret;
}
Also used : IomObject(ch.interlis.iom.IomObject)

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