Skip to content

Commit 3ba646f

Browse files
committed
Write operation for raster providers
1 parent c985736 commit 3ba646f

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

src/core/qgsrasterdataprovider.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,18 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast
435435
/** Current time stamp of data source */
436436
virtual QDateTime dataTimestamp() const { return QDateTime(); }
437437

438+
/**Writes into the provider datasource*/
439+
virtual bool write( void* data, int band, int width, int height, int xOffset, int yOffset )
440+
{
441+
Q_UNUSED( data );
442+
Q_UNUSED( band );
443+
Q_UNUSED( width );
444+
Q_UNUSED( height );
445+
Q_UNUSED( xOffset );
446+
Q_UNUSED( yOffset );
447+
return false;
448+
}
449+
438450
/** Creates a new dataset with mDataSourceURI
439451
@return true in case of success*/
440452
virtual bool create( const QString& format, int nBands,

src/providers/gdal/qgsgdalprovider.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2089,6 +2089,16 @@ bool QgsGdalProvider::create( const QString& format, int nBands, QgsRasterDataPr
20892089
return mValid;
20902090
}
20912091

2092+
bool QgsGdalProvider::write( void* data, int band, int width, int height, int xOffset, int yOffset )
2093+
{
2094+
GDALRasterBandH rasterBand = GDALGetRasterBand( mGdalDataset, band );
2095+
if ( rasterBand == NULL )
2096+
{
2097+
return false;
2098+
}
2099+
return ( GDALRasterIO( rasterBand, GF_Write, xOffset, yOffset, width, height, data, width, height, GDALGetRasterDataType( rasterBand ), 0, 0 ) == CE_None );
2100+
}
2101+
20922102
QStringList QgsGdalProvider::createFormats() const
20932103
{
20942104
return QStringList();

src/providers/gdal/qgsgdalprovider.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ class QgsGdalProvider : public QgsRasterDataProvider
269269
bool create( const QString& format, int nBands, QgsRasterDataProvider::DataType type, int width, int height,
270270
double* geoTransform, const QgsCoordinateReferenceSystem& crs );
271271

272+
/**Writes into the provider datasource*/
273+
bool write( void* data, int band, int width, int height, int xOffset, int yOffset );
274+
272275
/**Returns the formats supported by create()*/
273276
QStringList createFormats() const;
274277

0 commit comments

Comments
 (0)