void IlwisObjectModel::resetAttributeModel(const QString& attributeName){ auto setAttributeModel = [&](int i, const ColumnDefinition& coldef, const QString& attributeName){ if ( coldef.name() == attributeName){ AttributeModel *attribute = new AttributeModel(coldef, this, _ilwisobject); _attributes[i] = attribute; } }; IlwisTypes objecttype = _ilwisobject->ilwisType(); if ( objecttype == itRASTER){ IRasterCoverage raster = _ilwisobject.as<RasterCoverage>(); if ( raster->hasAttributes()){ for(int i = 0; i < raster->attributeTable()->columnCount(); ++i){ setAttributeModel(i,raster->attributeTable()->columndefinition(i), attributeName); } } } else if ( hasType(objecttype,itFEATURE)){ IFeatureCoverage features = _ilwisobject.as<FeatureCoverage>(); for(int i = 0; i < features->attributeDefinitions().definitionCount(); ++i){ setAttributeModel(i,features->attributeTable()->columndefinition(i), attributeName); } } else if ( hasType(objecttype,itTABLE)){ ITable tbl = _ilwisobject.as<Table>(); for(int i = 0; i < tbl->columnCount(); ++i){ setAttributeModel(i,tbl->columndefinition(i),attributeName); } } }
IIlwisObject OperationHelperRaster::initialize(const IIlwisObject &inputObject, IlwisTypes tp, quint64 what) { Resource resource(tp); if (inputObject->ilwisType() & itCOVERAGE) { ICoverage cov = inputObject.as<Coverage>(); if (inputObject->ilwisType() == itRASTER) { IRasterCoverage gcInput = inputObject.as<RasterCoverage>(); if ( what & itRASTERSIZE) { Size<> sz = gcInput->size(); BoundingBox box(sz); resource.addProperty("size", IVARIANT(box.size())); } if ( what & itGEOREF) { resource.addProperty("georeference", IVARIANT(gcInput->georeference())); } if ( what & itDOMAIN) { resource.addProperty("domain", IVARIANT(gcInput->datadef().domain())); } } if ( what & itCOORDSYSTEM) { resource.addProperty("coordinatesystem", IVARIANT(cov->coordinateSystem())); } } resource.prepare(); IIlwisObject obj; obj.prepare(resource); if (inputObject->ilwisType() & itCOVERAGE) { OperationHelper::initialize(inputObject, obj, tp, what); } return obj; }
QString IlwisObjectModel::valuetype() const { try{ if ( !_ilwisobject.isValid()) return ""; IlwisTypes objectype = _ilwisobject->ilwisType(); IlwisTypes valueType = itUNKNOWN; if ( hasType( objectype, itCOVERAGE|itDOMAIN)){ if ( objectype == itRASTER){ IRasterCoverage raster = _ilwisobject.as<RasterCoverage>(); valueType = raster->datadef().domain()->valueType(); } else if ( hasType( objectype , itFEATURE)){ IFeatureCoverage features = _ilwisobject.as<FeatureCoverage>(); ColumnDefinition coldef = features->attributeDefinitions().columndefinition(COVERAGEKEYCOLUMN); if ( coldef.isValid()){ valueType = coldef.datadef().domain()->valueType(); } } else if ( hasType( objectype , itDOMAIN)){ IDomain dom = _ilwisobject.as<Domain>(); valueType = dom->valueType(); } } QString typeName = TypeHelper::type2HumanReadable(valueType); return typeName == sUNDEF ? "" : typeName; }catch(const ErrorObject& ){ // no exceptions may escape here } return ""; }
void CrosssectionTool::changeCoords(int index, int c, int r, bool useScreenPixels) { if (index >= 0 && index < _pins.size()) { if (_panelCoverage->ilwisType() == itRASTER) { IRasterCoverage raster = _panelCoverage.as<RasterCoverage>(); if (raster.isValid()) { Coordinate crd; if (useScreenPixels) { crd = vpmodel()->layer()->layerManager()->rootLayer()->screenGrf()->pixel2Coord(Pixel(c, r)); Pixel pix = raster->georeference()->coord2Pixel(crd); c = pix.x; r = pix.y; } crd = raster->georeference()->pixel2Coord(Pixel(c, r)); _pins[index]->x(crd.x); _pins[index]->y(crd.y); _pins[index]->column(c); _pins[index]->row(r); _pins[index]->update(); vpmodel()->layer()->layerManager()->updatePostDrawers(); changePinData(index, crd); } } } }
IRasterCoverage operator*(const IRasterCoverage &raster1, const IRasterCoverage &raster2) { QString name = Identity::newAnonymousName();; QString stmt = QString("script %1=%2 * %3").arg(name).arg(raster1->name()).arg(raster2->name()); return doRasterOperation(stmt); }
void OperationWorker::process(){ try { Operation op(_expression); SymbolTable tbl; ExecutionContext ctx; if(op->execute(&ctx, tbl)){ if ( ctx._results.size() > 0){ for(auto resultName : ctx._results){ Symbol symbol = tbl.getSymbol(resultName); if ( hasType(symbol._type, itNUMBER)){ result += symbol._var.toDouble(); }else if ( hasType(symbol._type, itSTRING)){ result += symbol._var.toString(); }else if ( hasType(symbol._type, (itCOVERAGE | itTABLE))){ if ( symbol._type == itRASTER){ IRasterCoverage raster = symbol._var.value<IRasterCoverage>(); if ( raster.isValid()) result = raster->source().url().toString(); } } } } }else { qDebug() << "operation failed"; } emit finished(); }catch(const ErrorObject& err){ } emit finished(); }
DataDefinition IfOperation::findParameterDataDef(const OperationExpression &expr, int index) { const Parameter& parm = expr.parm(index); DataDefinition def; QString parmvalue = parm.value().toLower(); quint64 gcid = mastercatalog()->name2id(parmvalue, itRASTER); if ( gcid != i64UNDEF) { IRasterCoverage cov; if(cov.prepare(gcid)) { def = cov->datadef(); _coverages[index - 1] = cov.get<Coverage>(); } } else { bool ok; _number[index - 1] =parmvalue.toDouble(&ok); if ( ok){ def.domain().prepare("value"); } else { std::vector<QString> bools = {"true","false","yes","no","?"}; auto iter = std::find(bools.begin(), bools.end(), parmvalue.toLower()); if ( iter != bools.end()) { int v = 0; if ( parmvalue == "?" ) v= 2; else if ( parmvalue == "yes" || parmvalue == "true") v = 1; _number[index - 1] = v; IDomain dm; dm.prepare("boolean"); def.domain(dm); } } } return def; }
void domainCase(const IIlwisObject& obj, const QString& condition, int parmIndex, QVariantList& result) { if (hasType(obj->ilwisType(), itRASTER)) { IRasterCoverage raster = obj.as<RasterCoverage>(); QStringList parts = condition.split("="); QVariantMap mp; if ( parts.size() == 2){ if (parts[0] == "domain"){ QString domainType = parts[1]; if ( domainType == "numericdomain"){ mp["parameterIndex"] = parmIndex; mp["result"] = hasType(raster->datadef().domain()->ilwisType(), itNUMERICDOMAIN) ? obj->resource().url().toString() : ""; mp["uielement"] = "textfield"; }else if ( domainType == "itemdomain"){ mp["parameterIndex"] = parmIndex; mp["result"] = hasType(raster->datadef().domain()->ilwisType(), itITEMDOMAIN) ? obj->resource().url().toString() : ""; mp["uielement"] = "textfield"; } } else if ( parts[0] == "valuetype"){ QString valueType = parts[1]; IlwisTypes vt = IlwisObject::name2Type(valueType); mp["parameterIndex"] = parmIndex; mp["result"] = hasType(raster->datadef().domain()->valueType(), vt) ? obj->resource().url().toString() : ""; mp["uielement"] = "textfield"; } } result.append(mp); } }
void SelectionBase::ExpressionPart::setEnvelopePolygon(const IRasterCoverage& raster) { double deltax = _envelope.size().xsize() / 10.0; double deltay = _envelope.size().ysize() / 10.0; std::vector<geos::geom::Coordinate> *coords = new std::vector<geos::geom::Coordinate>(); double x,y = _envelope.min_corner().y; for(x = _envelope.min_corner().x; x < _envelope.max_corner().x; x+= deltax){ Pixel px = raster->georeference()->coord2Pixel(Coordinate(x,y)); coords->push_back(geos::geom::Coordinate(px.x, px.y,0)); } for(y = _envelope.min_corner().y; y < _envelope.max_corner().y; y+= deltay){ Pixel px = raster->georeference()->coord2Pixel(Coordinate(x,y)); coords->push_back(geos::geom::Coordinate(px.x, px.y,0)); } for(x = _envelope.max_corner().x; x > _envelope.min_corner().x; x-= deltax){ Pixel px = raster->georeference()->coord2Pixel(Coordinate(x,y)); coords->push_back(geos::geom::Coordinate(px.x, px.y,0)); } for(y = _envelope.max_corner().y; y > _envelope.min_corner().y; y-= deltay){ Pixel px = raster->georeference()->coord2Pixel(Coordinate(x,y)); coords->push_back(geos::geom::Coordinate(px.x, px.y,0)); } Pixel px = raster->georeference()->coord2Pixel(Coordinate(_envelope.min_corner().x,_envelope.min_corner().y)); coords->push_back(geos::geom::Coordinate(px.x, px.y,0)); geos::geom::CoordinateArraySequence *points = new geos::geom::CoordinateArraySequence(coords); geos::geom::LinearRing *ring = _geomfactory->createLinearRing(points); _polygon.reset( _geomfactory->createPolygon(ring, 0)); }
DataDefinition IfOperation::findParameterDataDef(const OperationExpression &expr, int index) { const Parameter& parm = expr.parm(index); DataDefinition def; QString parmvalue = parm.value(); IlwisTypes ptype = parm.valuetype(); if (hasType(ptype,itRASTER)) { IRasterCoverage cov; if (cov.prepare(parmvalue)) { def = cov->datadef(); _coverages[index - 1] = cov.as<Coverage>(); } } else { bool ok; _number[index - 1] = parmvalue.toDouble(&ok); if ( ok){ IDomain dom("code=domain:value"); def.domain(dom); } else { std::vector<QString> bools = {"true","false","yes","no","?"}; auto iter = std::find(bools.begin(), bools.end(), parmvalue.toLower()); if ( iter != bools.end()) { int v = 0; if ( parmvalue == "?" ) v= 2; else if ( parmvalue == "yes" || parmvalue == "true") v = 1; _number[index - 1] = v; IDomain dm; dm.prepare("boolean"); def.domain(dm); } } } return def; }
Ilwis::OperationImplementation::State CreateSimpelRasterCoverage::prepare(ExecutionContext *ctx,const SymbolTable&){ IRasterCoverage inputRaster; if ( _expression.parm(0).valuetype() == itRASTER){ if(!inputRaster.prepare(_expression.input<QString>(0))){ kernel()->issues()->log(TR("Invalid raster used to create new raster:") + _expression.input<QString>(0)); return sPREPAREFAILED; } _outputRaster = OperationHelperRaster::initialize(inputRaster,itRASTER,itRASTERSIZE|itDOMAIN|itCOORDSYSTEM|itGEOREF); return sPREPARED; } QString grf = _expression.input<QString>(0); if ( ! _grf.prepare(grf)){ kernel()->issues()->log(QString(TR("%1 is and invalid georeference")).arg(grf)); return sPREPAREFAILED; } _empty = _expression.input<bool>(1); _domain.prepare("code=domain:value"); _stackDomain = IDomain("count"); if (!_empty){ _stackValueStrings = {"1"}; _stackValueNumbers = {1}; } _outputRaster.prepare(); _outputRaster->georeference(_grf); _outputRaster->setDataDefintions(_domain, _stackValueNumbers , _stackDomain); return sPREPARED; }
IRasterCoverage operator*(const IRasterCoverage &raster1, const IRasterCoverage &raster2) { QString name = ANONYMOUS_PREFIX; QString stmt = QString("script %1=%2 * %3").arg(name).arg(raster1->name()).arg(raster2->name()); return doRasterOperation(stmt); }
bool runApplication( OperationExpression opExpr, QString *result){ Operation op(opExpr); SymbolTable tbl; ExecutionContext ctx; if(op->execute(&ctx, tbl)){ if ( ctx._results.size() > 0){ for(auto resultName : ctx._results){ Symbol symbol = tbl.getSymbol(resultName); if ( hasType(symbol._type, itNUMBER)){ *result += symbol._var.toDouble(); }else if ( hasType(symbol._type, itSTRING)){ *result += symbol._var.toString(); }else if ( hasType(symbol._type, (itCOVERAGE | itTABLE))){ if ( symbol._type == itRASTER){ IRasterCoverage raster = symbol._var.value<IRasterCoverage>(); QUrl url = raster->source().container(); } } } } return true; } return false; }
void GridBlockInternal::fetchFromSource() { IIlwisObject obj = mastercatalog()->get(_rasterid); if ( obj.isValid()){ IRasterCoverage raster = obj.as<RasterCoverage>(); raster->getData(_id); } }
geos::geom::Point *SelectionBase::pixel2point(const Pixel& pix){ IRasterCoverage raster = _inputObj.as<RasterCoverage>(); if ( raster.isValid()) { Coordinate crd = raster->georeference()->pixel2Coord(pix); return _geomfactory->createPoint(crd); } return 0; }
int CrosssectionTool::maxC() const { if (_panelCoverage.isValid() && _panelCoverage->ilwisType() == itRASTER) { IRasterCoverage raster = _panelCoverage.as<RasterCoverage>(); if (raster.isValid()) { return raster->georeference()->size().xsize(); } } return 0; }
DataDefinition MapCalc::datadef(int index) { auto iterP = _inputRasters.find(index); if ( iterP != _inputRasters.end()){ IRasterCoverage raster = _inputRasters[index].raster(); return raster->datadef(); } return DataDefinition(); }
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; }
QVariantMap MouseGotoPixelEditor::screenPixel(int column, int row) const { QVariantMap mp; IRasterCoverage raster = static_cast<CoverageLayerModel *>(vpmodel()->layer())->coverage().as<RasterCoverage>(); if (raster.isValid()) { auto crd = raster->georeference()->pixel2Coord(Pixel(column, row)); auto pix = vpmodel()->layer()->layerManager()->rootLayer()->screenGrf()->coord2Pixel(crd); mp["x"] = pix.x; mp["y"] = pix.y; } return mp; }
bool RasterLayerDrawer::prepare(DrawerInterface::PreparationType prepType, const IOOptions &options) { if(!LayerDrawer::prepare(prepType, options)) return false; IRasterCoverage raster = coverage().as<RasterCoverage>(); if ( !_rasterImage){ setActiveVisualAttribute(PIXELVALUE); _visualAttribute = visualProperty(activeAttribute()); _rasterImage.reset(RasterImageFactory::create(raster->datadef().domain()->ilwisType(), rootDrawer(),raster,_visualAttribute,IOOptions())); if (!_rasterImage){ ERROR2(ERR_NO_INITIALIZED_2,"RasterImage",raster->name()); return false; } } if ( hasType(prepType, ptSHADERS) && !isPrepared(ptSHADERS)){ _texcoordid = _shaders.attributeLocation("texCoord"); _textureid = _shaders.uniformLocation( "tex" ); _prepared |= DrawerInterface::ptSHADERS; } if ( hasType(prepType, DrawerInterface::ptGEOMETRY) && !isPrepared(DrawerInterface::ptGEOMETRY)){ Envelope env = rootDrawer()->coordinateSystem()->convertEnvelope(raster->coordinateSystem(), raster->envelope()); _vertices.resize(6); _vertices[0] = QVector3D(env.min_corner().x, env.min_corner().y, 0); _vertices[1] = QVector3D(env.max_corner().x, env.min_corner().y, 0); _vertices[2] = QVector3D(env.min_corner().x, env.max_corner().y, 0); _vertices[3] = QVector3D(env.max_corner().x, env.min_corner().y, 0); _vertices[4] = QVector3D(env.max_corner().x, env.max_corner().y, 0); _vertices[5] = QVector3D(env.min_corner().x, env.max_corner().y, 0); _texcoords.resize(6); _texcoords = {{0,1},{1,1},{0,0}, {1,1},{1,0},{0,0} }; _prepared |= ( DrawerInterface::ptGEOMETRY); } if ( hasType(prepType, DrawerInterface::ptRENDER) && !isPrepared(DrawerInterface::ptRENDER)){ setActiveVisualAttribute(PIXELVALUE); _visualAttribute = visualProperty(activeAttribute()); _rasterImage->visualAttribute(_visualAttribute); _prepared |= ( DrawerInterface::ptRENDER); } if (_rasterImage->prepare((int)prepType)){ _texture.reset( new QOpenGLTexture(*(_rasterImage->image().get()))); _texture->setMinMagFilters(QOpenGLTexture::Nearest,QOpenGLTexture::Nearest); } return true; }
bool PinDataSource::setStackDomain(const QString& id) { IRasterCoverage raster; raster.prepare(_objid); bool ok; _actives.clear(); quint64 oid = id.toULongLong(&ok); if (!ok) { kernel()->issues()->log(TR("No valid object id used: ") + id); return false; } RasterStackDefinition& stack = raster->stackDefinitionRef(); IDomain dom; if (dom.prepare(oid) && dom->ilwisType() == itITEMDOMAIN) { _stackDomain = dom; IItemDomain itemdom = dom.as< ItemDomain<DomainItem>>(); if (itemdom->count() == raster->size().zsize()) { std::vector<QString> items; for (auto item : itemdom) { items.push_back(item->name()); } stack.setSubDefinition(itemdom, items); } else { kernel()->issues()->log(TR("Item domain must have same size as tjhe number of bands in the container")); return false; } } for (quint32 i = 0; i < stack.count(); ++i) { QString name = QString::number(i + 1); // stack.index(i+1); QVariantMap data; data["name"] = name; data["active"] = true; if (_stackDomain->valueType() != itNUMERICITEM) { data["minvalue"] = "?"; data["maxvalue"] = "?"; } else { IIntervalDomain idomain = _stackDomain.as<IntervalDomain>(); if (idomain->count() == stack.count()) { auto item = idomain->item(i)->as<Interval>(); data["name"] = item->name(); auto range = item->range().as<NumericRange>(); data["minvalue"] = QString::number(range->min()); data["maxvalue"] = QString::number(range->max()); } } _actives.push_back(data); } return true; }
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 ""; }
Ilwis::OperationImplementation::State PercentileFilterStretch::prepare(ExecutionContext *, const SymbolTable & ) { QString raster = _expression.parm(0).value(); QString outputName = _expression.parm(0,false).value(); // open the input map list if (!_inputObj.prepare(raster, itRASTER)) { ERROR2(ERR_COULD_NOT_LOAD_2, raster, ""); return sPREPAREFAILED; } // Open the zonal map QString zones = _expression.parm(1).value(); if (!_inputZones.prepare(zones, itRASTER)) { ERROR2(ERR_COULD_NOT_LOAD_2, zones, ""); return sPREPAREFAILED; } // Open both percentile tables QString lowPerc = _expression.parm(2).value(); if (!_lowPercentile.prepare(lowPerc, {"mustexist", true})){ ERROR2(ERR_COULD_NOT_LOAD_2, lowPerc, ""); return sPREPAREFAILED; } QString highPerc = _expression.parm(3).value(); if (!_highPercentile.prepare(highPerc, {"mustexist", true})){ ERROR2(ERR_COULD_NOT_LOAD_2, highPerc, ""); return sPREPAREFAILED; } QString startDate = _expression.parm(4).value(); Time date(startDate); _startDekad = dekadFromDate(date); if (!date.isValid()) { ERROR1(TR("Invalid date: "), startDate); return sPREPAREFAILED; } _outputObj = OperationHelperRaster::initialize(_inputObj, itRASTER, itDOMAIN | itGEOREF | itCOORDSYSTEM | itRASTERSIZE | itBOUNDINGBOX | itENVELOPE); if ( !_outputObj.isValid()) { ERROR1(ERR_NO_INITIALIZED_1, "output rastercoverage"); return sPREPAREFAILED; } IRasterCoverage inputRaster = _inputObj.as<RasterCoverage>(); // initialize tranquilizer initialize(inputRaster->size().xsize() * inputRaster->size().ysize()); return sPREPARED; }
bool OperationHelperRaster::resample(IRasterCoverage& raster1, IRasterCoverage& raster2, ExecutionContext *ctx) { if ( !raster1.isValid()) return false; IGeoReference commonGeoref = raster1->georeference(); if ( ctx->_masterGeoref != sUNDEF) { if(!commonGeoref.prepare(ctx->_masterGeoref)) return false; } if (raster1->georeference()!= commonGeoref ){ Resource res; res.prepare(); QString expr = QString("%3=resample(%1,%2,bicubic)").arg(raster1->source().url().toString()).arg(commonGeoref->source().url().toString()).arg(res.name()); ExecutionContext ctxLocal; SymbolTable symtabLocal; if(!commandhandler()->execute(expr,&ctxLocal,symtabLocal)) return false; QVariant var = symtabLocal.getValue(res.name()); raster1 = var.value<IRasterCoverage>(); } if ( raster2.isValid() && raster2->georeference()!= commonGeoref ){ Resource res; res.prepare(); QString expr = QString("%3=resample(%1,%2,bicubic)").arg(raster2->source().url().toString()).arg(commonGeoref->source().url().toString()).arg(res.name()); ExecutionContext ctxLocal; SymbolTable symtabLocal; if(!commandhandler()->execute(expr,&ctxLocal,symtabLocal)) return false; QVariant var = symtabLocal.getValue(res.name()); IRasterCoverage outRaster = var.value<IRasterCoverage>(); raster2.assign(outRaster); } return true; }
IRasterCoverage OperationHelperRaster::resample(const IRasterCoverage& sourceRaster, const IGeoReference& targetGrf) { if (!sourceRaster.isValid() || !targetGrf.isValid()) return IRasterCoverage(); Resource res; res.prepare(); QString expr = QString("%3=resample(%1,%2,nearestneighbour)").arg(sourceRaster->resource().url().toString()).arg(targetGrf->resource().url().toString()).arg(res.name()); ExecutionContext ctxLocal; SymbolTable symtabLocal; if (!commandhandler()->execute(expr, &ctxLocal, symtabLocal)) return false; QVariant var = symtabLocal.getValue(res.name()); return var.value<IRasterCoverage>(); }
template<typename T> void storeBulk(const RawConverter& converter, QDataStream& stream, StreamConnector *streamconnector, const BoundingBox& box, const IRasterCoverage& raster){ quint64 count = streamconnector->position(); if ( streamconnector->isFileBased()){ const UPGrid& grid = raster->grid(); quint32 blockCount = grid->blocks(); stream << blockCount; for(quint32 i = 0; i < blockCount; ++i){ const char * data = grid->blockAsMemory(i, false); quint64 blockSize = 8 * grid->blockSize(i); stream << i; stream << blockSize; stream.writeRawData(data, blockSize); } streamconnector->flush(true); }else { PixelIterator iter(raster, box); while(iter != iter.end()){ if ( count >= STREAMBLOCKSIZE - 9 ) { streamconnector->flush(false); count = 0; } count += sizeof(T); stream << (T)converter.real2raw(*iter); ++iter; } } }
IRasterCoverage operator<(const IRasterCoverage &raster1, double v) { QString name = Identity::newAnonymousName(); QString stmt = QString("script %1=%2 < %3").arg(name).arg(raster1->name()).arg(v); return doRasterOperation(stmt); }
void IlwisObjectModel::setAttribute(const QString &attrname, const QString &value, const QString &extra) { if ( _ilwisobject.isValid()){ if ( attrname == "domain"){ IDomain dom(value); if ( _ilwisobject->ilwisType() == itRASTER){ IRasterCoverage raster = _ilwisobject.as<RasterCoverage>(); if ( dom->id() != raster->datadefRef().domain()->id()){ raster->datadefRef().domain(dom); raster->changed(true); mastercatalog()->changeResource(raster->id(),"domain",dom->id(), true); } } } } }
void RasterLayerDrawer::setActiveVisualAttribute(const QString &attr) { IRasterCoverage raster = coverage().as<RasterCoverage>(); if ( attr == PIXELVALUE){ LayerDrawer::setActiveVisualAttribute(attr); } else if ( raster.isValid() ) { if(raster->hasAttributes()) { if ( raster->attributeTable()->columnIndex(attr) != iUNDEF){ IRepresentation newrpr = Representation::defaultRepresentation(raster->attributeTable()->columndefinition(attr).datadef().domain()); if ( newrpr.isValid()){ LayerDrawer::setActiveVisualAttribute(attr); } } } } }
void CrosssectionTool::changePixel(int index, double x, double y) { if (index >= 0 && index < _pins.size()) { if (_panelCoverage->ilwisType() == itRASTER) { IRasterCoverage raster = _panelCoverage.as<RasterCoverage>(); if (raster.isValid()) { Pixel pix = raster->georeference()->coord2Pixel(Coordinate(x, y)); _pins[index]->x(x) ; _pins[index]->y(y); _pins[index]->column(pix.x); _pins[index]->row(pix.y); _pins[index]->update(); vpmodel()->layer()->layerManager()->updatePostDrawers(); changePinData(index, Coordinate(x,y)); } } } }