Example #1
0
SelectionDrawer::SelectionDrawer(DrawerInterface *parentDrawer, RootDrawer *rootdrawer, const IOOptions &options) : SimpleDrawer("SelectionDrawer", parentDrawer,rootdrawer, options)
{
    _vertexShader = "featurevertexshader_nvdia.glsl";
    _fragmentShader = "featurefragmentshader_nvdia.glsl";

    QColor clr;
    _colors.resize(13);
    if ( options.contains("areacolor")){
        clr = options["areacolor"].value<QColor>();
    }else {
        clr = QColor(80,80,0);
        clr.setAlphaF(0.15);
    }
    _colors[9] = _colors[10] = _colors[11] = _colors[12] = clr;
    clr.setAlphaF(0.5);
    _colors[5] = _colors[6] = _colors[7] = _colors[8] = clr;

    if ( options.contains("bordercolor")){
        clr = options["bordercolor"].value<QColor>();
    }else {
        clr = QColor(0,0,0);
        clr.setAlphaF(1);
    }
    _colors[0] = _colors[1] = _colors[2] = _colors[3] = _colors[4] = clr;
    QVector3D pos(0,0,0);
    _vertices = { pos,pos,pos,pos,pos, pos,pos,pos,pos, pos,pos,pos,pos};

    _indices.push_back(VertexIndex(0, 5, itLINE, iUNDEF));
    _indices.push_back(VertexIndex(5, 2, itLINE, iUNDEF));
    _indices.push_back(VertexIndex(7, 2, itLINE, iUNDEF));
    _indices.push_back(VertexIndex(9, 4, itPOLYGON, iUNDEF));
}
bool PostgresqlTableConnector::loadMetaData(IlwisObject *data, const IOOptions& options)
{
    Table *table = static_cast<Table *>(data);
    IOOptions iooptions = options.isEmpty() ? this->ioOptions() : options;
    PostgresqlTableLoader loader = PostgresqlTableLoader(source(), iooptions);
    return loader.loadMetadata(table);
}
Example #3
0
std::map<quint32, std::vector<quint32> > Grid::calcBlockLimits(const IOOptions& options ){
    std::map<quint32, std::vector<quint32> > result;
    int blockplayer = blocksPerBand();
    if ( options.size() == 0){
        quint32 lastblock = 0;
        for(int layer = 0; layer < size().zsize(); ++layer){
            for(int block = 0; block < blockplayer; ++block){
                result[layer].push_back(lastblock + block);
            }
            lastblock += blockplayer;
        }
    }else {
        auto bindex = options["blockindex"];
        if ( bindex.isValid()){
            quint32 index = bindex.toUInt();
            int layer = index / blockplayer;
            result[layer].push_back(index);
        }

    }


    return result;

}
void OperationCatalogModel::prepare(const IOOptions& opt){
    if ( opt.contains("globaloperationscatalog")){
        _isGlobalOperationsCatalog = opt["globaloperationscatalog"].toBool();
    }
    _refresh  = true;
    gatherItems();
}
Example #5
0
void IlwisObject::connectTo(const QUrl& outurl, const QString& format, const QString& fnamespace, ConnectorMode cmode, const IOOptions& options) {

    Locker<> lock(_mutex);
    if ( (!(cmode == cmOUTPUT)) && isReadOnly())
        return throw ErrorObject(TR(QString("format %1 or data object is readonly").arg(format)));

    QUrl url(outurl);
    if (!url.isValid()){
        url = resource(cmode).url(true);
        if ( !url.isValid()){
            ERROR2(ERR_ILLEGAL_VALUE_2, "Url","");
            throw ErrorObject(TR(QString("illegal url %1 for format %2").arg(url.toString()).arg(format)));
        }
    }
    Resource res = resource();
    if ( !res.isValid()) {
        res = Resource(url,ilwisType(), false);
        res.setId(id());
    }
    if ( url != QUrl()) {
        QString currenturl = res.url().toString();
        // we dont replace the normalized urls for internal objects if the url is pointing to the (disk based) cache
        if ( !(currenturl.indexOf(INTERNAL_CATALOG) == 0 && !outurl.isValid())){
            res.setUrl(url);

        }
        if ( url.scheme() != "ilwis") // raw urls can never go to an ilwis scheme
            res.setUrl(url,true);
        else {
            // if we are going to the internalcatalog ensure that the physical path is good
            if ( url.toString().indexOf(INTERNAL_CATALOG) == 0){
                QString rawUrl = context()->persistentInternalCatalog().toString() + "/" + res.name();
                res.setUrl(rawUrl, true);
            }
        }
    }
    const Ilwis::ConnectorFactory *factory = kernel()->factory<Ilwis::ConnectorFactory>("ilwis::ConnectorFactory");
    if ( !factory)
        throw ErrorObject(TR(QString("couldnt find factory for %1").arg(format)));
    IOOptions opt = options;
    opt.addOption("format", format);
    Ilwis::ConnectorInterface *conn = factory->createFromFormat(res, format,fnamespace,opt);
    if (!conn){
        throw ErrorObject(TR(QString("couldnt connect to %1 datasource for %2").arg(format).arg(url.toString())));
    }
    setConnector(conn, cmode, options);
}
Example #6
0
void IlwisObject::connectTo(const QUrl& outurl, const QString& format, const QString& fnamespace, ConnectorMode cmode, const IOOptions& options) {

    Locker<> lock(_mutex);
    if ( isReadOnly())
        return throw ErrorObject(TR(QString("format %1 or data object is readonly").arg(format)));

    QUrl url(outurl);
    if (!url.isValid()){
        url = source(cmode).url(true);
        if ( !url.isValid()){
            ERROR2(ERR_ILLEGAL_VALUE_2, "Url","");
            throw ErrorObject(TR(QString("illegal url %1 for format %2").arg(url.toString()).arg(format)));
        }
    }



    Resource resource;
    resource = mastercatalog()->id2Resource(id());
    if ( !resource.isValid()) {
        resource = Resource(url,ilwisType(), false);
        resource.setId(id());
    }
    if ( url != QUrl()) {
        QString currenturl = resource.url().toString();
        // we dont replace the normalized urls for internal objects if the url is pointing to the (disk based) cache
        if ( !(currenturl.indexOf("ilwis://internalcatalog") == 0 && !outurl.isValid()))
            resource.setUrl(url);
        resource.setUrl(url,true);
    }
    const Ilwis::ConnectorFactory *factory = kernel()->factory<Ilwis::ConnectorFactory>("ilwis::ConnectorFactory");
    if ( !factory)
        throw ErrorObject(TR(QString("couldnt find factory for %1").arg(format)));
    IOOptions opt = options;
    opt.addOption("format", format);
    Ilwis::ConnectorInterface *conn = factory->createFromFormat(resource, format,fnamespace,opt);
    if (!conn){
        throw ErrorObject(TR(QString("couldnt connect to %1 datasource for %2").arg(format).arg(url.toString())));
    }
    setConnector(conn, cmode, options);
    if ( Identity::name() == sUNDEF)
        name(resource.name());

}
bool PostgresqlFeatureConnector::loadData(IlwisObject *data, const IOOptions& options)
{
    if ( _binaryIsLoaded)
        return true;
    FeatureCoverage *fcoverage = static_cast<FeatureCoverage *>(data);
    IOOptions iooptions = options.isEmpty() ? this->ioOptions() : options;
    PostgresqlFeatureCoverageLoader loader = PostgresqlFeatureCoverageLoader(sourceRef(), iooptions);
    bool ok = loader.loadData(fcoverage);
    _binaryIsLoaded = ok;
    return ok;
}
void OperationCatalogModel::prepare(const IOOptions& opt){

    if ( opt.contains("globaloperationscatalog")){
        _isGlobalOperationsCatalog = opt["globaloperationscatalog"].toBool();
        QString filter = "(type=" + QString::number(itSINGLEOPERATION) + " or type=" + QString::number(itWORKFLOW) + ")";
        _view.filter("basefilter", filter);
    }
    _refresh  = true;
    catalogType(CatalogModel::ctOPERATION|CatalogModel::ctINTERNAL);
    catalogViewManager()->registerCatalogModel(this);
    gatherItems();
}
bool Ilwis3Connector::store(IlwisObject *obj, const IOOptions &options)
{
    bool ok = true;
    int storemode = options.contains("storemode") ? options["storemode"].toInt() : IlwisObject::smMETADATA | IlwisObject::smBINARYDATA;

    if ( storemode & IlwisObject::smMETADATA)
        ok &= storeMetaData(obj, options);
    if ( ok && storemode & IlwisObject::smBINARYDATA)
        ok &= storeBinaryData(obj);

    return ok;
}
bool PostgresqlTableConnector::loadData(IlwisObject *data,const IOOptions& options)
{
    Table *table = static_cast<Table *>(data);
    IOOptions iooptions = options.isEmpty() ? this->ioOptions() : options;
    PostgresqlTableLoader loader = PostgresqlTableLoader(source(), iooptions);
    if ( !loader.loadMetadata(table)) {
        return false;
    }
    bool ok = loader.loadData(table);
    _binaryIsLoaded = ok;
    return ok;
}
bool PostgresqlFeatureConnector::loadMetaData(IlwisObject *data, const IOOptions &options)
{

    FeatureCoverage *fcoverage = static_cast<FeatureCoverage *>(data);
    IOOptions iooptions = options.isEmpty() ? this->ioOptions() : options;
    PostgresqlFeatureCoverageLoader loader = PostgresqlFeatureCoverageLoader(sourceRef(), iooptions);
    if ( !loader.loadMetadata(fcoverage)) {
        ERROR1(ERR_NO_INITIALIZED_1, sourceRef().name());
        return false;
    }

    return true;
}
bool SpreadSheetTableConnector::store(IlwisObject *object, const IOOptions &options ){
    if ( !_spreadsheet){
        ERROR2(ERR_NO_INITIALIZED_2,TR("Spreadsheet"), object->name());
        return false;
    }
    QString file = _resource.toLocalFile();
    if ( QFileInfo(file).suffix() == "")
        if ( options.contains("format"))
            file += "." + options["format"].toString();
    _spreadsheet->openSheet(file, false);
    if (!_spreadsheet->isValid())
        return false;

    Table * tbl = static_cast<Table *>(object);
    bool allDeafultNames = true;
    for(int col = 0; col < tbl->columnCount() && allDeafultNames; ++col){
        allDeafultNames &= tbl->columndefinition(col).name().indexOf("column_") == 0;
    }
    if ( !allDeafultNames){
        for(int col = 0; col < tbl->columnCount(); ++col){
            _spreadsheet->cellValue(col, 0, tbl->columndefinition(col).name(), true );
        }
    }
    int rowStart = allDeafultNames ? 0 : 1;
    std::vector<ColumnDefinition *> coldefs(tbl->columnCount(),0);
    for(int col = 0; col < tbl->columnCount(); ++col) {
        if(hasType(tbl->columndefinition(col).datadef().domain()->ilwisType(), itITEMDOMAIN))
            coldefs[col] = &tbl->columndefinitionRef(col);
    }
    for(int row = 0; row < tbl->recordCount(); ++row){
        const Record& rec = tbl->record(row);
        for(int col = 0; col < tbl->columnCount(); ++col) {
            if ( coldefs[col]){
                QVariant v = coldefs[col]->datadef().domain<>()->impliedValue(rec.cell(col));
                _spreadsheet->cellValue(col, row + rowStart, v, true);
            } else {
                _spreadsheet->cellValue(col, row + rowStart, rec.cell(col), true);
            }
        }
    }

    QString error = _spreadsheet->storeSheet(_resource.toLocalFile());
    if ( !error.isEmpty()){
        kernel()->issues()->log(error);
        return false;
    }



    return true;
}
Example #13
0
bool IlwisObject::setConnector(ConnectorInterface *connector, int mode, const IOOptions &options)
{
    if ( (!(mode == cmOUTPUT)) && isReadOnly())
        return false;


    if (mode & cmINPUT){
        quint64 pointer = (quint64) ( _connector.data());
        quint64 npointer = (quint64) ( connector);
        if ( pointer != npointer || npointer == 0){
            _connector.reset(connector);
            if ( !_connector.isNull()){
                bool ok = true;
                connector->addProperty("connectormode",IlwisObject::cmINPUT);
                if ( !(options.contains("create") && options.find("create").value().toBool() == true))
                    ok = _connector->loadMetaData(this, options);
                changed(false);
                return ok;
            }
        }
        else {
            kernel()->issues()->log(QString("Duplicate (out)connector assignement for input/output in %1").arg(name()),IssueObject::itWarning);
        }
    }
    if ( mode == cmOUTPUT ){ // skip cmOUTPUt | cmINPUT;
        quint64 pointer = (quint64) ( _outConnector.data());
        quint64 npointer = (quint64) ( connector);
        if ( pointer != npointer || npointer == 0){
            connector->addProperty("connectormode",IlwisObject::cmOUTPUT);
            _outConnector.reset(connector);
        }
        else {
            kernel()->issues()->log(QString("Duplicate (out)connector assignement for input/output in %1").arg(name()),IssueObject::itWarning);
        }
    }

    return true;
}
bool WfsFeatureConnector::loadMetaData(Ilwis::IlwisObject *data, const IOOptions& options)
{
    qDebug() << "WfsFeatureConnector::loadMetaData()";
    if (options.size() > 0) {
        qWarning() << "IOOptions not empty .. not handled for now.";
    }

    QUrl featureUrl = sourceRef().url(true);
    WebFeatureService wfs(featureUrl);
    QUrlQuery queryFeatureType(featureUrl);
    SPWfsResponse featureDescriptionResponse = wfs.describeFeatureType(queryFeatureType);
    WfsFeatureDescriptionParser schemaParser(featureDescriptionResponse);
    FeatureCoverage *fcoverage = static_cast<FeatureCoverage *>(data);

    _context.setResource(_resource);
    return schemaParser.parseMetadata(fcoverage, _context);
}
IOOptions PostgresqlFeatureConnector::merge(const IOOptions &first, const IOOptions &second) {

    IOOptions result;
    auto end = first.end();
    for (auto it = first.begin(); it != end; ++it)
    {
        result.addOption(  it.key(), it.value());
    }

    end = second.end();
    for (auto it = second.begin(); it != end; ++it)
    {
        result.addOption(  it.key(), it.value());
    }

    return result;
}
Example #16
0
bool CatalogConnector::loadDataSingleThread(IlwisObject *obj, const IOOptions &options){
    Catalog *cat = static_cast<Catalog *>(obj);
    kernel()->issues()->log(QString(TR("Scanning %1")).arg(sourceRef().url(true).toString()),IssueObject::itMessage);
    for(const auto& explorer : _dataProviders){

        // TODO clear security issues which may arise here, as
        // all _dataProviders gets passed the ioptions probably
        // not indendet for them

        IOOptions iooptions = options.isEmpty() ? ioOptions() : options;
        std::vector<Resource> items = explorer->loadItems(iooptions);
        cat->addItemsPrivate(items);
        mastercatalog()->addItems(items);



    }
    return true;
}
bool DownloadManager::loadData(IlwisObject *object, const IOOptions &options){
    QUrl url = _resource.url(true);

    QUrlQuery query(url);
    if ( object->ilwisType() == itRASTER){
        RasterCoverage *raster = static_cast<RasterCoverage*>(object);
        _blockSizeBytes = raster->grid()->blockSize(0);
        if ( options.contains("blockindex")){
            _currentBlock = options["blockindex"].toInt();
            int layer = _currentBlock / raster->grid()->blocksPerBand();
            int relativeBlock = _currentBlock - layer * raster->grid()->blocksPerBand();
            unsigned int minLine = raster->grid()->maxLines() * relativeBlock ;
            unsigned int maxLine = std::min( minLine + raster->grid()->maxLines(), raster->size().ysize());
            query.addQueryItem("lines",QString("%1 %2 %3").arg(layer).arg(minLine).arg(maxLine));
        }
    }
    query.addQueryItem("datatype","data");
    url.setQuery(query);
    QString urltxt = url.toString();
    _object = object;
    QNetworkRequest request(url);

    QNetworkReply *reply = kernel()->network().get(request);

    if ( object->ilwisType() == itRASTER)
        connect(reply, &QNetworkReply::readyRead, this, &DownloadManager::readReadyRaster);
    else
        connect(reply, &QNetworkReply::readyRead, this, &DownloadManager::readReady);
    connect(reply, &QNetworkReply::downloadProgress, this, &DownloadManager::downloadProgress);
    connect(reply, static_cast<void (QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error), this, &DownloadManager::error);
    connect(reply, &QNetworkReply::finished, this, &DownloadManager::finishedData);

    QEventLoop loop; // waits for request to complete
    connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
    loop.exec();

    delete reply;

    return true;
}
bool PostgresqlTableConnector::store(IlwisObject *data, const IOOptions& options)
{
    Table *table = static_cast<Table *>(data);
    IOOptions iooptions = options.isEmpty() ? this->ioOptions() : options;
    PostgresqlParameters params (_resource.url(true).toString());
    PostgresqlDatabaseUtil pgUtil(params);
    SqlStatementHelper sqlHelper(params);
    QList<QString> primaryKeys;
    pgUtil.getPrimaryKeys(primaryKeys);
    sqlHelper.addCreateTempTableStmt("data_level_0");
    sqlHelper.addInsertChangedDataToTempTableStmt("data_level_0", table);
    sqlHelper.addUpdateStmt(primaryKeys, "data_level_0", table);
    sqlHelper.addInsertStmt(primaryKeys, "data_level_0", table);

    // TODO delete deleted rows

    //qDebug() << "SQL: " << sqlHelper->sql();

    pgUtil.doQuery(sqlHelper.sql());

    return true;
}
 Table::Table(std::string resource, const IOOptions& opt){
     QString input (QString::fromStdString(resource));
     input.replace('\\','/');
     // if it is file:// (or http:// etc) leave it untouched; if not, append file:// and the working catalog path if it is missing
     if (input.indexOf("://") < 0) {
         int pos = input.indexOf('/');
         if (pos > 0) {
             if ((input.count('/') > 1) || QFileInfo(input).exists()) // full path starting with drive-letter (MS-DOS-style)
                 input = "file:///" + input;
             else // container object without path, e.g. myfile.hdf/subdataset: look for it in workingCatalog()
                 input = "file:///" + Ilwis::context()->workingCatalog()->filesystemLocation().toLocalFile() + '/' + input;
         }  else if (pos == 0) // full path starting with path-separator (UNIX-style)
             input = "file://" + input;
         else { // pos < 0: file without path, or new object
             QString file = Ilwis::context()->workingCatalog()->filesystemLocation().toLocalFile() + '/' + input;
             if (QFileInfo (file).exists()) // file without path
                 input = "file:///" + file;
         }
     }
     Ilwis::ITable t(input, itTABLE, opt.ptr());
     if (t.isValid())
         this->_ilwisObject = std::shared_ptr<Ilwis::IIlwisObject>(new Ilwis::IIlwisObject(t));
 }
