void tableCase(const IIlwisObject &obj, const QString& condition, int parmIndex, QVariantList& result)
{
    ITable tbl ;
    if (hasType(obj->ilwisType(), itCOVERAGE)){
        ICoverage coverage = obj.as<Coverage>();
        tbl = coverage->attributeTable();
    }else if (hasType(obj->ilwisType(), itTABLE) ){
        tbl = obj.as<Table>();
    }
    QVariantMap mp;
    mp["parameterIndex"] = parmIndex;
    QStringList names;
    int index;
    IlwisTypes domainType = itTEXTDOMAIN | itITEMDOMAIN | itNUMERICDOMAIN;
    if ( (index = condition.indexOf(" with ")) != -1){
        QString domainPart = condition.mid(index + 6);
        QStringList parts = domainPart.split("=");
        QVariantMap mp;
        if ( parts.size() == 2){
            QStringList types = parts[1].split(",");
            IlwisTypes domainType = 0;
            for(auto tp: types){
                domainType |= IlwisObject::name2Type(tp);
            }
      }
    }
    for(int c=0; c < tbl->columnCount(); ++c){
        if ( domainType != itUNKNOWN){
            DataDefinition def = tbl->columndefinition(c).datadef();
            if ( hasType(def.domain()->ilwisType(), domainType))
               names.append(tbl->columndefinition(c).name());
        }else {
            names.append(tbl->columndefinition(c).name());
        }
    }
    mp["result"] = names;
    mp["uielement"] = "list";
    result.append(mp);
}
Esempio n. 2
0
SelectionBase::ExpressionPart::ExpressionPart(const ICoverage& coverage, const QString& p){
    QString part = p.trimmed();
    _isValid = false;
    int index;
    if ( (index = part.indexOf("envelope("))!= -1) {
        _envelope = QString(part).replace("envelope", "box");
        _isValid = _envelope.isValid();
        _type = ptENVELOPE;
        if ( coverage->ilwisType() == itRASTER && _envelope.isValid()){
            IRasterCoverage raster = coverage.as<RasterCoverage>();
            _box = raster->georeference()->coord2Pixel(_envelope);
            //setEnvelopePolygon(raster);
        }
    } else if ((index = part.indexOf("boundingbox("))==0){
        _box = QString(part).replace("boundingbox", "box");
        _isValid = _box.isValid();
        _type = ptBOX;

    }else if ( (index = part.indexOf("polygon(")) != -1){
        _polygon.reset(GeometryHelper::fromWKT(part,0));
        _isValid = _polygon.get() != 0;
        _type = ptPOLYGON;

    }else if ( part.indexOf("attributes(")!= -1) {
        index = part.indexOf("(");
        int len = part.lastIndexOf(")") - index - 1;
        QString lst = part.mid(index + 1, len);
        QStringList attribs = lst.split(",");
        for(auto attrib : attribs){
            if ( coverage->attributeTable()->columnIndex(attrib) != iUNDEF)    {
                _attributes.push_back(attrib);
                _isValid = true;
            }
        }
        _type = ptATTRIBUTE;
    } else if (part.indexOf("rasterbands(")!=-1){
        index = part.indexOf("(");
        int len = part.lastIndexOf(")") - index - 1;
        QString lst = part.mid(index + 1, len);
        QStringList indexes = lst.split(",");
        IRasterCoverage raster = coverage.as<RasterCoverage>();
        for(auto ind : indexes){
            if (raster->stackDefinition().index(ind) != iUNDEF){
                _bands.push_back(ind);
                _isValid = true;
            }
        }
        _type = ptBANDS;

    }else if ((index = part.indexOf("featuretype("))==0){
        QString ft = part.mid(index + 1);
        if ( ft == "point")
            _geometryType = itPOINT;
        if ( ft == "line")
            _geometryType = itLINE;
        if ( ft == "polygon"){
            _geometryType = itPOLYGON;
        }
        _isValid = true;

    }else {
        std::map<QString,LogicalOperator> operators = {{"==", loEQ},{"<=",loLESSEQ},{">=", loGREATEREQ},{"<",loLESS},{">", loGREATER},{"!=",loNEQ}};
        int index1 = part.indexOf("\"");
        if ( index1 == -1)
            index1 = 10000;
        int index2 = 0;
        for(auto op : operators){
            if ((index2 = part.indexOf(op.first)) != -1){
                if ( index2 < index1)    {
                    _operator = op.second;
                    QString rights = part.mid(index2 + op.first.size()).trimmed();
                    _rightSide = rights.remove("\'");
                    QString leftSide = part.left(index2).trimmed();
                    if ( leftSide.toLower() == "pixelvalue"){
                        _leftSide = iUNDEF;
                        _isValid = true;
                    }else {
                        if ( (_leftSide = coverage->attributeTable()->columnIndex(leftSide)) == iUNDEF){
                            _isValid = false;
                        }else {
                            ColumnDefinition coldef = coverage->attributeTable()->columndefinition(_leftSide);
                            QVariant val = coldef.datadef().domain()->impliedValue(_rightSide);
                            _rightSide = val;
                        }
                    }

                    _type = ptATTRIBUTESELECTION;
                    break;
                }
            }
        }
    }
}