Skip to content
Permalink
Browse files

Remove some more macros not needed with GDAL>=2 requirement

  • Loading branch information
nyalldawson committed Jan 9, 2017
1 parent b0bc763 commit 4b8c5bea297be9259fc70de4b3f149b96fa85b9b
@@ -23,8 +23,6 @@
#define M_PI 3.14159265358979323846
#endif

#define TO8F(x) (x).toUtf8().constData()

QgsKernelDensityEstimation::QgsKernelDensityEstimation( const QgsKernelDensityEstimation::Parameters& parameters, const QString& outputFile, const QString& outputFormat )
: mInputLayer( parameters.vectorLayer )
, mOutputFile( outputFile )
@@ -95,7 +93,7 @@ QgsKernelDensityEstimation::Result QgsKernelDensityEstimation::prepare()
return FileCreationError;

// open the raster in GA_Update mode
mDatasetH = GDALOpen( TO8F( mOutputFile ), GA_Update );
mDatasetH = GDALOpen( mOutputFile.toUtf8().constData(), GA_Update );
if ( !mDatasetH )
return FileCreationError;
mRasterBandH = GDALGetRasterBand( mDatasetH, 1 );
@@ -21,8 +21,6 @@
#include <QProgressDialog>
#include <QFile>

#define TO8F(x) (x).toUtf8().constData()

QgsNineCellFilter::QgsNineCellFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat )
: mInputFile( inputFile )
, mOutputFile( outputFile )
@@ -204,7 +202,7 @@ int QgsNineCellFilter::processRaster( QProgressDialog* p )
if ( p && p->wasCanceled() )
{
//delete the dataset without closing (because it is faster)
GDALDeleteDataset( outputDriver, TO8F( mOutputFile ) );
GDALDeleteDataset( outputDriver, mOutputFile.toUtf8().constData() );
return 7;
}
GDALClose( outputDataset );
@@ -214,7 +212,7 @@ int QgsNineCellFilter::processRaster( QProgressDialog* p )

