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; }
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(); }
int OperationHelperRaster::subdivideTasks(ExecutionContext *ctx,const IRasterCoverage& raster, const BoundingBox &bnds, std::vector<BoundingBox > &boxes) { if ( !raster.isValid() || raster->size().isNull() || raster->size().ysize() == 0) { return ERROR1(ERR_NO_INITIALIZED_1, "Grid size"); return iUNDEF; } int cores = std::min(QThread::idealThreadCount(),(int)raster->size().ysize()); if (raster->size().linearSize() < 10000 || ctx->_threaded == false) cores = 1; boxes.clear(); boxes.resize(cores); BoundingBox bounds = bnds; if ( bounds.isNull()) bounds = BoundingBox(raster->size()); int left = 0; //bounds.min_corner().x; int right = bounds.size().xsize(); int top = bounds.size().ysize(); int step = bounds.size().ysize() / cores; int currentY = 0; for(int i=0 ; i < cores; ++i){ BoundingBox smallBox(Pixel(left, currentY,0), Pixel(right - 1, std::min(top - 1,currentY + step),bounds.zlength()) ); boxes[i] = smallBox; currentY = currentY + step ; } return cores; }
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); } } } }
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; }
PinDataSource::PinDataSource(quint64 objid, QObject *parent) : QObject(parent) { IRasterCoverage raster; raster.prepare(objid); if (!raster.isValid()) return; _objid = objid; _stackDomain = raster->stackDefinition().domain(); CrosssectionTool *tool = static_cast<CrosssectionTool *>(parent); IRasterCoverage rasterPanel = tool->coverage().as<RasterCoverage>(); if (!rasterPanel.isValid()) { throw ErrorObject(TR("Crossection tool only works for raster coverages")); } if (!raster->georeference()->isCompatible(rasterPanel->georeference())) { throw ErrorObject(TR("Rasters must have compatible georeferences")); } setStackDomain( QString::number(_stackDomain->id())); }
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; }
BoundingBox OperationHelperRaster::initialize(const IRasterCoverage &inputRaster, IRasterCoverage &outputRaster, quint64 what) { Resource resource(itRASTER); Size<> sz = inputRaster->size(); BoundingBox box(sz); if ( what & itRASTERSIZE) { resource.addProperty("size", IVARIANT(sz.toString())); } if ( what & itENVELOPE) { if ( box.isNull() || !box.isValid()) { sz = inputRaster->size(); box = BoundingBox(sz); } Envelope bounds = inputRaster->georeference()->pixel2Coord(box); resource.addProperty("envelope", IVARIANT(bounds.toString())); } if ( what & itCOORDSYSTEM) { resource.addProperty("coordinatesystem", IVARIANT(inputRaster->coordinateSystem()->id())); } if ( what & itGEOREF) { if ( box.isNull() || !box.isValid()) { sz = inputRaster->size(); box = BoundingBox(sz); } if ( sz.xsize() == box.xlength() && sz.ysize() == box.ylength()) resource.addProperty("georeference", IVARIANT(inputRaster->georeference()->id())); } if ( what & itDOMAIN) { resource.addProperty("domain", IVARIANT(inputRaster->datadef().domain<>()->id())); } resource.prepare(); outputRaster.prepare(resource); if ( what & itTABLE) { if ( inputRaster->attributeTable().isValid()) { if ( inputRaster->datadef().domain<>() == outputRaster->datadef().domain<>()) { if ( outputRaster.isValid()) outputRaster->setAttributes(inputRaster->attributeTable()); } } } if ( what & itDOMAIN){ for(quint32 i = 0; i < outputRaster->size().zsize(); ++i){ QString index = outputRaster->stackDefinition().index(i); outputRaster->setBandDefinition(index,DataDefinition(outputRaster->datadef().domain())); } } return box; }
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; }
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>(); }
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)); } } } }
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 RasterLayerDrawer::coverage(const ICoverage &cov) { LayerDrawer::coverage(cov); setActiveVisualAttribute(PIXELVALUE); IRasterCoverage raster = cov.as<RasterCoverage>(); if (!raster.isValid()) return; // fot the moment test only single band value maps with no attribute table; will extend when this works IlwisTypes attrType = raster->datadef().domain()->valueType(); VisualAttribute attr(raster->datadef().domain()); if ( hasType(attrType, itNUMBER)){ auto numrange = raster->datadef().range<NumericRange>(); attr.actualRange(NumericRange(numrange->min(), numrange->max(), numrange->resolution())); visualProperty(PIXELVALUE, attr); } else if ( hasType(attrType, itCONTINUOUSCOLOR)){ visualProperty(PIXELVALUE, attr); }else if ( hasType(attrType, itPALETTECOLOR)){ auto colorrange = raster->datadef().range<ColorPalette>(); } }