Ejemplo n.º 1
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());
    }
}
Ejemplo n.º 2
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;
}
Ejemplo n.º 3
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;
}
Ejemplo n.º 4
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;
}
Ejemplo n.º 6
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;
}
Ejemplo n.º 7
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;
}
Ejemplo n.º 8
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;
}