GDALDatasetH QgsNineCellFilter::openInputFile( int& nCellsX, int& nCellsY )
{
GDALDatasetH inputDataset = GDALOpen( TO8F( mInputFile ), GA_ReadOnly );
GDALDatasetH inputDataset = GDALOpen( mInputFile.toUtf8().constData(), GA_ReadOnly );
if ( inputDataset )
{
nCellsX = GDALGetRasterXSize( inputDataset );
@@ -263,7 +261,7 @@ GDALDatasetH QgsNineCellFilter::openOutputFile( GDALDatasetH inputDataset, GDALD

//open output file
char **papszOptions = nullptr;
GDALDatasetH outputDataset = GDALCreate( outputDriver, TO8F( mOutputFile ), xSize, ySize, 1, GDT_Float32, papszOptions );
GDALDatasetH outputDataset = GDALCreate( outputDriver, mOutputFile.toUtf8().constData(), xSize, ySize, 1, GDT_Float32, papszOptions );
if ( !outputDataset )
{
return outputDataset;
@@ -29,9 +29,6 @@
#include <cpl_string.h>
#include <gdalwarper.h>

#define TO8(x) (x).toUtf8().constData()
#define TO8F(x) (x).toUtf8().constData()

QgsRasterCalculator::QgsRasterCalculator( const QString& formulaString, const QString& outputFile, const QString& outputFormat,
const QgsRectangle& outputExtent, int nOutputColumns, int nOutputRows, const QVector<QgsRasterCalculatorEntry>& rasterEntries )
: mFormulaString( formulaString )
@@ -175,7 +172,7 @@ int QgsRasterCalculator::processCalculation( QProgressDialog* p )
if ( p && p->wasCanceled() )
{
//delete the dataset without closing (because it is faster)
GDALDeleteDataset( outputDriver, TO8F( mOutputFile ) );
GDALDeleteDataset( outputDriver, mOutputFile.toUtf8().constData() );
return static_cast< int >( Cancelled );
}
GDALClose( outputDataset );
@@ -214,7 +211,7 @@ GDALDatasetH QgsRasterCalculator::openOutputFile( GDALDriverH outputDriver )
{
//open output file
char **papszOptions = nullptr;
GDALDatasetH outputDataset = GDALCreate( outputDriver, TO8F( mOutputFile ), mNumOutputColumns, mNumOutputRows, 1, GDT_Float32, papszOptions );
GDALDatasetH outputDataset = GDALCreate( outputDriver, mOutputFile.toUtf8().constData(), mNumOutputColumns, mNumOutputRows, 1, GDT_Float32, papszOptions );
if ( !outputDataset )
{
return outputDataset;
@@ -28,8 +28,6 @@
#include <QFile>
#include <QTextStream>

#define TO8F(x) (x).toUtf8().constData()

QgsRelief::QgsRelief( const QString& inputFile, const QString& outputFile, const QString& outputFormat )
: mInputFile( inputFile )
, mOutputFile( outputFile )
@@ -288,7 +286,7 @@ int QgsRelief::processRaster( QProgressDialog* p )
if ( p && p->wasCanceled() )
{
//delete the dataset without closing (because it is faster)
GDALDeleteDataset( outputDriver, TO8F( mOutputFile ) );
GDALDeleteDataset( outputDriver, mOutputFile.toUtf8().constData() );
return 7;
}
GDALClose( outputDataset );
@@ -411,7 +409,7 @@ bool QgsRelief::setElevationColor( double elevation, int* red, int* green, int*
//duplicated from QgsNineCellFilter. Todo: make common base class
GDALDatasetH QgsRelief::openInputFile( int& nCellsX, int& nCellsY )
{
GDALDatasetH inputDataset = GDALOpen( TO8F( mInputFile ), GA_ReadOnly );
GDALDatasetH inputDataset = GDALOpen( mInputFile.toUtf8().constData(), GA_ReadOnly );
if ( inputDataset )
{
nCellsX = GDALGetRasterXSize( inputDataset );
@@ -465,7 +463,7 @@ GDALDatasetH QgsRelief::openOutputFile( GDALDatasetH inputDataset, GDALDriverH o
papszOptions = CSLSetNameValue( papszOptions, "COMPRESS", "PACKBITS" );

//create three band raster (reg, green, blue)
GDALDatasetH outputDataset = GDALCreate( outputDriver, TO8F( mOutputFile ), xSize, ySize, 3, GDT_Byte, papszOptions );
GDALDatasetH outputDataset = GDALCreate( outputDriver, mOutputFile.toUtf8().constData(), xSize, ySize, 3, GDT_Byte, papszOptions );
if ( !outputDataset )
{
return outputDataset;
@@ -28,8 +28,6 @@
#include <QProgressDialog>
#include <QFile>

#define TO8F(x) (x).toUtf8().constData()

QgsZonalStatistics::QgsZonalStatistics( QgsVectorLayer* polygonLayer, const QString& rasterFile, const QString& attributePrefix, int rasterBand, Statistics stats )
: mRasterFilePath( rasterFile )
, mRasterBand( rasterBand )
@@ -65,7 +63,7 @@ int QgsZonalStatistics::calculateStatistics( QProgressDialog* p )

//open the raster layer and the raster band
GDALAllRegister();
GDALDatasetH inputDataset = GDALOpen( TO8F( mRasterFilePath ), GA_ReadOnly );
GDALDatasetH inputDataset = GDALOpen( mRasterFilePath.toUtf8().constData(), GA_ReadOnly );
if ( !inputDataset )
{
return 3;
@@ -26,8 +26,6 @@
#include <ogr_api.h>
#include <cpl_error.h>

#define TO8F(x) (x).toUtf8().constData()

QgsNewOgrConnection::QgsNewOgrConnection( QWidget *parent, const QString& connType, const QString& connName, Qt::WindowFlags fl )
: QDialog( parent, fl )
, mOriginalConnName( connName )
@@ -85,7 +83,7 @@ void QgsNewOgrConnection::testConnection()
OGRDataSourceH poDS;
OGRSFDriverH pahDriver;
CPLErrorReset();
poDS = OGROpen( TO8F( uri ), false, &pahDriver );
poDS = OGROpen( uri.toUtf8().constData(), false, &pahDriver );
if ( !poDS )
{
QMessageBox::information( this, tr( "Test connection" ), tr( "Connection failed - Check settings and try again.\n\nExtended error information:\n%1" ).arg( QString::fromUtf8( CPLGetLastErrorMsg() ) ) );
@@ -266,8 +266,6 @@
#include <gdal_version.h>
#include <proj_api.h>

#define SUPPORT_GEOPACKAGE

//
// Other includes
//
@@ -1962,10 +1960,6 @@ void QgisApp::createMenus()
*/

// Layer menu
#ifndef SUPPORT_GEOPACKAGE
mProjectMenu->removeAction( mActionDwgImport );
mNewLayerMenu->removeAction( mActionNewGeoPackageLayer );
#endif

// Panel and Toolbar Submenus
mPanelMenu = new QMenu( tr( "Panels" ), this );
@@ -2239,9 +2233,7 @@ void QgisApp::createToolBars()
bt->setPopupMode( QToolButton::MenuButtonPopup );
bt->addAction( mActionNewVectorLayer );
bt->addAction( mActionNewSpatiaLiteLayer );
#ifdef SUPPORT_GEOPACKAGE
bt->addAction( mActionNewGeoPackageLayer );
#endif
bt->addAction( mActionNewMemoryLayer );

QAction* defNewLayerAction = mActionNewVectorLayer;
@@ -2256,11 +2248,9 @@ void QgisApp::createToolBars()
case 2:
defNewLayerAction = mActionNewMemoryLayer;
break;
#ifdef SUPPORT_GEOPACKAGE
case 3:
defNewLayerAction = mActionNewGeoPackageLayer;
break;
#endif
}
bt->setDefaultAction( defNewLayerAction );
QAction* newLayerAction = mLayerToolBar->addWidget( bt );
@@ -21,10 +21,6 @@
#include <QTextCodec>
#include <QUuid>

#define TO8(x) (x).toUtf8().constData()
#define TO8F(x) (x).toUtf8().constData()
#define FROM8(x) QString::fromUtf8(x)

QgsFeature QgsOgrUtils::readOgrFeature( OGRFeatureH ogrFet, const QgsFields& fields, QTextCodec* encoding )
{
QgsFeature feature;
@@ -233,21 +229,21 @@ QgsFeatureList QgsOgrUtils::stringToFeatureList( const QString& string, const Qg

// create memory file system object from string buffer
QByteArray ba = string.toUtf8();
VSIFCloseL( VSIFileFromMemBuffer( TO8( randomFileName ), reinterpret_cast< GByte* >( ba.data() ),
VSIFCloseL( VSIFileFromMemBuffer( randomFileName.toUtf8().constData(), reinterpret_cast< GByte* >( ba.data() ),
static_cast< vsi_l_offset >( ba.size() ), FALSE ) );

OGRDataSourceH hDS = OGROpen( TO8( randomFileName ), false, nullptr );
OGRDataSourceH hDS = OGROpen( randomFileName.toUtf8().constData(), false, nullptr );
if ( !hDS )
{
VSIUnlink( TO8( randomFileName ) );
VSIUnlink( randomFileName.toUtf8().constData() );
return features;
}

OGRLayerH ogrLayer = OGR_DS_GetLayer( hDS, 0 );
if ( !ogrLayer )
{
OGR_DS_Destroy( hDS );
VSIUnlink( TO8( randomFileName ) );
VSIUnlink( randomFileName.toUtf8().constData() );
return features;
}

@@ -262,7 +258,7 @@ QgsFeatureList QgsOgrUtils::stringToFeatureList( const QString& string, const Qg
}

OGR_DS_Destroy( hDS );
VSIUnlink( TO8( randomFileName ) );
VSIUnlink( randomFileName.toUtf8().constData() );

return features;
}
@@ -277,21 +273,21 @@ QgsFields QgsOgrUtils::stringToFields( const QString& string, QTextCodec* encodi

// create memory file system object from buffer
QByteArray ba = string.toUtf8();
VSIFCloseL( VSIFileFromMemBuffer( TO8( randomFileName ), reinterpret_cast< GByte* >( ba.data() ),
VSIFCloseL( VSIFileFromMemBuffer( randomFileName.toUtf8().constData(), reinterpret_cast< GByte* >( ba.data() ),
static_cast< vsi_l_offset >( ba.size() ), FALSE ) );

OGRDataSourceH hDS = OGROpen( TO8( randomFileName ), false, nullptr );
OGRDataSourceH hDS = OGROpen( randomFileName.toUtf8().constData(), false, nullptr );
if ( !hDS )
{
VSIUnlink( TO8( randomFileName ) );
VSIUnlink( randomFileName.toUtf8().constData() );
return fields;
}

OGRLayerH ogrLayer = OGR_DS_GetLayer( hDS, 0 );
if ( !ogrLayer )
{
OGR_DS_Destroy( hDS );
VSIUnlink( TO8( randomFileName ) );
VSIUnlink( randomFileName.toUtf8().constData() );
return fields;
}

@@ -304,6 +300,6 @@ QgsFields QgsOgrUtils::stringToFields( const QString& string, QTextCodec* encodi
}

OGR_DS_Destroy( hDS );
VSIUnlink( TO8( randomFileName ) );
VSIUnlink( randomFileName.toUtf8().constData() );
return fields;
}
@@ -50,8 +50,6 @@
#include <cpl_conv.h>
#include <gdal.h>

#define TO8F(x) (x).toUtf8().constData()

QgsVectorFileWriter::FieldValueConverter::FieldValueConverter()
{
}
@@ -275,9 +273,9 @@ void QgsVectorFileWriter::init( QString vectorFileName,

// create the data source
if ( action == CreateOrOverwriteFile )
mDS = OGR_Dr_CreateDataSource( poDriver, TO8F( vectorFileName ), options );
mDS = OGR_Dr_CreateDataSource( poDriver, vectorFileName.toUtf8().constData(), options );
else
mDS = OGROpen( TO8F( vectorFileName ), TRUE, nullptr );
mDS = OGROpen( vectorFileName.toUtf8().constData(), TRUE, nullptr );

if ( options )
{
@@ -309,7 +307,7 @@ void QgsVectorFileWriter::init( QString vectorFileName,
for ( int i = 0; i < layer_count; i++ )
{
OGRLayerH hLayer = OGR_DS_GetLayer( mDS, i );
if ( EQUAL( OGR_L_GetName( hLayer ), TO8F( layerName ) ) )
if ( EQUAL( OGR_L_GetName( hLayer ), layerName.toUtf8().constData() ) )
{
if ( OGR_DS_DeleteLayer( mDS, i ) != OGRERR_NONE )
{
@@ -377,9 +375,9 @@ void QgsVectorFileWriter::init( QString vectorFileName,
CPLSetConfigOption( "SHAPE_ENCODING", "" );

if ( action == CreateOrOverwriteFile || action == CreateOrOverwriteLayer )
mLayer = OGR_DS_CreateLayer( mDS, TO8F( layerName ), mOgrRef, wkbType, options );
mLayer = OGR_DS_CreateLayer( mDS, layerName.toUtf8().constData(), mOgrRef, wkbType, options );
else
mLayer = OGR_DS_GetLayerByName( mDS, TO8F( layerName ) );
mLayer = OGR_DS_GetLayerByName( mDS, layerName.toUtf8().constData() );

if ( options )
{
@@ -2609,11 +2607,11 @@ QMap<QString, QString> QgsVectorFileWriter::ogrDriverList()
poDriver = OGRGetDriverByName( drvName.toLocal8Bit().constData() );
if ( poDriver )
{
OGRDataSourceH ds = OGR_Dr_CreateDataSource( poDriver, TO8F( QString( "/vsimem/spatialitetest.sqlite" ) ), options );
OGRDataSourceH ds = OGR_Dr_CreateDataSource( poDriver, QString( "/vsimem/spatialitetest.sqlite" ).toUtf8().constData(), options );
if ( ds )
{
writableDrivers << QStringLiteral( "SpatiaLite" );
OGR_Dr_DeleteDataSource( poDriver, TO8F( QString( "/vsimem/spatialitetest.sqlite" ) ) );
OGR_Dr_DeleteDataSource( poDriver, QString( "/vsimem/spatialitetest.sqlite" ).toUtf8().constData() );
OGR_DS_Destroy( ds );
}
}
@@ -3013,7 +3011,7 @@ QStringList QgsVectorFileWriter::concatenateOptions( const QMap<QString, QgsVect
QgsVectorFileWriter::EditionCapabilities QgsVectorFileWriter::editionCapabilities( const QString& datasetName )
{
OGRSFDriverH hDriver = nullptr;
OGRDataSourceH hDS = OGROpen( TO8F( datasetName ), TRUE, &hDriver );
OGRDataSourceH hDS = OGROpen( datasetName.toUtf8().constData(), TRUE, &hDriver );
if ( !hDS )
return 0;
QString drvName = OGR_Dr_GetName( hDriver );
@@ -3054,15 +3052,15 @@ bool QgsVectorFileWriter::targetLayerExists( const QString& datasetName,
const QString& layerNameIn )
{
OGRSFDriverH hDriver = nullptr;
OGRDataSourceH hDS = OGROpen( TO8F( datasetName ), TRUE, &hDriver );
OGRDataSourceH hDS = OGROpen( datasetName.toUtf8().constData(), TRUE, &hDriver );
if ( !hDS )
return false;

QString layerName( layerNameIn );
if ( layerName.isEmpty() )
layerName = QFileInfo( datasetName ).baseName();

bool ret = OGR_DS_GetLayerByName( hDS, TO8F( layerName ) );
bool ret = OGR_DS_GetLayerByName( hDS, layerName.toUtf8().constData() );
OGR_DS_Destroy( hDS );
return ret;
}
@@ -3074,10 +3072,10 @@ bool QgsVectorFileWriter::areThereNewFieldsToCreate( const QString& datasetName,
const QgsAttributeList& attributes )
{
OGRSFDriverH hDriver = nullptr;
OGRDataSourceH hDS = OGROpen( TO8F( datasetName ), TRUE, &hDriver );
OGRDataSourceH hDS = OGROpen( datasetName.toUtf8().constData(), TRUE, &hDriver );
if ( !hDS )
return false;
OGRLayerH hLayer = OGR_DS_GetLayerByName( hDS, TO8F( layerName ) );
OGRLayerH hLayer = OGR_DS_GetLayerByName( hDS, layerName.toUtf8().constData() );
if ( !hLayer )
{
OGR_DS_Destroy( hDS );
@@ -3088,7 +3086,7 @@ bool QgsVectorFileWriter::areThereNewFieldsToCreate( const QString& datasetName,
Q_FOREACH ( int idx, attributes )
{
QgsField fld = layer->fields().at( idx );
if ( OGR_FD_GetFieldIndex( defn, TO8F( fld.name() ) ) < 0 )
if ( OGR_FD_GetFieldIndex( defn, fld.name().toUtf8().constData() ) < 0 )
{
ret = true;
break;

0 comments on commit 4b8c5be

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