コード例 #1
0
ファイル: domainmerger.cpp プロジェクト: 52North/IlwisCore
void ItemDomainMergerNamedItems::renumber(const std::unique_ptr<NamedIdentifierRange>& newRange,
                                          const QSharedPointer<NamedIdentifierRange>& range1,
                                          QSharedPointer<NamedIdentifierRange>& range2 ) {
    quint32 maxraw = 0;
    for(int i=0; i < range1->count(); ++i) {
        maxraw = std::max(range1->itemByOrder(i)->raw(), maxraw);
    }
    for(int i=0; i < newRange->count(); ++i)    {
        SPDomainItem item = newRange->item(i);
        bool inrange1 = range1->contains(item->name());
        bool inrange2 = range2->contains(item->name());
        if ( !inrange1 && inrange2){
            _renumber[item->raw()] = ++maxraw;
            item->raw(maxraw);
        }
    }
}
コード例 #2
0
QVariant AttributeDefinition::checkInput(const QVariant& inputVar, quint32 columnIndex)  const{
    QVariant actualval= inputVar;
    const ColumnDefinition& coldef = columndefinitionRef(columnIndex);
    QString typenm = inputVar.typeName();
    if ( !coldef.datadef().domain<>().isValid()){
        ERROR2(ERR_NO_INITIALIZED_2,"Domain",coldef.name());
        return QVariant();
    }
    IlwisTypes domtype = coldef.datadef().domain<>()->ilwisType();
    IlwisTypes valueType = coldef.datadef().domain<>()->valueType();
    IDomain dm = coldef.datadef().domain<>();
    if ( domtype == itITEMDOMAIN){
        if ( inputVar == sUNDEF){
            return QVariant((int)iUNDEF);
        } else if ( typenm == "QString"){
            actualval = dm->impliedValue(inputVar);

            SPItemRange rng2 = coldef.datadef().range<ItemRange>();

            if ( !hasType(valueType,itINDEXEDITEM)){
                SPItemRange rng1 = dm->range<ItemRange>();
                SPDomainItem item = rng1->item(inputVar.toString());
                if ( item.isNull()){
                    return QVariant((int)iUNDEF);
                }
                if ( !rng2->contains(item->name())){
                    rng2->add(item->clone());
                }
                actualval = item->raw();
            }
        }

    }else if ( domtype == itNUMERICDOMAIN){
        if (typenm == "QString")
            actualval =  dm->impliedValue(inputVar);
        if ( hasType(valueType,itDATETIME) && actualval.value<Ilwis::Time>() == tUNDEF)
            return actualval;
        else if (isNumericalUndef(actualval.toDouble()))
            return rUNDEF;
        if (! dm->contains(actualval))
            actualval = rUNDEF;
        else {
            SPNumericRange rng = coldef.datadef().range<NumericRange>();
            if ( !rng.isNull()){
                if ( hasType(valueType,itDATETIME))
                    rng->add(actualval.value<Ilwis::Time>());
                else
                    rng->add(actualval.toDouble());
            }
        }
    } else if ( domtype == itTEXTDOMAIN){
        return dm->impliedValue(inputVar);
    }
    return actualval;
}
コード例 #3
0
ファイル: mapcalc.cpp プロジェクト: 52North/IlwisCore
bool MapCalc::execute(ExecutionContext *ctx, SymbolTable& symTable)
{
     if (_prepState == sNOTPREPARED)
        if((_prepState = prepare(ctx, symTable)) != sPREPARED)
            return false;

    PixelIterator iterOut(_outputRaster);

    PixelIterator iterEnd = end(iterOut);
    while(iterOut != iterEnd) {
        double v = calc();
        *iterOut = v;
        ++iterOut;
        for(auto& item : _inputRasters){
            ++(item.second);
        }
        updateTranquilizer(iterOut.linearPosition(), 1000);
    }

    if ( _outputRaster->datadef().domain()->ilwisType() == itNUMERICDOMAIN){
        double rmin = rUNDEF, rmax= rUNDEF;
        bool isInt = true;
        for(double v : _outputRaster ){
            rmin = Ilwis::min(rmin, v);
            rmax = Ilwis::max(rmax, v);
            if ( v != rUNDEF){
                isInt &=  std::abs((qint64)v - v) <EPS8;
            }
        }
        NumericRange *range = new NumericRange(rmin,rmax, isInt ? 1 : 0);
        _outputRaster->datadefRef().range(range);
    }else {
        IFlatTable tbl;
        tbl.prepare();
        tbl->addColumn(_outputRaster->primaryKey(),_outputRaster->datadef().domain());
        int rec = 0;
        ItemRangeIterator iter(_outputRaster->datadef().range<>().data());
        while (iter.isValid()) {
            SPDomainItem item = (*iter);
            tbl->setCell(0,rec++,item->raw());
            ++iter;
        }
        _outputRaster->setAttributes(tbl);

    }

    QVariant value;
    value.setValue<IRasterCoverage>(_outputRaster);
    logOperation(_outputRaster, _expression);
    ctx->setOutput(symTable,value,_outputRaster->name(), itRASTER,_outputRaster->resource() );

    return true;
}