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;
}
IlwisObject *InternalIlwisObjectFactory::createCsyFromCode(const Resource& resource, const IOOptions &options) const {
    QString code = resource.code();
    bool isUnknown = code == "unknown" || code == "csy:unknown";
    QString projParms = code;
    if ( code.left(6) == "proj4:"){
        projParms = code.mid(6);
    }else if(!isUnknown && code.left(5) == "epsg:"){
        QString query = QString("select * from projectedcsy where code='%1'").arg(code);
        InternalDatabaseConnection db;
        if ( db.exec(query)) {
            if (db.next()) {
                QSqlRecord rec = db.record();
                projParms = rec.value("proj_params").toString();
            } else {
                kernel()->issues()->log(TR(ERR_COULDNT_CREATE_OBJECT_FOR_2).arg("coordinatesystem", resource.name()));
                return 0;
            }
        }
    }
    CoordinateSystem *csy = 0;
    if ( isUnknown){
        csy = createFromResource<BoundsOnlyCoordinateSystem>(resource, options);
        csy->name("unknown");
        csy->code("unknown");
        csy->setDescription(TR("Unknown coordinate system"));
    }else {
        csy = createFromResource<ConventionalCoordinateSystem>(resource, options);
        csy->setDescription(resource.name());
        csy->prepare("proj4=" + projParms);
    }

    return csy;

}
示例#3
0
void GeodeticDatum::getFromInternal(const QString &ellips) {
    InternalDatabaseConnection db;
    QString query = "Select * from datum";
    if ( db.exec(query) ){
        while( db.next()){
             QSqlRecord rec = db.record();
             double dx = rec.field("dx").value().toDouble();
             double dy = rec.field("dy").value().toDouble();
             double dz = rec.field("dz").value().toDouble();
             QString ellipsoid = rec.field("ellipsoid").value().toString();
             // the combination of ellips-name, dx, dy and dz uniquely identifies the datum by name and area
             if ( ellipsoid.toLower() == ellips.toLower() && std::abs(_datumParams[dmDX] - dx) < 0.01 && std::abs(_datumParams[dmDY] - dy) < 0.01 && std::abs(_datumParams[dmDZ] - dz) < 0.01) {
                 _datumParams[dmDX] = dx;
                 _datumParams[dmDY] = dy;
                 _datumParams[dmDZ] = dz;
                 code(rec.field("code").value().toString());
                 name(rec.field("name").value().toString());
                 setArea(rec.field("area").value().toString());
                 setWktName(rec.field("wkt").value().toString());
                 setAuthority(rec.field("authority").value().toString());
                 return;
             }
        }
    }
}
示例#4
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());
    }
}
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;
}
DataFormat::DataFormat(const QString &code, const QString connector)
{
    InternalDatabaseConnection db;
    QString stmt = QString("select %1 from dataformats where code='" + code + "'").arg(code);
    if ( connector != sUNDEF)
        stmt += " and connector='" + connector + "'";

    if (db.exec(stmt) && db.next()) {

    }

}
示例#7
0
bool IlwisObject::isSystemObject() const {
    if ( code() == sUNDEF)
        return false;

    InternalDatabaseConnection db;
    QString query = QString("Select linkedtable from codes where code = '%1'").arg(code());
    bool ok = db.exec(query);
    if ( ok)
        return ok;
    QString path = resource().url().toString();
    return path.indexOf("ilwis://system/") == 0;
}
bool DataFormat::setFormatInfo(const QString& path, const QString connector) {
    QFile file;
    file.setFileName(path);
    if (file.open(QIODevice::ReadOnly)) {
        QString settings = file.readAll();
        QJsonDocument doc = QJsonDocument::fromJson(settings.toUtf8());
        if ( !doc.isNull()){
            InternalDatabaseConnection sqlPublic;
            QJsonObject obj = doc.object();
            QJsonValue formats = obj.value("Formats");
            if ( formats.isArray()){
                InternalDatabaseConnection db("BEGIN TRANSACTION");
                QJsonArray arrFormats = formats.toArray();
                for(auto iter = arrFormats.begin(); iter != arrFormats.end(); ++iter) {
                    auto jsonValue  = *iter;
                    if ( jsonValue.isObject()) {
                        QJsonObject objv = jsonValue.toObject();
                        QString code = objv.value("code").toString(sUNDEF);
                        QString name = objv.value("name").toString(sUNDEF);
                        QString desc = objv.value("description").toString(sUNDEF);
                        QString type = objv.value("type").toString(sUNDEF);
                        QString ext = objv.value("extension").toString(sUNDEF);
                        QString datatp = objv.value("datatypes").toString(sUNDEF);
                        QString fileparts = objv.value("parts").toString(sUNDEF);
                        quint64 ilwtype = itUNKNOWN;
                        QStringList parts = datatp.split(",");
                        for(QString tp : parts)
                            ilwtype |= IlwisObject::name2Type(tp);
                        QString rw = objv.value("readwrite").toString("r");
                        QString extt = objv.value("extendedtype").toString(sUNDEF);
                        quint64 exttypes = itUNKNOWN;
                        parts = extt.split(",");
                        for(QString tp : parts)
                            exttypes |= IlwisObject::name2Type(tp);

                        QString parms = QString("'%1','%2','%3','%4','%5',%6,'%7','%8',%9,'%10'").arg(code.toLower(),name,desc, ext,type).arg(ilwtype).arg(connector).arg(rw).arg(exttypes).arg(fileparts);
                        QString stmt = QString("INSERT INTO dataformats VALUES(%1)").arg(parms);
                        bool ok = sqlPublic.exec(stmt);
                        if (!ok) {
                            return kernel()->issues()->logSql(sqlPublic.lastError());
                        }
                    }

                }
                db.exec("COMMIT TRANSACTION");
                return true;
            }
        }

    }
    return false;
}
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;
}
示例#10
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;
}
示例#11
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::createProjection(const Resource& resource, const IOOptions &options) const {
    QString query;
    QString code = resource.code();

    Projection *proj = 0;
    if ( code == sUNDEF){ // meant for new projections which will be initialized later (e.g by the streaming connector)
        proj = createFromResource<Projection>(resource, options);
    }

    else if ( code != "") {
        InternalDatabaseConnection db;
        query = QString("Select * from projection where code = '%1'").arg(code);
        if ( db.exec(query)) {
            if (db.next()) {
                QSqlRecord rec = db.record();

                const ProjectionFactory *factory =  kernel()->factory<ProjectionFactory>("ProjectionFactory",resource);
                if ( factory) {
                    ProjectionImplementation *projimpl = 0;
                    if ( options.contains("proj4"))
                        projimpl = static_cast<ProjectionImplementation *>(factory->create(resource.code(), options["proj4"].toString()));
                    else
                        projimpl = static_cast<ProjectionImplementation *>(factory->create(resource));
                    if (!projimpl) {
                        kernel()->issues()->log(TR(ERR_COULDNT_CREATE_OBJECT_FOR_2).arg("projection", resource.name()));
                        return 0;
                    }
                    proj = createFromResource<Projection>(resource, options);
                    proj->setImplementation(projimpl);
                    proj->fromInternal(rec);
                    proj->setAuthority(rec.field("authority").value().toString());
                    proj->setWkt(rec.field("wkt").value().toString());
                } else {
                    kernel()->issues()->log(TR(ERR_COULDNT_CREATE_OBJECT_FOR_2).arg("ProjectionFactory",resource.name()));
                }
            } else {
                kernel()->issues()->log(TR(ERR_FIND_SYSTEM_OBJECT_1).arg(code));
            }
        } else{
            kernel()->issues()->logSql(db.lastError());
        }
    } else {
        kernel()->issues()->log(TR(ERR_MISSING_CODE_FOR_SYSTEM_OBJECT));
    }
    return proj;
}
template<class DomainItemType, class RangeType> Domain* createItemDomain2(const QSqlRecord& rec, const Resource& resource){
    ItemDomain<DomainItemType> *itemdom = new ItemDomain<DomainItemType>(resource);
    const ConnectorFactory *factory = kernel()->factory<ConnectorFactory>("ilwis::ConnectorFactory");
    ConnectorInterface *connector = factory->createFromResource<>(resource, "internal");
    itemdom->setConnector(connector,IlwisObject::cmINPUT, IOOptions());
    itemdom->createTime(Time::now());
    itemdom->modifiedTime(Time::now());
    itemdom->fromInternal(rec);
    itemdom->name(resource.name());
    RangeType range ;
    InternalDatabaseConnection itemstable;
    QString query = "Select * from domainitems where code='" + resource.code() + "'";
    if (itemstable.exec(query) ) {
        while ( itemstable.next()){
            QSqlRecord rec = itemstable.record();
            range << rec.value("itemname").toString() + "|" + rec.value("itemcode").toString() + "|" + rec.value("itemdescription").toString();
        }
        itemdom->range(range.clone());
    }
    return itemdom;
}
示例#14
0
bool DataFormat::store()
{
    InternalDatabaseConnection sqlPublic;
    IlwisTypes extTypes = _properties[fpDATATYPE].toULongLong() == itRASTER ? itCOORDSYSTEM | itGEOREF | itDOMAIN : itUNKNOWN;
    QString parms = QString("'%1','%2','%3','%4','file',%5,'%6','%7',%8,'%9'").arg(_properties[fpCODE].toString(),
                                                                            _properties[fpNAME].toString(),
                                                                            _properties[fpDESCRIPTION].toString(),
                                                                              _properties[fpEXTENSION].toString()).
                                                                            arg(_properties[fpDATATYPE].toULongLong()).
                                                                            arg(_properties[fpCONNECTOR].toString()).
                                                                            arg(_properties[fpREADWRITE].toString()).
                                                                            arg(extTypes).
                                                                            arg(_properties[fpPARTS].toString());

    QString stmt = QString("INSERT INTO dataformats VALUES(%1)").arg(parms);
    bool ok = sqlPublic.exec(stmt);
    if (!ok) {
        return kernel()->issues()->logSql(sqlPublic.lastError());
    }
    return true;
}
GeodeticDatum *InternalIlwisObjectFactory::createDatum(const Resource& resource, const IOOptions &options) const {
    QString query;
    if ( resource.code() != sUNDEF) {
        QString code = resource.code();
        if ( code != "") {
            query = QString("Select * from datum where code = '%1'").arg(code);
        }
    }
    if ( resource["area"] != sUNDEF) {
        QString name = resource.name();
        QString area = resource["area"].toString();
        query = QString("Select * from datum where name='%1' and area='%1'").arg(name, area);
    }

    if ( query == "")
        return 0;

    InternalDatabaseConnection db;
    if (db.exec(query) && db.next()) {
        GeodeticDatum *datum = new GeodeticDatum();
        QSqlRecord rec = db.record();
        datum->name(rec.field("name").value().toString());
        datum->setDescription(rec.field("description").value().toString());
        datum->setAuthority(rec.field("authority").value().toString());
        datum->setArea(rec.field("area").value().toString());
        datum->code(rec.field("code").value().toString());
        QString ellips = rec.field("code").value().toString();
        IEllipsoid ell;
        QString ellres = QString("code=ellipsoid:%1").arg(ellips);
        ell.prepare(ellres);
        datum->set3TransformationParameters(rec.field("dx").value().toDouble(),
                                            rec.field("dy").value().toDouble(),
                                            rec.field("dz").value().toDouble(),
                                            ell);

        return datum;
    }

    return 0;
}
示例#16
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;
}
示例#17
0
bool Ilwis3Connector::isSystemObject(const QString& filename) {
    IlwisTypes tp = ilwisType(filename);
    QString table;
    QString fn = noExt(filename).toLower();

    if ( tp & itDOMAIN){
        table = "numericdomain";
        QString realname = Ilwis3Connector::name2Code(fn,"domain");
        if ( realname != sUNDEF)
            fn = realname;
    }
    else if ( tp & itGEODETICDATUM)
        table = "datum";
    else if ( tp & itPROJECTION)
        table = "projection";
    else if ( tp & itELLIPSOID)
        table = "ellipsoid";
    else if ( tp & itCOORDSYSTEM)
        table = "projectedcsy";

    if ( table.size() == 0) {
        kernel()->issues()->log(TR(ERR_FIND_SYSTEM_OBJECT_1).arg(filename));
        return false;
    }



    InternalDatabaseConnection db;
    QString query = QString("Select code from %1 where code='%2'").arg(table, fn);
    if ( !db.exec(query)) {
        kernel()->issues()->logSql(db.lastError());
        return false;
    }
    if (!db.next()) {
        return false;
    }
    return true;
}
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;
}