OperationImplementation::State UnaryMathRasterAndNumber::prepare(ExecutionContext *ctx,const SymbolTable &st)
{
    OperationImplementation::prepare(ctx,st);
    IlwisTypes ptype = _expression.parm(0).valuetype();


    if ( hasType(ptype,itNUMBER) ) {
        _case = otNUMBER;
        bool ok;
        _number = _expression.parm(0).value().toDouble(&ok);
        if (!ok) {
            ERROR2(ERR_NO_OBJECT_TYPE_FOR_2,"Numerical value", "UnaryMathRasterAndNumber operation");
            _number = rUNDEF;
            return sPREPAREFAILED;
        }
        return sPREPARED;

    } else if ( hasType(ptype,itRASTER)) {
        QString raster = _expression.parm(0).value();

        if (!_inputGC.prepare(raster)) {
            ERROR2(ERR_COULD_NOT_LOAD_2,raster,"");
            return sPREPAREFAILED;
        }
        OperationHelperRaster helper;
        _box = helper.initialize(_inputGC, _outputGC, itRASTERSIZE | itENVELOPE | itCOORDSYSTEM | itGEOREF);
        if ( !_outputGC.isValid()) {
            ERROR1(ERR_NO_INITIALIZED_1, "output rastercoverage");
            return sPREPAREFAILED;
        }
        QString outputName = _expression.parm(0,false).value();
        if ( outputName != sUNDEF)
            _outputGC->name(outputName);

        auto nrange = _inputGC->datadef().range<NumericRange>();
        if (nrange.isNull())
            return sPREPAREFAILED;

        NumericRange *newRange = constructRangeFrom(nrange);

        IDomain dom;
         if(!dom.prepare(_outputDomain))
             return sPREPAREFAILED;

         _outputGC->datadefRef().domain(dom);
         _outputGC->datadefRef().range(newRange);
        for(quint32 i=0; i<_outputGC->size().zsize(); ++i){
                QString index = _outputGC->stackDefinition().index(i);
             _outputGC->setBandDefinition(index,{dom, newRange->clone()});
         }
        _case = otSPATIAL;
        return sPREPARED;
    }
    return sNOTPREPARED;
}
Esempio n. 2
0
void IntervalRange::load(QDataStream &stream)
{
    quint32 size;
    stream >> size;
    for(int i =0; i < size; ++i)    {
        QString label, desc;
        quint32 raw;
        stream >> raw >> label >> desc;
        NumericRange rng;
        rng.load(stream);
        Interval *interval = new Interval(label, rng);
        interval->description(desc);
        add(interval);
    }
}
Esempio n. 3
0
void ChartModel::fillXValues()
{
   _xvalues.clear();
    NumericRange rng = Ilwis::MathHelper::roundRange(0, _table->table()->recordCount());
    double scale = rng.max() / _chartWidth;
    int marker = rng.min();
    for( int x = 0; x < _chartWidth; ++x){
        double value = x * scale;
        if ( value > marker){
            _xvalues.push_back(QString::number(marker));
            marker += rng.resolution();
        }else
            _xvalues.push_back("");
    }
}
bool SetValueRange::execute(ExecutionContext *ctx, SymbolTable &symTable)
{
    if (_prepState == sNOTPREPARED)
        if((_prepState = prepare(ctx, symTable)) != sPREPARED)
            return false;

    DataDefinition& datadef = _outputRaster->datadefRef();
    const SPNumericRange numrange = datadef.range<NumericRange>();
    const SPNumericRange rngDomain = datadef.domain()->range<NumericRange>();
    double lmin = _min == rUNDEF ? numrange->min() : std::max(_min, rngDomain->min());
    double lmax = _max == rUNDEF ? numrange->max() : std::min(_max, rngDomain->max());
    double lstep = _step == rUNDEF ? numrange->resolution() : std::max(_step, rngDomain->resolution());
    NumericRange *rng = new NumericRange(lmin, lmax,lstep);
    datadef.range(rng);
    datadef.domain()->range(rng);


    std::function<bool(const BoundingBox)> SetValrange = [&](const BoundingBox box ) -> bool {
        PixelIterator iter(_raster, box);
        PixelIterator iterOut(_outputRaster, box);
        auto end =  iter.end();
        while(iter != end){
            double val = *iter;
            if ( val != rUNDEF){
                double v = rng->ensure(val).value<double>();
                val = v;
            }
            *iterOut = val;
            updateTranquilizer(iterOut.linearPosition(), 1000);
            ++iter;
            ++iterOut;
        };
        return true;
    };
    bool ok = OperationHelperRaster::execute(ctx, SetValrange, _outputRaster);
    _outputRaster->datadefRef().range<NumericRange>()->resolution(_step);
    for(int i=0; i < _outputRaster->size().zsize(); ++i){
        _outputRaster->datadefRef(i).range<NumericRange>()->resolution(_step)    ;
    }

    QVariant value;
    value.setValue<IRasterCoverage>(_outputRaster);
    _outputRaster->addDescription(_expression.toString());
    ctx->setOutput(symTable,value,_outputRaster->name(), itRASTER,_outputRaster->resource() );
    return ok;
}
Esempio n. 5
0
QColor LayerDrawer::color(const IRepresentation &rpr, double value, DrawerInterface::ColorValueMeaning cvm)
{
    if ( _activeAttribute != sUNDEF){
        VisualAttribute& attr = _visualProperties[_activeAttribute];
        if ( cvm ==DrawerInterface::cvmFRACTION){
            NumericRange numrange = attr.stretchRange();
            if ( !numrange.isValid()){
                numrange = attr.actualRange();
            }
            value = numrange.min() + numrange.distance() * value;

        }
        QColor clr = attr.value2color(value);
        return clr;
    }
    return QColor();
}
bool BinaryMathRaster::prepareCoverageCoverage() {
    QString raster =  _expression.parm(0).value();
    if (!_inputGC1.prepare(raster)) {
        kernel()->issues()->log(TR(ERR_COULD_NOT_LOAD_2).arg(raster, ""));
        return false;
    }
    raster =  _expression.parm(1).value();
    if (!_inputGC2.prepare(raster)) {
        kernel()->issues()->log(TR(ERR_COULD_NOT_LOAD_2).arg(raster, ""));
        return false;
    }
    bool isNumeric = _inputGC1->datadef().domain<>()->ilwisType() == itNUMERICDOMAIN && _inputGC2->datadef().domain<>()->ilwisType() == itNUMERICDOMAIN;
    if (!isNumeric)
        return false;

    OperationHelperRaster helper;
    _box = helper.initialize(_inputGC1, _outputGC, itRASTERSIZE | itENVELOPE | itCOORDSYSTEM | itGEOREF);

    auto nrange1 = _inputGC1->datadef().range().dynamicCast<NumericRange>();
    if (nrange1.isNull())
        return false;

    auto nrange2 = _inputGC2->datadef().range().dynamicCast<NumericRange>();
    if (nrange2.isNull())
        return false;

    NumericRange *newRange = constructRangeFrom(nrange1, nrange2);

    IDomain dom;
    dom.prepare("value");
    _outputGC->datadefRef().domain(dom);
    _outputGC->datadefRef().range(newRange);

    for(quint32 i = 0; i < _outputGC->size().zsize(); ++i){
     QString index = _outputGC->stackDefinition().index(i);
        _outputGC->setBandDefinition(index,DataDefinition(dom,newRange->clone()));
    }

    _coveragecoverage = true;
    return true;
}
Esempio n. 7
0
void ChartModel::fillYValues(QList<QVariant>& yvalues, IlwisTypes valueTypeYAxis, int columnIndex)
{
    QVariant oldValue = 0;
    std::vector<QVariant> values = _table->table()->column(columnIndex);
    NumericRange rng = Ilwis::MathHelper::roundRange(0, _table->table()->recordCount());
    double scale = rng.max() / _chartWidth;
    for( int x = 0; x < _chartWidth; ++x){
        int index = x * scale;
        if ( index < values.size()){

            QVariant v = values[index];
            if ( hasType(valueTypeYAxis,itNUMBER)){
                if ( v == rUNDEF)
                    v = oldValue;
                else
                    oldValue = v;
            }
            yvalues.push_back(v);
        }
    }
}
bool BinaryMathRaster::prepareCoverageNumber(IlwisTypes ptype1, IlwisTypes ptype2) {

    int mindex = (ptype1 & itNUMBER) == 0 ? 0 : 1;
    int nindex = mindex ? 0 : 1;

    _firstorder = mindex > nindex;
    QString raster =  _expression.parm(mindex).value();
    if (!_inputGC1.prepare(raster)) {
        kernel()->issues()->log(TR(ERR_COULD_NOT_LOAD_2).arg(raster, ""));
        return false;
    }
    if(_inputGC1->datadef().domain<>()->ilwisType() != itNUMERICDOMAIN)
        return false;

    _number1 = _expression.parm(nindex).value().toDouble();

    OperationHelperRaster helper;
    _box = helper.initialize(_inputGC1, _outputGC,itRASTERSIZE | itENVELOPE | itCOORDSYSTEM | itGEOREF);

    auto nrange = _inputGC1->datadef().range<NumericRange>();
    if (nrange.isNull())
        return false;

    NumericRange *newRange = constructRangeFrom(nrange, _number1);

    IDomain dom;
    dom.prepare("value");
    _outputGC->datadefRef().domain(dom);
    _outputGC->datadefRef().range(newRange);

    for(quint32 i = 0; i < _outputGC->size().zsize(); ++i){
        QString index = _outputGC->stackDefinition().index(i);
        _outputGC->setBandDefinition(index,DataDefinition(dom,newRange->clone()));
    }

    return true;
}
void NumericRepresentationSetter::prepare(VisualAttributeModel *vattrib, const IIlwisObject &obj, const ColumnDefinition &cdef)
{
    VisualAttributeEditor::prepare(vattrib, obj, cdef);

    if ( attribute()->layer() && attribute()->layer()->drawer()){
        QVariant actAttribute = attribute()->layer()->drawer()->attribute("activevisualattribute");
           if ( !actAttribute.isValid())
               return ;
        auto var = attribute()->layer()->drawer()->attribute("visualattribute|stretchrange|" + actAttribute.toString());
        NumericRange numrange = var.value<NumericRange>();
        if ( !numrange.isValid())
            return;

        NumericRange roundedRange = MathHelper::roundRange(numrange.min(), numrange.max());
        double tickValue = roundedRange.min();
        while(tickValue <= numrange.max()){
            _rprElements.push_back(new RepresentationElement(QString::number(tickValue),this));
            tickValue += roundedRange.resolution();
        }
        _rprElements.push_back(new RepresentationElement(QString::number(tickValue),this));

        emit rprNameChanged();
    }
}
Esempio n. 10
0
Range *NumericRange::clone() const {
    NumericRange *rng = new NumericRange(_min, _max, _resolution);
    rng->interpolation(interpolation());
    return rng;
}
Esempio n. 11
0
bool NumericRange::operator<=(const NumericRange &vr)
{
    return max() <= vr.max() && min() <= vr.min() && max() <= vr.min();
}
Esempio n. 12
0
bool NumericRange::operator>(const NumericRange &vr)
{
    return max() > vr.max() && min() > vr.min() && min() > vr.max();
}
Esempio n. 13
0
bool NumericRange::operator==(const NumericRange& vr) {
    return vr.max() == max() && vr.min() == min() && vr.resolution() == resolution();
}