bool MirrorRotateRaster::dimChanged(const PixelIterator& iter) const{
    switch(_method)    {
    case tmMirrorVertical:
        return iter.ychanged();
    case tmMirrorHorizontal:
        return iter.xchanged();
    case tmRotate90:
        return iter.xchanged();
    case tmRotate270:
        return iter.xchanged();
    default:
        break;
    }
    return false;
}
Exemple #2
0
bool BoxClassifier::classify(PixelIterator &iterIn, PixelIterator &iterOut) const
{
    Raw currentClass, raw;
    PixelIterator iterEnd = iterOut.end();
    std::vector<double> zcolumn(sampleset().sampleRasterSet()->size().zsize(), rUNDEF);
    while( iterOut != iterEnd)    {
        for(auto item : sampleset().thematicDomain() ){
            raw = iUNDEF;
            currentClass = _classSequence.at(item->raw());
            bool classFound = true;

            for(double& v : zcolumn){
                v = *iterIn;
                ++iterIn;
            }
            for(int band = 0; band < zcolumn.size(); ++band){
                classFound = classFound &&
                        (zcolumn[band] < _boxMax.at((quint32)currentClass).at(band) &&
                         zcolumn[band] > _boxMin.at((quint32)currentClass).at(band));
                if (!classFound)
                    break;
            }
            if ( classFound)  {
                raw = currentClass;
                break;
            }
        }
        *iterOut = raw;
        ++iterOut;
    }
    return true;
}
void MirrorRotateRaster::translatepixels(PixelIterator iterIn,PixelIterator iterOut, const BoundingBox& box, quint32 linelength ){
    std::vector<double> line(linelength);
    auto iterLine = line.begin();
    auto end = iterIn.end();
    double v = *iterIn;
    for(; iterIn != end; ++iterIn, ++iterLine){
        if ( dimChanged(iterIn)){
            std::reverse(line.begin(), line.end());
            std::copy(line.begin(), line.end(),iterOut);
            iterLine = line.begin();
            iterOut += iterIn.box().xlength();
        }
        (*iterLine) = *iterIn;
    }
    // lastline
    std::reverse(line.begin(), line.end());
    std::copy(line.begin(), line.end(),iterOut);
}
void FadingDecoration::update()
{
  assert(step_count < steps);
  
  if (delay_count < delay)
    ++delay_count;
  else {
    delay_count = 0;

    ++step_count;

    Glib::RefPtr<Gdk::Pixbuf> p = graphic->get_pixbuf();
    
    for (PixelIterator d = begin(p), s = begin(original), e = end(p);
	 d != e; ++d, ++s)
      d->alpha() = int(s->alpha()) * (steps - step_count) / steps;
    
    graphic->set_pixbuf(p);
  }
}
bool RasterCoverageConnector::saveByteBand(RasterCoverage *raster, GDALDatasetH dataset,int gdallayerindex, int band, GDALColorInterp colorType){
    quint32 columns = raster->size().xsize();
    PixelIterator iter = raster->band(band);
    std::vector<unsigned char> data(columns);
    GDALRasterBandH hband = gdal()->getRasterBand(dataset,gdallayerindex);
    if (!hband) {
        return ERROR1(ERR_NO_INITIALIZED_1,"raster band");
    }
    if ( gdal()->setColorInterpretation(hband,colorType) != CE_None) // not supported by this format
        return ERROR2(ERR_OPERATION_NOTSUPPORTED2,"Color"," this format");
    auto endPosition =  iter.end();
    while(iter != endPosition) {
        for_each(data.begin(), data.end(), [&](unsigned char& v){
           quint32 component = (quint32)*iter;
            switch(colorType){
            case GCI_RedBand:
                v = (0x00FF0000 & component) >> 16;break;
            case GCI_GreenBand:
                v =(0x0000FF00 & component) >> 8;break;
            case GCI_BlueBand:
                v = 0x00000000FF & component;break;
            default:
                break;
            }
            ++iter;
        });

        double y = iter.zchanged() ? iter.box().ylength()  : iter.position().y;

        if(iter == endPosition){
            y = iter.box().ylength();
        }

        gdal()->rasterIO(hband, GF_Write, 0, y - 1, columns, 1, (void *)&data[0],columns,1, GDT_Byte,0,0 );

    }
Exemple #6
0
bool SelectionRaster::execute(ExecutionContext *ctx, SymbolTable& symTable)
{
    if (_prepState == sNOTPREPARED)
        if((_prepState = prepare(ctx, symTable)) != sPREPARED)
            return false;
    IRasterCoverage outputRaster = _outputObj.as<RasterCoverage>();
    IRasterCoverage inputRaster = _inputObj.as<RasterCoverage>();

    std::map<Raw, quint32> raw2record;
    int keyColumn = _inputAttributeTable.isValid() ? _inputAttributeTable->columnIndex(inputRaster->primaryKey()) : iUNDEF;
    if (keyColumn != iUNDEF){
        std::vector<QVariant> values = _inputAttributeTable->column(keyColumn);
        for(quint32 rec=0; rec < values.size(); ++rec){
            Raw r = values[rec].toDouble();
            if ( !isNumericalUndef(r)){
                raw2record[r] = rec;
            }
        }
    }

    std::vector<int> extraAtrrib = organizeAttributes();


    std::vector<QString> selectionBands = bands(inputRaster);
    initialize(outputRaster->size().linearSize() * selectionBands.size());

    PixelIterator iterOut(outputRaster);
    int count = 0;
    bool numeric = outputRaster->datadef().domain()->ilwisType() == itNUMERICDOMAIN;
    for(QString band : selectionBands){
        PixelIterator iterIn = inputRaster->band(band, _box);

        PixelIterator iterEnd = iterIn.end();
        while(iterIn != iterEnd) {
            bool ok = true;
            double pixValue = *iterIn;
            double matchValue = pixValue;

            for(const auto& epart : _expressionparts){
                bool partOk = epart.match(iterIn.position(), matchValue,this);
                if ( epart._andor != loNONE)
                    ok =  epart._andor == loAND ? ok && partOk : ok || partOk;
                else
                    ok &= partOk;
                if (epart._type == ExpressionPart::ptATTRIBUTE && extraAtrrib.size() == 1){
                    if ( pixValue < 0 || pixValue >= _inputAttributeTable->recordCount()){
                        ok = false;
                        continue;
                    }
                    // pixValue == ID; ID < zero means undef, ID's start at zero.
                    if (pixValue >= 0) {
                        if (keyColumn != iUNDEF){
                            auto iter = raw2record.find(pixValue);
                            if ( iter != raw2record.end()){
                                quint32 rec = iter->second;
                                const Record& record = _inputAttributeTable->record(rec);
                                pixValue = record.cell(extraAtrrib[0]).toDouble();
                            }else
                                pixValue = rUNDEF;
                        }

                    }
                    else
                        pixValue = rUNDEF;
                }
            }
            if ( ok){
                *iterOut = pixValue;
            }else
                *iterOut = rUNDEF;

            ++iterIn;
            ++iterOut;
            updateTranquilizer(++count, 100);
        }
        // if there is an attribute table we must copy the correct attributes and records
        if ( keyColumn != iUNDEF && _attTable.isValid()){
            for(int recIndex=0; recIndex < _inputAttributeTable->recordCount(); ++recIndex){
                const Record& rec = _inputAttributeTable->record(recIndex);
                for(int i=0; i < extraAtrrib.size(); ++i){
                    _attTable->setCell(i, recIndex, rec.cell(extraAtrrib[i]));
                }
            }
        }
    }
    if ( numeric)
        outputRaster->statistics(ContainerStatistics<double>::pBASIC);

    outputRaster->setAttributes(_attTable);
    QVariant value;
    value.setValue<IRasterCoverage>(outputRaster);
    logOperation(outputRaster, _expression);
    ctx->setOutput(symTable, value, outputRaster->name(), itRASTER,outputRaster->resource());
    return true;


}
bool RasterCoverage::bandPrivate(quint32 bandIndex,  PixelIterator inputIter)
{
    if ( inputIter.box().size().zsize() != 1)
        return false;
    bool isFirstLayer = !size().isValid() || size().isNull();
    if (!isFirstLayer)    { // if it is not the first layer, some rules for this raster have already been defined(2dsize + domain)
        if ( inputIter.box().xlength() != size().xsize() || inputIter.box().ylength() != size().ysize())
            return false;
        if (!inputIter.raster()->datadef().domain()->isCompatibleWith(datadef().domain().ptr()))
            return false;
    }


    if ( isFirstLayer ){ //  totally new band in new coverage, initialize everything

        coordinateSystem(inputIter.raster()->coordinateSystem());
        georeference(inputIter.raster()->georeference());
        datadefRef() = inputIter.raster()->datadef();
        envelope(inputIter.raster()->envelope());

        Size<> twodsz = inputIter.box().size().twod();
        size(Size<>(twodsz.xsize(), twodsz.ysize() ,stackDefinition().count()));
        _datadefBands.resize(stackDefinition().count());
    }
    datadefRef(bandIndex) = inputIter.raster()->datadef();
//    grid()->setBandProperties(this,bandIndex);

    PixelIterator iter = bandPrivate(bandIndex);
    while(iter != iter.end()){
        *iter = *inputIter;
        ++iter;
        ++inputIter;
    }
    return true;


}
int PixelIterator:: operator-(const PixelIterator& iter) {
    return linearPosition() - iter.linearPosition();
}
PixelIterator PixelIterator::end(){
    PixelIterator newIter = PixelIterator(*this);
    newIter._ilwisPixelIterator.reset(new Ilwis::PixelIterator(newIter.ptr().end()));
    return newIter;
}
bool PixelIterator::operator> (const PixelIterator &other){
    return this->ptr() > other.ptr();
}
PixelIterator::PixelIterator(const PixelIterator& pi): _coverage(pi._coverage), _ilwisPixelIterator(new Ilwis::PixelIterator(pi.ptr())), _endposition(pi._endposition){
}