Skip to content
Permalink
Browse files

heatmap plugin: port to C-API (fixes #15028)

  • Loading branch information
jef-n committed Jun 22, 2016
1 parent d7414d7 commit 186036659e31f416751f40ffc872da1d23996704
Showing with 27 additions and 31 deletions.
  1. +1 −0 src/app/qgsapplayertreeviewmenuprovider.cpp
  2. +17 −22 src/plugins/heatmap/heatmap.cpp
  3. +9 −9 src/plugins/heatmap/heatmapgui.cpp
@@ -568,6 +568,7 @@ void QgsAppLayerTreeViewMenuProvider::editSymbolLegendNodeSymbol()
QScopedPointer< QgsSymbolV2 > symbol( originalSymbol->clone() );
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( node->layerNode()->layer() );
QgsSymbolV2SelectorDialog dlg( symbol.data(), QgsStyleV2::defaultStyle(), vlayer, mView->window() );
dlg.setWindowTitle( tr( "Edit symbol" ) );
dlg.setMapCanvas( mCanvas );
if ( dlg.exec() )
{
@@ -16,9 +16,9 @@
***************************************************************************/

// GDAL includes
#include "gdal_priv.h"
#include "cpl_string.h"
#include "cpl_conv.h"
#include <gdal.h>
#include <cpl_string.h>
#include <cpl_conv.h>

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

GDALDataset *emptyDataset;
GDALDriver *myDriver;

myDriver = GetGDALDriverManager()->GetDriverByName( d.outputFormat().toUtf8() );
GDALDriverH myDriver = GDALGetDriverByName( d.outputFormat().toUtf8() );
if ( !myDriver )
{
mQGisIface->messageBar()->pushMessage( tr( "GDAL driver error" ), tr( "Cannot open the driver for the specified format" ), QgsMessageBar::WARNING, mQGisIface->messageTimeout() );
return;
}

double geoTransform[6] = { myBBox.xMinimum(), cellsize, 0, myBBox.yMinimum(), 0, cellsize };
emptyDataset = myDriver->Create( d.outputFilename().toUtf8(), columns, rows, 1, GDT_Float32, nullptr );
emptyDataset->SetGeoTransform( geoTransform );
GDALDatasetH emptyDataset = GDALCreate( myDriver, d.outputFilename().toUtf8(), columns, rows, 1, GDT_Float32, nullptr );
GDALSetGeoTransform( emptyDataset, geoTransform );
// Set the projection on the raster destination to match the input layer
emptyDataset->SetProjection( inputLayer->crs().toWkt().toLocal8Bit().data() );
GDALSetProjection( emptyDataset, inputLayer->crs().toWkt().toLocal8Bit().data() );

GDALRasterBand *poBand;
poBand = emptyDataset->GetRasterBand( 1 );
poBand->SetNoDataValue( NO_DATA );
GDALRasterBandH poBand = GDALGetRasterBand( emptyDataset, 1 );
GDALSetRasterNoDataValue( poBand, NO_DATA );

float* line = ( float * ) CPLMalloc( sizeof( float ) * columns );
for ( int i = 0; i < columns ; i++ )
@@ -170,25 +166,24 @@ void Heatmap::run()
// Write the empty raster
for ( int i = 0; i < rows ; i++ )
{
if ( poBand->RasterIO( GF_Write, 0, i, columns, 1, line, columns, 1, GDT_Float32, 0, 0 ) != CE_None )
if ( GDALRasterIO( poBand, GF_Write, 0, i, columns, 1, line, columns, 1, GDT_Float32, 0, 0 ) != CE_None )
{
QgsDebugMsg( "Raster IO Error" );
}
}

CPLFree( line );
//close the dataset
GDALClose(( GDALDatasetH ) emptyDataset );
GDALClose( emptyDataset );

// open the raster in GA_Update mode
GDALDataset *heatmapDS;
heatmapDS = ( GDALDataset * ) GDALOpen( TO8F( d.outputFilename() ), GA_Update );
GDALDatasetH heatmapDS = GDALOpen( TO8F( d.outputFilename() ), GA_Update );
if ( !heatmapDS )
{
mQGisIface->messageBar()->pushMessage( tr( "Raster update error" ), tr( "Could not open the created raster for updating. The heatmap was not generated." ), QgsMessageBar::WARNING );
return;
}
poBand = heatmapDS->GetRasterBand( 1 );
poBand = GDALGetRasterBand( heatmapDS, 1 );

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

// get the data
float *dataBuffer = ( float * ) CPLMalloc( sizeof( float ) * blockSize * blockSize );
if ( poBand->RasterIO( GF_Read, xPosition, yPosition, blockSize, blockSize,
dataBuffer, blockSize, blockSize, GDT_Float32, 0, 0 ) != CE_None )
if ( GDALRasterIO( poBand, GF_Read, xPosition, yPosition, blockSize, blockSize,
dataBuffer, blockSize, blockSize, GDT_Float32, 0, 0 ) != CE_None )
{
QgsDebugMsg( "Raster IO Error" );
}
@@ -347,8 +342,8 @@ void Heatmap::run()
}
}
}
if ( poBand->RasterIO( GF_Write, xPosition, yPosition, blockSize, blockSize,
dataBuffer, blockSize, blockSize, GDT_Float32, 0, 0 ) != CE_None )
if ( GDALRasterIO( poBand, GF_Write, xPosition, yPosition, blockSize, blockSize,
dataBuffer, blockSize, blockSize, GDT_Float32, 0, 0 ) != CE_None )
{
QgsDebugMsg( "Raster IO Error" );
}
@@ -24,9 +24,9 @@
#include "qgsdistancearea.h"

// GDAL includes
#include "gdal_priv.h"
#include "cpl_string.h"
#include "cpl_conv.h"
#include <gdal.h>
#include <cpl_string.h>
#include <cpl_conv.h>

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

0 comments on commit 1860366

Please sign in to comment.
You can’t perform that action at this time.