Skip to content

Commit 1860366

Browse files
committed
heatmap plugin: port to C-API (fixes #15028)
1 parent d7414d7 commit 1860366

File tree

3 files changed

+27
-31
lines changed

3 files changed

+27
-31
lines changed

src/app/qgsapplayertreeviewmenuprovider.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ void QgsAppLayerTreeViewMenuProvider::editSymbolLegendNodeSymbol()
568568
QScopedPointer< QgsSymbolV2 > symbol( originalSymbol->clone() );
569569
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( node->layerNode()->layer() );
570570
QgsSymbolV2SelectorDialog dlg( symbol.data(), QgsStyleV2::defaultStyle(), vlayer, mView->window() );
571+
dlg.setWindowTitle( tr( "Edit symbol" ) );
571572
dlg.setMapCanvas( mCanvas );
572573
if ( dlg.exec() )
573574
{

src/plugins/heatmap/heatmap.cpp

+17-22
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
***************************************************************************/
1717

1818
// 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>
2222

2323
// QGIS Specific includes
2424
#include <qgisinterface.h>
@@ -142,25 +142,21 @@ void Heatmap::run()
142142
// Getting the rasterdataset in place
143143
GDALAllRegister();
144144

145-
GDALDataset *emptyDataset;
146-
GDALDriver *myDriver;
147-
148-
myDriver = GetGDALDriverManager()->GetDriverByName( d.outputFormat().toUtf8() );
145+
GDALDriverH myDriver = GDALGetDriverByName( d.outputFormat().toUtf8() );
149146
if ( !myDriver )
150147
{
151148
mQGisIface->messageBar()->pushMessage( tr( "GDAL driver error" ), tr( "Cannot open the driver for the specified format" ), QgsMessageBar::WARNING, mQGisIface->messageTimeout() );
152149
return;
153150
}
154151

155152
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 );
158155
// 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() );
160157

161-
GDALRasterBand *poBand;
162-
poBand = emptyDataset->GetRasterBand( 1 );
163-
poBand->SetNoDataValue( NO_DATA );
158+
GDALRasterBandH poBand = GDALGetRasterBand( emptyDataset, 1 );
159+
GDALSetRasterNoDataValue( poBand, NO_DATA );
164160

165161
float* line = ( float * ) CPLMalloc( sizeof( float ) * columns );
166162
for ( int i = 0; i < columns ; i++ )
@@ -170,25 +166,24 @@ void Heatmap::run()
170166
// Write the empty raster
171167
for ( int i = 0; i < rows ; i++ )
172168
{
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 )
174170
{
175171
QgsDebugMsg( "Raster IO Error" );
176172
}
177173
}
178174

179175
CPLFree( line );
180176
//close the dataset
181-
GDALClose(( GDALDatasetH ) emptyDataset );
177+
GDALClose( emptyDataset );
182178

183179
// 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 );
186181
if ( !heatmapDS )
187182
{
188183
mQGisIface->messageBar()->pushMessage( tr( "Raster update error" ), tr( "Could not open the created raster for updating. The heatmap was not generated." ), QgsMessageBar::WARNING );
189184
return;
190185
}
191-
poBand = heatmapDS->GetRasterBand( 1 );
186+
poBand = GDALGetRasterBand( heatmapDS, 1 );
192187

193188
QgsAttributeList myAttrList;
194189
int rField = 0;
@@ -302,8 +297,8 @@ void Heatmap::run()
302297

303298
// get the data
304299
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 )
307302
{
308303
QgsDebugMsg( "Raster IO Error" );
309304
}
@@ -347,8 +342,8 @@ void Heatmap::run()
347342
}
348343
}
349344
}
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 )
352347
{
353348
QgsDebugMsg( "Raster IO Error" );
354349
}

src/plugins/heatmap/heatmapgui.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
#include "qgsdistancearea.h"
2525

2626
// GDAL includes
27-
#include "gdal_priv.h"
28-
#include "cpl_string.h"
29-
#include "cpl_conv.h"
27+
#include <gdal.h>
28+
#include <cpl_string.h>
29+
#include <cpl_conv.h>
3030

3131
//qt includes
3232
#include <QComboBox>
@@ -83,18 +83,18 @@ HeatmapGui::HeatmapGui( QWidget* parent, Qt::WindowFlags fl, QMap<QString, QVari
8383
int nDrivers = GDALGetDriverCount();
8484
for ( int i = 0; i < nDrivers; i += 1 )
8585
{
86-
GDALDriver* nthDriver = GetGDALDriverManager()->GetDriver( i );
87-
char** driverMetadata = nthDriver->GetMetadata();
86+
GDALDriverH nthDriver = GDALGetDriver( i );
87+
char **driverMetadata = GDALGetMetadata( nthDriver, nullptr );
8888
// Only formats which allow creation of Float32 data types are valid
8989
if ( CSLFetchBoolean( driverMetadata, GDAL_DCAP_CREATE, false ) &&
90-
QString( nthDriver->GetMetadataItem( GDAL_DMD_CREATIONDATATYPES, nullptr ) ).contains( "Float32" ) )
90+
QString( GDALGetMetadataItem( nthDriver, GDAL_DMD_CREATIONDATATYPES, nullptr ) ).contains( "Float32" ) )
9191
{
9292
++myIndex;
93-
QString myLongName = nthDriver->GetMetadataItem( GDAL_DMD_LONGNAME );
93+
QString myLongName = GDALGetMetadataItem( nthDriver, GDAL_DMD_LONGNAME, nullptr );
9494
// Add LongName text, shortname variant; GetDescription actually gets the shortname
95-
mFormatCombo->addItem( myLongName, QVariant( nthDriver->GetDescription() ) );
95+
mFormatCombo->addItem( myLongName, QVariant( GDALGetDescription( nthDriver ) ) );
9696
// Add the drivers and their extensions to a map for filename correction
97-
mExtensionMap.insert( nthDriver->GetDescription(), nthDriver->GetMetadataItem( GDAL_DMD_EXTENSION ) );
97+
mExtensionMap.insert( GDALGetDescription( nthDriver ), GDALGetMetadataItem( nthDriver, GDAL_DMD_EXTENSION, nullptr ) );
9898
if ( myLongName == "GeoTIFF" )
9999
{
100100
myTiffIndex = myIndex;

0 commit comments

Comments
 (0)