예제 #1
0
std::multimap<QString, DataFormat> DataFormat::getSelectedBy(FormatProperties prop, const QString& selection){
    QString criterium;
    InternalDatabaseConnection db;
    QString stmt = QString("select * from dataformats where %1").arg(selection);
    std::multimap<QString, DataFormat> formats;
    if (db.exec(stmt)) {
        while(db.next()){
            QString code = db.value("code").toString();
            switch (prop){
            case fpCODE:
                criterium = code; break;
            case fpNAME:
                criterium = db.value("name").toString(); break;
            case fpEXTENSION:
                criterium = db.value("extension").toString(); break;
            case fpCONNECTOR:
                criterium = db.value("connector").toString(); break;
            default:
                ERROR2(ERR_OPERATION_NOTSUPPORTED2,"Property", "format selection");
                return std::multimap<QString, DataFormat>();
            }
            if ( criterium.size() == 0 || criterium == sUNDEF)
                continue;

            DataFormat format;
            format.setProps(db,code);
            formats.insert(std::pair<QString, DataFormat>(criterium,format));
        }

    }
    return formats;
}
예제 #2
0
void DataFormat::setProps(InternalDatabaseConnection& db, const QString &code){
    _properties[fpCODE] = code;
    _properties[fpNAME] = set(db.value("name").toString());
    _properties[fpDESCRIPTION] = set(db.value("description").toString());
    _properties[fpEXTENSION] = set(db.value("extension"));
    _properties[fpCONNECTOR] = set(db.value("connector").toString());
    _properties[fpDATATYPE] = set(db.value("datatype").toULongLong());
    _properties[fpREADWRITE] = set(db.value("readwrite").toString());
    _properties[fpEXTENDEDTYPE] = set(db.value("extendedtype").toULongLong());
    _properties[fpPARTS] = set(db.value("parts").toString());
    _isValid = true;
}
예제 #3
0
void GeodeticDatum::fromCode(const QString &gcode)
{
    InternalDatabaseConnection stmt;
    QString query = QString("Select * from datum where code='%1' or code='%2'").arg(gcode).arg('D' + gcode); // temporary workaround (only working for wgs84) because file datums.csv does not have datumnames that match the ones in epsg.pcs

    if (stmt.exec(query)) {
        if ( stmt.next()) {
            QString area = stmt.value(stmt.record().indexOf("area")).toString();
            QString geocode = stmt.value(stmt.record().indexOf("code")).toString();
            QString ellipsoid = stmt.value(stmt.record().indexOf("ellipsoid")).toString();
            double dx = stmt.value(stmt.record().indexOf("dx")).toDouble();
            double dy = stmt.value(stmt.record().indexOf("dy")).toDouble();
            double dz = stmt.value(stmt.record().indexOf("dz")).toDouble();
            setArea(area);
            code(geocode);
            setWktName(stmt.value(stmt.record().indexOf("wkt")).toString());
            IEllipsoid ellips;
            ellips.prepare("code=ellipsoid:" + ellipsoid);
            set3TransformationParameters(dx, dy, dz, ellips);
        } else {
            kernel()->issues()->log(TR("No datum for this code %1").arg(gcode));
        }
    } else {
        kernel()->issues()->logSql(stmt.lastError());
    }
}
예제 #4
0
QString Ilwis3Connector::code2name(const QString& code, const QString& type) {
    InternalDatabaseConnection db;
    QString query = QString("Select alias from aliasses where code='%1' and type='%2' and source='ilwis3'").arg(code, type);
    if ( !db.exec(query)) {
        kernel()->issues()->logSql(db.lastError());
        return sUNDEF;
    }
    if (!db.next()) {
        return sUNDEF;
    }

    QString name = db.value(0).toString();
    return name;
}
예제 #5
0
QVariantList DataFormat::getFormatProperties(FormatProperties prop, IlwisTypes types, QString connector, QString code){
    QVariantList result;
    InternalDatabaseConnection db;
    QString field= "";
    switch( prop){
        case fpCODE:
            field = "code"; break;
        case fpNAME:
            field = "name"; break;
        case fpDESCRIPTION:
            field = "description"; break;
        case fpEXTENSION:
            field = "extension"; break;
//        case fpCONTAINER:
//            field = "type"; break;
        case fpDATATYPE:
            field = "datatype"; break;
        case fpCONNECTOR:
            field = "connector"; break;
        case fpREADWRITE:
            field = "readwrite"; break;
        case fpEXTENDEDTYPE:
            field = "extendedtype"; break;
        case fpPARTS:
            field = "parts"; break;
    }

    QString stmt = QString("select %1 from dataformats where (datatype & %2) != 0").arg(field).arg(types);
    if ( code != sUNDEF)
        stmt += " and code='" + code + "'";
    if ( connector != sUNDEF)
        stmt += " and connector='" + connector + "'";

    if (db.exec(stmt)) {
        while(db.next()){
            QVariant var = db.value(0).toString();
            if ( var.type() == QVariant::String){
                QStringList parts = var.toString().split(",");
                for(QString part : parts) {
                    if ( part.size() > 0)
                        result += part;
                }
            }
        }

    }
    return result;
}
예제 #6
0
QString Ilwis3Connector::datum2Code(const QString &name, const QString &area) const
{
    QString id = name;
    if ( area != "")
        id += "|" + area;
    InternalDatabaseConnection db;
    QString query = QString("Select code from aliasses where alias='%1' and type='datum' and source='ilwis3'").arg(id);
    if ( db.exec(query)) {
        if ( db.next())
            return db.value(0).toString();
    }
    else {
        kernel()->issues()->logSql(db.lastError());
    }

    return sUNDEF;
}
IlwisObject *InternalIlwisObjectFactory::createRepresentation(const Resource& resource, const IOOptions &options) const{
    QString code = resource.code();
    Representation *rpr = createFromResource<Representation>(resource, options);


    if ( code != sUNDEF) {

        InternalDatabaseConnection db;
        QString query = QString("Select linkedtable from codes where code = '%1'").arg(code);
        if (db.exec(query)) {
            if ( db.next()){
                QString table = db.value(0).toString();
                if ( table == "representation"){
                    query = QString("Select * from representation where code='%1'").arg(code);
                    if (db.exec(query)) {
                        if ( db.next()){
                            QSqlRecord rec = db.record();
                            rpr->fromInternal(rec);
                            QString relateddomain = rec.field("relateddomain").value().toString();
                            QString rprType = rec.field("representationtype").value().toString();
                            QString  definition = rec.field("definition").value().toString();
							QString mode = rec.field("mode").value().toString();
                            if ( rprType == "continuouscolor"){
                                rpr->colors(new ContinuousColorLookup(definition, mode));
                            }else if ( rprType == "palettecolor"){
                                rpr->colors(new PaletteColorLookUp(definition));
                            }
                            if ( relateddomain == "value"){
                                rpr->domain(IDomain("value"));
                            }
                            rpr->readOnly(true);
                        }else
                            return 0;
                    }else
                        return 0;
                }else
                    return 0;
            }else
                return 0;
        }else
            return 0;
    }


    return rpr;
}
예제 #8
0
QString Ilwis3Connector::name2Code(const QString& nameIn, const QString& type) {
    QString name = nameIn;
    int index = nameIn.indexOf(".");
    if ( index != -1){
        QString ext = name.mid(index + 1);
        if ( ext == "dom" )
            name = name.left(index).toLower();
    }

    InternalDatabaseConnection db;
    QString query = QString("Select code from aliasses where lower(alias)=lower('%1') and type='%2' and source='ilwis3'").arg(name, type);
    if ( !db.exec(query)) {
        kernel()->issues()->logSql(db.lastError());
        return sUNDEF;
    }
    if (!db.next()) {
        return sUNDEF;
    }

    QString code = db.value(0).toString();
    return code;
}
IlwisObject *InternalIlwisObjectFactory::createDomain(const Resource& resource, const IOOptions &options) const{
    if ( resource.ilwisType() == itTEXTDOMAIN || resource.code() == "text")
        return createFromResource<TextDomain>(resource, options);

    if ( resource.ilwisType() == itCOLORDOMAIN || resource.code() == "color") {
        ColorDomain *dm = createFromResource<ColorDomain>(resource, options);
        ContinuousColorRange *rng = new ContinuousColorRange(QColor("#000000"), QColor("#FFFFFF"));
        dm->range(rng);
        return dm;
    }else if ( resource.ilwisType() == itCOLORDOMAIN || resource.code() == "colorpalette") {
        ColorDomain *dm = createFromResource<ColorDomain>(resource, options);
        Range *rng = new ColorPalette();
        dm->range(rng);
        return dm;
    }
    QString code = resource.code();
    Domain *newdomain = 0;
    bool readonlyState = false;
    if ( code != sUNDEF) {

		InternalDatabaseConnection db;
        QString query = QString("Select linkedtable from codes where code = '%1'").arg(code);
        if (db.exec(query)) {
            if ( db.next()){
                QString table = db.value(0).toString();
			
                if ( table == "numericdomain"){
                    newdomain = createNumericDomain(code, db, options, resource);

                }else if ( table == "itemdomain"){
                    newdomain = createItemDomain(db, options, resource);
                }
                readonlyState = true;
            }
        }else {
            kernel()->issues()->log(TR(ERR_FIND_SYSTEM_OBJECT_1).arg(code));
        }
    }else {
        if ( hasType(resource.ilwisType(), itITEMDOMAIN )){
            if ( hasType(resource.extendedType(), itNAMEDITEM)) {
                Resource res = resource;
                res.setIlwisType(itITEMDOMAIN);
                newdomain = createFromResource<ItemDomain<NamedIdentifier>>(res, options);
            }
            else if ( hasType(resource.extendedType(), itINDEXEDITEM)) {
                Resource res = resource;
                res.setIlwisType(itITEMDOMAIN);
                newdomain = createFromResource<ItemDomain<IndexedIdentifier>>(res, options);
            }
            else if ( hasType(resource.extendedType(), itTHEMATICITEM)) {
                Resource res = resource;
                res.setIlwisType(itITEMDOMAIN);
                newdomain = createFromResource<ItemDomain<ThematicItem>>(res, options);
            }
            else if ( hasType(resource.extendedType(), itNUMERICITEM)) {
                Resource res = resource;
                res.setIlwisType(itITEMDOMAIN);
                newdomain = createFromResource<ItemDomain<Interval>>(res, options);
            }
            else if ( hasType(resource.extendedType(), itPALETTECOLOR)) {
                Resource res = resource;
                res.setIlwisType(itITEMDOMAIN);
                newdomain = createFromResource<ItemDomain<ColorItem>>(res, options);
            }
        } if ( hasType(resource.ilwisType(), itNUMERICDOMAIN)){
            newdomain = createFromResource<NumericDomain>(resource, options);
        }
    }
    if ( newdomain){
        newdomain->readOnly(readonlyState);
    }
    return newdomain;
}