bool CreateIdentifierDomain::execute(ExecutionContext *ctx, SymbolTable &symTable) { if (_prepState == sNOTPREPARED) if((_prepState = prepare(ctx, symTable)) != sPREPARED) return false; INamedIdDomain nameiddomain; nameiddomain.prepare(); nameiddomain->setDescription(_domaindesc); if ( _parentdomain.isValid()) nameiddomain->setParent(_parentdomain); for(int i=0; i < _items.size(); ++i) { nameiddomain->addItem(new NamedIdentifier(_items[i])); } QVariant value; value.setValue<IDomain>(nameiddomain); ctx->setOutput(symTable,value,nameiddomain->name(),itDOMAIN,nameiddomain->source()); return true; }
Ilwis::OperationImplementation::State CreateRasterCoverage::prepare(ExecutionContext *ctx, const SymbolTable &st) { OperationImplementation::prepare(ctx,st); auto CreateStackDomain = [&](const QString& dom)-> Ilwis::OperationImplementation::State{ _stackDomain.prepare(dom); if ( !_stackDomain.isValid()){ kernel()->issues()->log(QString(TR("%1 is and invalid stack domain")).arg(dom)); return sPREPAREFAILED; } return sPREPARED; }; QString grf = _expression.input<QString>(0); _grf.prepare(grf); if ( !_grf.isValid()){ kernel()->issues()->log(QString(TR("%1 is and invalid georeference")).arg(grf)); return sPREPAREFAILED; } QString maps = _expression.input<QString>(2); if ( maps != sUNDEF && (maps.indexOf("?") != -1 || maps.indexOf("*") != -1)){ maps = OperationHelper::expandWildCards(maps); } if (maps != "" && maps != sUNDEF && maps != "default"){ QStringList bands = maps.split(","); for(QString band : bands){ IRasterCoverage raster(band); if ( raster.isValid() && ( raster->georeference()->isCompatible(_grf) || _autoresample)){ _bands.push_back(raster); _ranges.push_back(raster->datadef().range()->clone()); }else{ kernel()->issues()->log(QString(TR("%1 is and invalid band; raster can not be build")).arg(raster->name())); return sPREPAREFAILED; } } } QString dom = _expression.input<QString>(1); if ( dom == "as bands"){ if (_bands.size() > 0) dom = _bands[0]->datadef().domain()->resource().url().toString(); else dom = "value"; } _domain.prepare(dom); if ( !_domain.isValid()){ kernel()->issues()->log(QString(TR("%1 is and invalid domain")).arg(dom)); return sPREPAREFAILED; } QString potentialCatalog = _expression.input<QString>(4); ICatalog cat; if (cat.prepare(potentialCatalog, { "mustexist", true })) { auto resources = cat->items(); QString domainName = _expression.input<QString>(3); QString path = cat->resource().container().toString(); INamedIdDomain dom; if (dom.prepare(domainName, { "extendedtype",itNAMEDITEM})) { for (auto resource : resources) { NamedIdentifier *item = new NamedIdentifier(resource.name()); dom->addItem(item); } dom->connectTo(path + "/" + domainName, "domain", "stream", IlwisObject::cmOUTPUT); dom->store(); _stackDomain = dom; for (auto band : _bands) _stackValueStrings.push_back(band->name()); } } else { _stackDomain = IDomain("positiveInteger"); _stackValueStrings = { "1" }; _stackValueNumbers = { 1 }; } if ( _expression.parameterCount() >= 4){ for(int i=3; i < _expression.parameterCount(); ++i){ if ( hasType(_expression.parm(i).valuetype(),itSTRING|itINTEGER)){ ParseStackDefinition parser; parser.parseStackDefintion(_expression.input<QString>(i), _bands.size(), _stackDomain,_stackValueStrings, _stackValueNumbers); } else if ( hasType(_expression.parm(i).valuetype(),itDOMAIN)){ if (CreateStackDomain(_expression.input<QString>(i)) == sPREPAREFAILED) return sPREPAREFAILED; } else if ( hasType(_expression.parm(i).valuetype(),itBOOL) && maps.size() != 0){ _autoresample = _expression.input<bool>(i); } } } _outputRaster.prepare(); _outputRaster->georeference(_grf); _outputRaster->size( Size<>(_grf->size().xsize(), _grf->size().ysize(), std::max(_stackValueNumbers.size(), _stackValueStrings.size()))); if ( _stackDomain->ilwisType() == itNUMERICDOMAIN) _outputRaster->setDataDefintions(_domain, _stackValueNumbers , _stackDomain); else _outputRaster->setDataDefintions(_domain, _stackValueStrings, _stackDomain); for(quint32 i=0; i < _ranges.size(); ++i){ if ( i < _outputRaster->size().zsize()){ _outputRaster->datadefRef(i).range(_ranges[i]); } } initialize(_outputRaster->size().linearSize()); return sPREPARED; }