bool WfsFeatureConnector::loadData(IlwisObject *data, const IOOptions &options)
{
    qDebug() << "WfsFeatureConnector::loadData()";

    IOOptions iooptions = options.isEmpty() ? ioOptions() : options;
    //if(!loadMetaData(data, iooptions))
    //    return false;

    FeatureCoverage *fcoverage = static_cast<FeatureCoverage *>(data);

    QUrl featureUrl = sourceRef().url(true);
    WebFeatureService wfs(featureUrl);

    QUrlQuery queryFeature(featureUrl);
    SPWfsResponse response = wfs.getFeature(queryFeature);
    WfsFeatureParser featureParser(response, fcoverage);

    featureParser.context(_context);
    featureParser.parseFeatureMembers();

    _binaryIsLoaded = true;
    return _binaryIsLoaded;
}
bool FeatureLayerDrawer::prepare(DrawerInterface::PreparationType prepType, const IOOptions &options)
{
    if(!LayerDrawer::prepare(prepType, options))
        return false;

    if ( hasType(prepType, ptSHADERS) && !isPrepared(ptSHADERS)){
        _vboColor = _shaders.attributeLocation("vertexColor");
        _scaleCenter = _shaders.uniformLocation("scalecenter");
        _scaleFactor = _shaders.uniformLocation("scalefactor");

        _prepared |= DrawerInterface::ptSHADERS;
    }
    if ( hasType(prepType, DrawerInterface::ptGEOMETRY) && !isPrepared(DrawerInterface::ptGEOMETRY)){



        IFeatureCoverage features = coverage().as<FeatureCoverage>();
        if ( !features.isValid()){
            return ERROR2(ERR_COULDNT_CREATE_OBJECT_FOR_2,"FeatureCoverage", TR("Visualization"));
        }
        // set all to 0
        //_indices = std::vector<VertexIndex>();
        _vertices = QVector<QVector3D>();
        _normals = QVector<QVector3D>();
        _colors = std::vector<VertexColor>();
        // get a description of how to render
        VisualAttribute attr = visualProperty(activeAttribute());


        std::vector<std::shared_ptr<BaseSpatialAttributeSetter>> setters(5); // types are 1 2 4, for performance a vector is used thoug not all elements are used
        // for the moment I use the simple setters, in the future this will be representation dependent
        createAttributeSetter(features, setters, rootDrawer());

        _featureDrawings.resize(features->featureCount());
        int featureIndex = 0;
        for(const SPFeatureI& feature : features){
            QVariant value =  attr.columnIndex() != iUNDEF ? feature(attr.columnIndex()) : featureIndex;
            IlwisTypes geomtype = feature->geometryType();
             _featureDrawings[featureIndex] = setters[geomtype]->setSpatialAttributes(feature,_vertices,_normals);
            const QColor& clr = geomtype == itPOLYGON ? _boundaryColor : _lineColor;
            setters[geomtype]->setColorAttributes(attr,value,clr,_featureDrawings[featureIndex],_colors) ;
            ++featureIndex;
        }
        // implicity the redoing of the geometry is also redoing the representation stuff(a.o. colors)
        _prepared |= ( DrawerInterface::ptGEOMETRY | DrawerInterface::ptRENDER);

    }
    if ( hasType(prepType, DrawerInterface::ptRENDER) && !isPrepared(DrawerInterface::ptRENDER)){
        IFeatureCoverage features = coverage().as<FeatureCoverage>();
        int featureIndex = 0;
        std::vector<std::shared_ptr<BaseSpatialAttributeSetter>> setters(5); // types are 1 2 4, for performance a vector is used thoug not all elements are used
        // for the moment I use the simple setters, in the future this will be representation dependent
        createAttributeSetter(features, setters, rootDrawer());
        VisualAttribute attr = visualProperty(activeAttribute());
        if ( !features.isValid()){
            return ERROR2(ERR_COULDNT_CREATE_OBJECT_FOR_2,"FeatureCoverage", TR("Visualization"));
        }
        _colors.resize(0);
        bool polygononly = false;
        if ( options.contains("polygononly"))
            polygononly = options["polygononly"].toBool();

        for(const SPFeatureI& feature : features){
            if ( polygononly && feature->geometryType() != itPOLYGON){
                ++featureIndex;
                continue;
            }
            QVariant value =  attr.columnIndex() != iUNDEF ? feature(attr.columnIndex()) : featureIndex;
            IlwisTypes geomtype = feature->geometryType();
            const QColor& clr = geomtype == itPOLYGON ? _boundaryColor : _lineColor;
            setters[geomtype]->setColorAttributes(attr,value,clr,_featureDrawings[featureIndex],_colors) ;
            ++featureIndex;
        }
        _prepared |= DrawerInterface::ptRENDER;
    }

    //initialize();
    return true;
}