QgsRasterFileWriter::WriterError QgsRasterFileWriter::writeRaster( const QgsRasterPipe *pipe, int nCols, int nRows, const QgsRectangle &outputExtent, const QgsCoordinateReferenceSystem &crs, QgsRasterBlockFeedback *feedback ) { QgsDebugMsgLevel( "Entered", 4 ); if ( !pipe ) { return SourceProviderError; } mPipe = pipe; //const QgsRasterInterface* iface = iter->input(); const QgsRasterInterface *iface = pipe->last(); if ( !iface ) { return SourceProviderError; } mInput = iface; if ( QgsRasterBlock::typeIsColor( iface->dataType( 1 ) ) ) { mMode = Image; } else { mMode = Raw; } QgsDebugMsgLevel( QString( "reading from %1" ).arg( typeid( *iface ).name() ), 4 ); if ( !iface->sourceInput() ) { QgsDebugMsg( "iface->srcInput() == 0" ); return SourceProviderError; } #ifdef QGISDEBUG const QgsRasterInterface &srcInput = *iface->sourceInput(); QgsDebugMsgLevel( QString( "srcInput = %1" ).arg( typeid( srcInput ).name() ), 4 ); #endif mFeedback = feedback; QgsRasterIterator iter( pipe->last() ); //create directory for output files if ( mTiledMode ) { QFileInfo fileInfo( mOutputUrl ); if ( !fileInfo.exists() ) { QDir dir = fileInfo.dir(); if ( !dir.mkdir( fileInfo.fileName() ) ) { QgsDebugMsg( "Cannot create output VRT directory " + fileInfo.fileName() + " in " + dir.absolutePath() ); return CreateDatasourceError; } } } // Remove pre-existing overview files to avoid using those with new raster QFile pyramidFile( mOutputUrl + ( mTiledMode ? ".vrt.ovr" : ".ovr" ) ); if ( pyramidFile.exists() ) pyramidFile.remove(); pyramidFile.setFileName( mOutputUrl + ( mTiledMode ? ".vrt.rrd" : ".rrd" ) ); if ( pyramidFile.exists() ) pyramidFile.remove(); if ( mMode == Image ) { WriterError e = writeImageRaster( &iter, nCols, nRows, outputExtent, crs, feedback ); return e; } else { WriterError e = writeDataRaster( pipe, &iter, nCols, nRows, outputExtent, crs, feedback ); return e; } }
QgsRasterFileWriter::WriterError QgsRasterFileWriter::writeRaster( const QgsRasterPipe* pipe, int nCols, int nRows, QgsRectangle outputExtent, const QgsCoordinateReferenceSystem& crs, QProgressDialog* progressDialog ) { QgsDebugMsgLevel( "Entered", 4 ); if ( !pipe ) { return SourceProviderError; } mPipe = pipe; //const QgsRasterInterface* iface = iter->input(); const QgsRasterInterface* iface = pipe->last(); if ( !iface ) { return SourceProviderError; } mInput = iface; if ( QgsRasterBlock::typeIsColor( iface->dataType( 1 ) ) ) { mMode = Image; } else { mMode = Raw; } QgsDebugMsgLevel( QString( "reading from %1" ).arg( typeid( *iface ).name() ), 4 ); if ( !iface->srcInput() ) { QgsDebugMsg( "iface->srcInput() == 0" ); return SourceProviderError; } #ifdef QGISDEBUG const QgsRasterInterface &srcInput = *iface->srcInput(); QgsDebugMsgLevel( QString( "srcInput = %1" ).arg( typeid( srcInput ).name() ), 4 ); #endif mProgressDialog = progressDialog; QgsRasterIterator iter( pipe->last() ); //create directory for output files if ( mTiledMode ) { QFileInfo fileInfo( mOutputUrl ); if ( !fileInfo.exists() ) { QDir dir = fileInfo.dir(); if ( !dir.mkdir( fileInfo.fileName() ) ) { QgsDebugMsg( "Cannot create output VRT directory " + fileInfo.fileName() + " in " + dir.absolutePath() ); return CreateDatasourceError; } } } if ( mMode == Image ) { WriterError e = writeImageRaster( &iter, nCols, nRows, outputExtent, crs, progressDialog ); mProgressDialog = nullptr; return e; } else { mProgressDialog = nullptr; WriterError e = writeDataRaster( pipe, &iter, nCols, nRows, outputExtent, crs, progressDialog ); return e; } }