16
16
***************************************************************************/
17
17
18
18
// GDAL includes
19
- #include " gdal_priv.h "
20
- #include " cpl_string.h"
21
- #include " cpl_conv.h"
19
+ #include < gdal.h >
20
+ #include < cpl_string.h>
21
+ #include < cpl_conv.h>
22
22
23
23
// QGIS Specific includes
24
24
#include < qgisinterface.h>
@@ -142,25 +142,21 @@ void Heatmap::run()
142
142
// Getting the rasterdataset in place
143
143
GDALAllRegister ();
144
144
145
- GDALDataset *emptyDataset;
146
- GDALDriver *myDriver;
147
-
148
- myDriver = GetGDALDriverManager ()->GetDriverByName ( d.outputFormat ().toUtf8 () );
145
+ GDALDriverH myDriver = GDALGetDriverByName ( d.outputFormat ().toUtf8 () );
149
146
if ( !myDriver )
150
147
{
151
148
mQGisIface ->messageBar ()->pushMessage ( tr ( " GDAL driver error" ), tr ( " Cannot open the driver for the specified format" ), QgsMessageBar::WARNING, mQGisIface ->messageTimeout () );
152
149
return ;
153
150
}
154
151
155
152
double geoTransform[6 ] = { myBBox.xMinimum (), cellsize, 0 , myBBox.yMinimum (), 0 , cellsize };
156
- emptyDataset = myDriver-> Create ( d.outputFilename ().toUtf8 (), columns, rows, 1 , GDT_Float32, nullptr );
157
- emptyDataset-> SetGeoTransform ( geoTransform );
153
+ GDALDatasetH emptyDataset = GDALCreate ( myDriver, d.outputFilename ().toUtf8 (), columns, rows, 1 , GDT_Float32, nullptr );
154
+ GDALSetGeoTransform ( emptyDataset, geoTransform );
158
155
// Set the projection on the raster destination to match the input layer
159
- emptyDataset-> SetProjection ( inputLayer->crs ().toWkt ().toLocal8Bit ().data () );
156
+ GDALSetProjection ( emptyDataset, inputLayer->crs ().toWkt ().toLocal8Bit ().data () );
160
157
161
- GDALRasterBand *poBand;
162
- poBand = emptyDataset->GetRasterBand ( 1 );
163
- poBand->SetNoDataValue ( NO_DATA );
158
+ GDALRasterBandH poBand = GDALGetRasterBand ( emptyDataset, 1 );
159
+ GDALSetRasterNoDataValue ( poBand, NO_DATA );
164
160
165
161
float * line = ( float * ) CPLMalloc ( sizeof ( float ) * columns );
166
162
for ( int i = 0 ; i < columns ; i++ )
@@ -170,25 +166,24 @@ void Heatmap::run()
170
166
// Write the empty raster
171
167
for ( int i = 0 ; i < rows ; i++ )
172
168
{
173
- if ( poBand-> RasterIO ( GF_Write, 0 , i, columns, 1 , line, columns, 1 , GDT_Float32, 0 , 0 ) != CE_None )
169
+ if ( GDALRasterIO ( poBand, GF_Write, 0 , i, columns, 1 , line, columns, 1 , GDT_Float32, 0 , 0 ) != CE_None )
174
170
{
175
171
QgsDebugMsg ( " Raster IO Error" );
176
172
}
177
173
}
178
174
179
175
CPLFree ( line );
180
176
// close the dataset
181
- GDALClose (( GDALDatasetH ) emptyDataset );
177
+ GDALClose ( emptyDataset );
182
178
183
179
// open the raster in GA_Update mode
184
- GDALDataset *heatmapDS;
185
- heatmapDS = ( GDALDataset * ) GDALOpen ( TO8F ( d.outputFilename () ), GA_Update );
180
+ GDALDatasetH heatmapDS = GDALOpen ( TO8F ( d.outputFilename () ), GA_Update );
186
181
if ( !heatmapDS )
187
182
{
188
183
mQGisIface ->messageBar ()->pushMessage ( tr ( " Raster update error" ), tr ( " Could not open the created raster for updating. The heatmap was not generated." ), QgsMessageBar::WARNING );
189
184
return ;
190
185
}
191
- poBand = heatmapDS-> GetRasterBand ( 1 );
186
+ poBand = GDALGetRasterBand ( heatmapDS, 1 );
192
187
193
188
QgsAttributeList myAttrList;
194
189
int rField = 0 ;
@@ -302,8 +297,8 @@ void Heatmap::run()
302
297
303
298
// get the data
304
299
float *dataBuffer = ( float * ) CPLMalloc ( sizeof ( float ) * blockSize * blockSize );
305
- if ( poBand-> RasterIO ( GF_Read, xPosition, yPosition, blockSize, blockSize,
306
- dataBuffer, blockSize, blockSize, GDT_Float32, 0 , 0 ) != CE_None )
300
+ if ( GDALRasterIO ( poBand, GF_Read, xPosition, yPosition, blockSize, blockSize,
301
+ dataBuffer, blockSize, blockSize, GDT_Float32, 0 , 0 ) != CE_None )
307
302
{
308
303
QgsDebugMsg ( " Raster IO Error" );
309
304
}
@@ -347,8 +342,8 @@ void Heatmap::run()
347
342
}
348
343
}
349
344
}
350
- if ( poBand-> RasterIO ( GF_Write, xPosition, yPosition, blockSize, blockSize,
351
- dataBuffer, blockSize, blockSize, GDT_Float32, 0 , 0 ) != CE_None )
345
+ if ( GDALRasterIO ( poBand, GF_Write, xPosition, yPosition, blockSize, blockSize,
346
+ dataBuffer, blockSize, blockSize, GDT_Float32, 0 , 0 ) != CE_None )
352
347
{
353
348
QgsDebugMsg ( " Raster IO Error" );
354
349
}
0 commit comments