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; }
void BaseTable::adjustRange(int index) { ColumnDefinition& coldef = columndefinitionRef(index); if (!coldef.isValid()) return; if( hasType(coldef.datadef().domain<>()->ilwisType(), itNUMERICDOMAIN)) { SPNumericRange rng = coldef.datadef().range<NumericRange>(); std::vector<QVariant> values = column(coldef.id()); if ( values.size() > 0 && !rng.isNull()) { double vmin=1e208, vmax=-1e208; bool hasfraction = true; for(const QVariant& var : values ){ double v = var.toDouble(); if ( !isNumericalUndef2(v, this)) vmin = std::min(vmin, v) ; v = var.toDouble(); if (!isNumericalUndef2(v, this)) { vmax = std::max(vmax, v) ; } hasfraction |= (v - (qint64)v != 0); } if ( vmin != 1e208 && vmax != -1e208) { //something has changed rng->min(vmin); rng->max(vmax); if (!hasfraction) rng->resolution(1); } } } else if ( hasType(coldef.datadef().domain<>()->ilwisType(), itITEMDOMAIN)) { SPItemRange rng = coldef.datadef().range<ItemRange>(); SPItemRange rngDomain = coldef.datadef().domain<>()->range<ItemRange>(); std::vector<QVariant> values = column(coldef.id()); if ( values.size() > 0 && !rng.isNull()) { rng->clear(); for(auto qval : values) { quint32 id = qval.toUInt(); SPDomainItem item = rngDomain->item(id); if ( !item.isNull()) { rng->add(item->clone()); } } } } coldef.changed(false); }