Ilwis::OperationImplementation::State Assignment::prepare(ExecutionContext *, const SymbolTable &) { if ( _expression.parameterCount() != 1) { ERROR3(ERR_ILLEGAL_NUM_PARM3,"assignment","1",QString::number(_expression.parameterCount())); return sPREPAREFAILED; } bool ok; _number = _expression.parm(0).value().toDouble(&ok); if ( !ok) { _number = rILLEGAL; QString coverage = _expression.parm(0).value(); Resource resource = mastercatalog()->name2Resource(coverage); if ( !resource.isValid()) { ERROR1(ERR_COULD_NOT_OPEN_READING_1,coverage); return sPREPAREFAILED; } _inputObj.prepare(coverage, resource.ilwisType()); OperationHelperRaster helper; _outputObj = helper.initialize(_inputObj, resource.ilwisType(), itRASTERSIZE | itENVELOPE | itCOORDSYSTEM | itGEOREF | itDOMAIN | itTABLE); QString outname = _expression.parm(0,false).value(); if ( outname != sUNDEF) _outputObj->setName(outname); } else { _varName = _expression.parm(0,false).value(); } return sPREPARED; }
bool BinaryLogical::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 ERROR2(ERR_INVALID_PROPERTY_FOR_2,"domain","logical operation"); } OperationHelperRaster helper; _box = helper.initialize(_inputGC1, _outputGC, itRASTERSIZE | itENVELOPE | itCOORDSYSTEM | itGEOREF); IDomain dom; dom.prepare("bool"); _outputGC->datadefRef().domain(dom); _coveragecoverage = true; return true; }
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, _expression.parm(0), 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; double rmax, rmin; switch(_operator) { case otPLUS: rmin = nrange1->min() + nrange2->min(); rmax = nrange1->max() + nrange1->max(); break; case otMINUS: rmin = nrange1->min() - nrange2->min(); rmax = nrange1->max() - nrange1->max(); break; case otDIV: rmin = nrange2->min() != 0 ? nrange1->min() / nrange2->min() : std::min(nrange1->min(), nrange2->min()); rmax = nrange2->max() != 0 ? nrange1->max() / nrange2->max() : std::min(nrange1->max(), nrange2->max()); break; case otMULT: rmin = nrange1->min() * nrange2->min(); rmax = nrange1->max() * nrange1->max(); break; } NumericRange *newRange = new NumericRange(rmin, rmax, std::min(nrange1->step(), nrange2->step())); IDomain dom; dom.prepare("value"); _outputGC->datadef().domain(dom); _outputGC->datadef().range(newRange); _coveragecoverage = true; return true; }
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; }
OperationImplementation::State MapCalc::prepare(ExecutionContext *ctx,const SymbolTable &st) { OperationImplementation::prepare(ctx,st); QString expr = _expression.input<QString>(0); RasterStackDefinition stackdef; for(int parmIndex = 1 ; parmIndex < _expression.parameterCount(); ++parmIndex){ Parameter parm = _expression.parm(parmIndex); if ( hasType(parm.valuetype(), itRASTER)){ QString url = parm.value(); IRasterCoverage raster; if(!raster.prepare(url)){ return sPREPAREFAILED; } if ( stackdef.isValid()){ if(!stackdef.checkStackDefintion(raster->stackDefinition())){ kernel()->issues()->log(TR("Incompatible stack definition for ") +raster->name() ) ; return sPREPAREFAILED; } }else if ( raster->stackDefinition().domain()->code().indexOf("count") == -1) stackdef = raster->stackDefinition(); _inputRasters[parmIndex] = PixelIterator(raster); }else if ( hasType(parm.valuetype(), itNUMBER)){ bool ok; double v = parm.value().toDouble(&ok); if (!ok){ return sPREPAREFAILED; } _inputNumbers[parmIndex] = v; } } OperationHelperRaster helper; helper.initialize((*_inputRasters.begin()).second.raster(), _outputRaster, itRASTERSIZE | itENVELOPE | itCOORDSYSTEM | itGEOREF); if ( stackdef.isValid()){ _outputRaster->stackDefinitionRef() = stackdef; } IDomain outputDomain; try { outputDomain = linearize(shuntingYard(expr)); if( !outputDomain.isValid()) return sPREPAREFAILED; } catch(ErrorObject& err){ return sPREPAREFAILED; } _outputRaster->datadefRef().domain(outputDomain); for(quint32 i = 0; i < _outputRaster->size().zsize(); ++i){ QString index = _outputRaster->stackDefinition().index(i); _outputRaster->setBandDefinition(index,DataDefinition(outputDomain)); } initialize(_outputRaster->size().linearSize()); return sPREPARED; }
bool BinaryMathRaster::prepareCoverageNumber(IlwisTypes ptype1, IlwisTypes ptype2) { int mindex = (ptype1 & itNUMBER) == 0 ? 0 : 1; int nindex = mindex ? 0 : 1; 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; _number = _expression.parm(nindex).value().toDouble(); OperationHelperRaster helper; _box = helper.initialize(_inputGC1, _outputGC, _expression.parm(mindex), itRASTERSIZE | itENVELOPE | itCOORDSYSTEM | itGEOREF); auto nrange = _inputGC1->datadef().range().dynamicCast<NumericRange>(); if (nrange.isNull()) return false; double rmax, rmin; switch(_operator) { case otPLUS: rmin = nrange->min() + _number; rmax = nrange->max() + _number; break; case otMINUS: rmin = nrange->min() - _number; rmax = nrange->max() - _number; break; case otDIV: rmin = _number != 0 ? nrange->min() / _number : nrange->min(); rmax = _number != 0 ? nrange->max() / _number : nrange->max(); break; case otMULT: rmin = nrange->min() * _number; rmax = nrange->max() * _number; break; } NumericRange *newRange = new NumericRange(rmin, rmax, nrange->step()); IDomain dom; dom.prepare("value"); _outputGC->datadef().domain(dom); _outputGC->datadef().range(newRange); return true; }
Ilwis::OperationImplementation::State SetAttributeTable::prepare(ExecutionContext *ctx, const SymbolTable &st) { OperationImplementation::prepare(ctx,st); OperationHelper::check([&] ()->bool { return _inputTable.prepare(_expression.input<QString>(0), itTABLE); }, {ERR_COULD_NOT_LOAD_2,_expression.input<QString>(0), "" } ); OperationHelper::check([&] ()->bool { return _inputRaster.prepare(_expression.input<QString>(1), itRASTER); }, {ERR_COULD_NOT_LOAD_2,_expression.input<QString>(1), "" } ); _primaryKey = _expression.input<QString>(2); int index = _inputTable->columnIndex(_primaryKey); if ( index == iUNDEF){ kernel()->issues()->log(TR("Table doesnt contain column ") + _primaryKey); return sPREPAREFAILED; } std::vector<QVariant> values = _inputTable->column(_primaryKey); std::set<QVariant> uniques; int undefs = 0; for(QVariant v : values){ if ( isNumericalUndef(v.toDouble())) ++undefs; else uniques.insert(v); } if ( (uniques.size() + undefs ) != values.size()){ kernel()->issues()->log(TR("Key column must not contain duplicate values")); return sPREPAREFAILED; } ColumnDefinition coldef = _inputTable->columndefinition(index); if ( !coldef.datadef().domain()->isCompatibleWith(_inputRaster->datadef().domain().ptr())){ kernel()->issues()->log(TR("Key column doesnt match raster domain ") + _primaryKey); return sPREPAREFAILED; } OperationHelperRaster helper; helper.initialize(_inputRaster, _outputRaster, itRASTERSIZE | itENVELOPE | itCOORDSYSTEM | itGEOREF|itDOMAIN); for(quint32 i = 0; i < _outputRaster->size().zsize(); ++i){ QString index = _outputRaster->stackDefinition().index(i); DataDefinition datadef = _outputRaster->datadef(i); _outputRaster->setBandDefinition(index,DataDefinition(datadef.domain(), datadef.range()->clone())); } return sPREPARED; }
OperationImplementation::State IffRaster::prepare(ExecutionContext *, const SymbolTable &) { QString raster = _expression.parm(0).value(); if (!_inputGC.prepare(raster)) { ERROR2(ERR_COULD_NOT_LOAD_2,raster,""); return sPREPAREFAILED; } DataDefinition outputDataDef = findOutputDataDef(_expression); OperationHelperRaster helper; helper.initialize(_inputGC, _outputGC, itRASTERSIZE | itENVELOPE | itCOORDSYSTEM | itGEOREF); _outputGC->datadefRef() = outputDataDef; return sPREPARED; }
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; }
Ilwis::OperationImplementation::State SetValueRange::prepare(ExecutionContext *ctx, const SymbolTable &st) { OperationImplementation::prepare(ctx,st); QString objectName = _expression.parm(0).value(); if ( !_raster.prepare(objectName)) { ERROR2(ERR_COULD_NOT_LOAD_2, "raster", objectName); return sPREPAREFAILED; } OperationHelperRaster helper; _box = helper.initialize(_raster, _outputRaster, itRASTERSIZE | itENVELOPE | itCOORDSYSTEM | itGEOREF|itDOMAIN); QString minTxt = _expression.parm(1).value(); QString maxTxt = _expression.parm(2).value(); bool ok = true; _step = _raster->datadef().domain()->range<NumericRange>()->resolution(); if ( minTxt.trimmed() != ""){ _min = minTxt.toDouble(&ok); } if ( maxTxt.trimmed() != ""){ _max = maxTxt.toDouble(&ok); } if ( _expression.parameterCount() == 4) { QString stepTxt = _expression.parm(3).value(); if ( stepTxt.trimmed() != ""){ _step = stepTxt.toDouble(&ok); } } auto indexes = _raster->stackDefinition().indexes(); _raster->setDataDefintions(_raster->datadef().domain(),indexes); if ( !ok) { ERROR2(ERR_ILLEGAL_VALUE_2, TR("parameter"),TR("expression")); return sPREPAREFAILED; } initialize(_outputRaster->size().linearSize()); return sPREPARED; }
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; }
bool BinaryLogical::prepareCoverageNumber(IlwisTypes ptype1, IlwisTypes ptype2) { int mindex = (ptype1 & itNUMBER) == 0 ? 0 : 1; int nindex = mindex ? 0 : 1; 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; _number = _expression.parm(nindex).value().toDouble(); OperationHelperRaster helper; _box = helper.initialize(_inputGC1, _outputGC, itRASTERSIZE | itENVELOPE | itCOORDSYSTEM | itGEOREF); IDomain dom; dom.prepare("boolean"); _outputGC->datadefRef().domain(dom); return true; }