bool ColumnUnaryOperation::execute(ExecutionContext *ctx, SymbolTable &symTable) { if (_prepState == sNOTPREPARED) if((_prepState = prepare(ctx, symTable)) != sPREPARED) return false; std::vector<QVariant> data(_inputTable->recordCount(), _number1),outdata(1, rUNDEF); if ( _column1 != sUNDEF) data = _inputTable->column(_column1); auto iter1 = data.begin(); std::vector<double> values(data.size()); int i=0; for(auto v : data){ values[i++] = v.toDouble(); } NumericStatistics stats; stats.calculate(values.begin(), values.end(),_method); double outputData = stats[_method]; std::for_each(outdata.begin(), outdata.end(),[&](QVariant& v){ v = outputData; ++iter1; }); _outputTable->column(_outColumn,outdata); if ( _outputTable.isValid()){ QVariant var; var.setValue<ITable>(_outputTable); ctx->setOutput(symTable,var, _outputTable->name(),itTABLE,_outputTable->source(),_outColumn); return true; } return false; }
QString IlwisObjectModel::rangeDefinition(bool defaultRange, bool calc, const QString& columnName) { try { IlwisTypes objectype = _ilwisobject->ilwisType(); QString rangeString; if ( hasType( objectype, itCOVERAGE|itDOMAIN)){ if ( objectype == itRASTER){ IRasterCoverage raster = _ilwisobject.as<RasterCoverage>(); if ( defaultRange){ rangeString = raster->datadef().domain()->range()->toString(); }else{ if ( calc){ raster->loadData(); raster->statistics(NumericStatistics::pBASIC); } rangeString = raster->datadef().range()->toString(); } } else if ( hasType( objectype , itFEATURE)){ IFeatureCoverage features = _ilwisobject.as<FeatureCoverage>(); ColumnDefinition coldef = features->attributeDefinitions().columndefinition(COVERAGEKEYCOLUMN); if ( coldef.isValid()){ if ( defaultRange) rangeString = coldef.datadef().domain()->range()->toString(); else{ if ( calc){ features->loadData(); std::vector<QVariant> data = features->attributeTable()->column(columnName); if ( data.size() != 0){ std::vector<double> values(data.size()); int i=0; for(auto v : data) values[i++] = v.toDouble(); NumericStatistics stats; // realy like to do this with a template specialization of the proper calculate function, but the syntax was unclear to me stats.calculate(values.begin(), values.end()); NumericRange *rng = new NumericRange(stats.prop(NumericStatistics::pMIN),stats.prop(NumericStatistics::pMAX)); features->attributeDefinitionsRef().columndefinitionRef(columnName).datadef().range(rng); } } rangeString = coldef.datadef().range()->toString(); } } } else if ( hasType( objectype , itDOMAIN)){ rangeString = _ilwisobject.as<Domain>()->range()->toString(); } } return rangeString; }catch(const ErrorObject& ){ // no exceptions may escape here } return ""; }
bool AggregateRaster::execute(ExecutionContext *ctx, SymbolTable& symTable) { if (_prepState == sNOTPREPARED) if((_prepState = prepare(ctx,symTable)) != sPREPARED) return false; IRasterCoverage outputRaster = _outputObj.as<RasterCoverage>(); quint64 currentCount = 0; BoxedAsyncFunc aggregateFun = [&](const BoundingBox& box) -> bool { //Size sz = outputRaster->size(); PixelIterator iterOut(outputRaster, box); BoundingBox inpBox(Pixel(box.min_corner().x, box.min_corner().y * groupSize(1), box.min_corner().z * groupSize(2)), Pixel((box.max_corner().x+1) * groupSize(0) - 1, (box.max_corner().y + 1) * groupSize(1) - 1, (box.max_corner().z + 1) * groupSize(2) - 1) ); BlockIterator blockIter(_inputObj.as<RasterCoverage>(),Size<>(groupSize(0),groupSize(1), groupSize(2)), inpBox); NumericStatistics stats; PixelIterator iterEnd = iterOut.end(); while(iterOut != iterEnd) { GridBlock& block = *blockIter; stats.calculate(block.begin(), block.end(), _method); double v = stats[_method]; *iterOut = v; ++iterOut; ++blockIter; updateTranquilizer(currentCount++, 1000); } return true; }; bool res = OperationHelperRaster::execute(ctx, aggregateFun, outputRaster); if ( res && ctx != 0) { QVariant value; value.setValue<IRasterCoverage>(outputRaster); ctx->setOutput(symTable,value,outputRaster->name(), itRASTER, outputRaster->source() ); } return res; }