Skip to content

Commit

Permalink
Write operation for raster providers
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Jul 11, 2012
1 parent c985736 commit 3ba646f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/core/qgsrasterdataprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,18 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast
/** Current time stamp of data source */
virtual QDateTime dataTimestamp() const { return QDateTime(); }

/**Writes into the provider datasource*/
virtual bool write( void* data, int band, int width, int height, int xOffset, int yOffset )
{
Q_UNUSED( data );
Q_UNUSED( band );
Q_UNUSED( width );
Q_UNUSED( height );
Q_UNUSED( xOffset );
Q_UNUSED( yOffset );
return false;
}

/** Creates a new dataset with mDataSourceURI
@return true in case of success*/
virtual bool create( const QString& format, int nBands,
Expand Down
10 changes: 10 additions & 0 deletions src/providers/gdal/qgsgdalprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2089,6 +2089,16 @@ bool QgsGdalProvider::create( const QString& format, int nBands, QgsRasterDataPr
return mValid;
}

bool QgsGdalProvider::write( void* data, int band, int width, int height, int xOffset, int yOffset )
{
GDALRasterBandH rasterBand = GDALGetRasterBand( mGdalDataset, band );
if ( rasterBand == NULL )
{
return false;
}
return ( GDALRasterIO( rasterBand, GF_Write, xOffset, yOffset, width, height, data, width, height, GDALGetRasterDataType( rasterBand ), 0, 0 ) == CE_None );
}

QStringList QgsGdalProvider::createFormats() const
{
return QStringList();
Expand Down
3 changes: 3 additions & 0 deletions src/providers/gdal/qgsgdalprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ class QgsGdalProvider : public QgsRasterDataProvider
bool create( const QString& format, int nBands, QgsRasterDataProvider::DataType type, int width, int height,
double* geoTransform, const QgsCoordinateReferenceSystem& crs );

/**Writes into the provider datasource*/
bool write( void* data, int band, int width, int height, int xOffset, int yOffset );

/**Returns the formats supported by create()*/
QStringList createFormats() const;

Expand Down

0 comments on commit 3ba646f

Please sign in to comment.