Skip to content

Commit

Permalink
Merge pull request #3940 from nyalldawson/gdal2
Browse files Browse the repository at this point in the history
Bump minimum GDAL version to 2.0, remove old version #ifdefs
  • Loading branch information
nyalldawson committed Jan 10, 2017
2 parents 313ec55 + 4b8c5be commit 21ad4ed
Show file tree
Hide file tree
Showing 44 changed files with 110 additions and 688 deletions.
22 changes: 7 additions & 15 deletions cmake/FindGDAL.cmake
Expand Up @@ -61,13 +61,9 @@ ELSE(WIN32)
ENDIF (NOT GDAL_VERSION)
STRING(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\1" GDAL_VERSION_MAJOR "${GDAL_VERSION}")
STRING(REGEX REPLACE "([0-9]+)\\.([0-9]+)\\.([0-9]+)" "\\2" GDAL_VERSION_MINOR "${GDAL_VERSION}")
IF (GDAL_VERSION_MAJOR LESS 1 OR (GDAL_VERSION EQUAL 1 AND GDAL_VERSION_MINOR LESS 4))
MESSAGE (FATAL_ERROR "GDAL version is too old (${GDAL_VERSION}). Use 1.4.0 or higher.")
ENDIF (GDAL_VERSION_MAJOR LESS 1 OR (GDAL_VERSION EQUAL 1 AND GDAL_VERSION_MINOR LESS 4))

IF (GDAL_VERSION_MAJOR LESS 1 OR (GDAL_VERSION_MAJOR EQUAL 1 AND GDAL_VERSION_MINOR LESS 11))
MESSAGE (WARNING "GDAL version is too old (${GDAL_VERSION}) to support GeoPackage. 1.11.0 or higher is recommended.")
ENDIF (GDAL_VERSION_MAJOR LESS 1 OR (GDAL_VERSION_MAJOR EQUAL 1 AND GDAL_VERSION_MINOR LESS 11))
IF (GDAL_VERSION_MAJOR LESS 2)
MESSAGE (FATAL_ERROR "GDAL version is too old (${GDAL_VERSION}). Use 2.0 or higher.")
ENDIF (GDAL_VERSION_MAJOR LESS 2)

ENDIF (GDAL_LIBRARY)
SET (CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK_save} CACHE STRING "" FORCE)
Expand Down Expand Up @@ -105,14 +101,10 @@ ELSE(WIN32)

# check for gdal version
# version 1.2.5 is known NOT to be supported (missing CPL_STDCALL macro)
# According to INSTALL, 1.4.0+ is required
IF (GDAL_VERSION_MAJOR LESS 1 OR (GDAL_VERSION_MAJOR EQUAL 1 AND GDAL_VERSION_MINOR LESS 4))
MESSAGE (FATAL_ERROR "GDAL version is too old (${GDAL_VERSION}). Use 1.4.0 or higher.")
ENDIF (GDAL_VERSION_MAJOR LESS 1 OR (GDAL_VERSION_MAJOR EQUAL 1 AND GDAL_VERSION_MINOR LESS 4))

IF (GDAL_VERSION_MAJOR LESS 1 OR (GDAL_VERSION_MAJOR EQUAL 1 AND GDAL_VERSION_MINOR LESS 11))
MESSAGE (WARNING "GDAL version is too old (${GDAL_VERSION}) to support GeoPackage. 1.11.0 or higher is recommended.")
ENDIF (GDAL_VERSION_MAJOR LESS 1 OR (GDAL_VERSION_MAJOR EQUAL 1 AND GDAL_VERSION_MINOR LESS 11))
# According to INSTALL, 2.0+ is required
IF (GDAL_VERSION_MAJOR LESS 2)
MESSAGE (FATAL_ERROR "GDAL version is too old (${GDAL_VERSION}). Use 2.0 or higher.")
ENDIF (GDAL_VERSION_MAJOR LESS 2)

# set INCLUDE_DIR to prefix+include
EXEC_PROGRAM(${GDAL_CONFIG}
Expand Down
8 changes: 1 addition & 7 deletions src/analysis/raster/qgskde.cpp
Expand Up @@ -23,12 +23,6 @@
#define M_PI 3.14159265358979323846
#endif

#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
#define TO8F(x) (x).toUtf8().constData()
#else
#define TO8F(x) QFile::encodeName( x ).constData()
#endif

QgsKernelDensityEstimation::QgsKernelDensityEstimation( const QgsKernelDensityEstimation::Parameters& parameters, const QString& outputFile, const QString& outputFormat )
: mInputLayer( parameters.vectorLayer )
, mOutputFile( outputFile )
Expand Down Expand Up @@ -99,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 );
Expand Down
12 changes: 3 additions & 9 deletions src/analysis/raster/qgsninecellfilter.cpp
Expand Up @@ -21,12 +21,6 @@
#include <QProgressDialog>
#include <QFile>

#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
#define TO8F(x) (x).toUtf8().constData()
#else
#define TO8F(x) QFile::encodeName( x ).constData()
#endif

QgsNineCellFilter::QgsNineCellFilter( const QString& inputFile, const QString& outputFile, const QString& outputFormat )
: mInputFile( inputFile )
, mOutputFile( outputFile )
Expand Down Expand Up @@ -208,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 );
Expand All @@ -218,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 );
Expand Down Expand Up @@ -267,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;
Expand Down
12 changes: 2 additions & 10 deletions src/analysis/raster/qgsrastercalculator.cpp
Expand Up @@ -29,14 +29,6 @@
#include <cpl_string.h>
#include <gdalwarper.h>

#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
#define TO8(x) (x).toUtf8().constData()
#define TO8F(x) (x).toUtf8().constData()
#else
#define TO8(x) (x).toLocal8Bit().constData()
#define TO8F(x) QFile::encodeName( x ).constData()
#endif

QgsRasterCalculator::QgsRasterCalculator( const QString& formulaString, const QString& outputFile, const QString& outputFormat,
const QgsRectangle& outputExtent, int nOutputColumns, int nOutputRows, const QVector<QgsRasterCalculatorEntry>& rasterEntries )
: mFormulaString( formulaString )
Expand Down Expand Up @@ -180,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 );
Expand Down Expand Up @@ -219,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;
Expand Down
12 changes: 3 additions & 9 deletions src/analysis/raster/qgsrelief.cpp
Expand Up @@ -28,12 +28,6 @@
#include <QFile>
#include <QTextStream>

#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
#define TO8F(x) (x).toUtf8().constData()
#else
#define TO8F(x) QFile::encodeName( x ).constData()
#endif

QgsRelief::QgsRelief( const QString& inputFile, const QString& outputFile, const QString& outputFormat )
: mInputFile( inputFile )
, mOutputFile( outputFile )
Expand Down Expand Up @@ -292,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 );
Expand Down Expand Up @@ -415,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 );
Expand Down Expand Up @@ -469,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;
Expand Down
8 changes: 1 addition & 7 deletions src/analysis/vector/qgszonalstatistics.cpp
Expand Up @@ -28,12 +28,6 @@
#include <QProgressDialog>
#include <QFile>

#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
#define TO8F(x) (x).toUtf8().constData()
#else
#define TO8F(x) QFile::encodeName( x ).constData()
#endif

QgsZonalStatistics::QgsZonalStatistics( QgsVectorLayer* polygonLayer, const QString& rasterFile, const QString& attributePrefix, int rasterBand, Statistics stats )
: mRasterFilePath( rasterFile )
, mRasterBand( rasterBand )
Expand Down Expand Up @@ -69,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;
Expand Down
5 changes: 0 additions & 5 deletions src/app/dwg/qgsdwgimportdialog.cpp
Expand Up @@ -69,11 +69,6 @@ QgsDwgImportDialog::QgsDwgImportDialog( QWidget *parent, Qt::WindowFlags f )
cbMergeLayers->setChecked( s.value( "/DwgImport/lastMergeLayers", false ).toBool() );
cbUseCurves->setChecked( s.value( "/DwgImport/lastUseCurves", true ).toBool() );

#if !defined(GDAL_COMPUTE_VERSION) || GDAL_VERSION_NUM < GDAL_COMPUTE_VERSION(2,0,0)
cbUseCurves->setChecked( false );
cbUseCurves->setHidden( true );
#endif

leDrawing->setReadOnly( true );
pbImportDrawing->setHidden( true );
lblMessage->setHidden( true );
Expand Down
9 changes: 0 additions & 9 deletions src/app/dwg/qgsdwgimporter.cpp
Expand Up @@ -140,30 +140,26 @@ void QgsDwgImporter::startTransaction()
{
Q_ASSERT( mDs );

#if defined(GDAL_COMPUTE_VERSION) && GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,0,0)
mInTransaction = GDALDatasetStartTransaction( mDs, 0 ) == OGRERR_NONE;
if ( !mInTransaction )
{
LOG( QObject::tr( "Could not start transaction\nDatabase:%1\nError:%2" )
.arg( mDatabase )
.arg( QString::fromUtf8( CPLGetLastErrorMsg() ) ) );
}
#endif
}

void QgsDwgImporter::commitTransaction()
{
Q_ASSERT( mDs != nullptr );

#if defined(GDAL_COMPUTE_VERSION) && GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,0,0)
if ( mInTransaction && GDALDatasetCommitTransaction( mDs ) != OGRERR_NONE )
{
LOG( QObject::tr( "Could not commit transaction\nDatabase:%1\nError:%2" )
.arg( mDatabase )
.arg( QString::fromUtf8( CPLGetLastErrorMsg() ) ) );
}
mInTransaction = false;
#endif
}

QgsDwgImporter::~QgsDwgImporter()
Expand All @@ -186,13 +182,8 @@ bool QgsDwgImporter::import( const QString &drawing, QString &error, bool doExpa
OGRwkbGeometryType lineGeomType, hatchGeomType;
if ( useCurves )
{
#if !defined(GDAL_COMPUTE_VERSION) || GDAL_VERSION_NUM < GDAL_COMPUTE_VERSION(2,0,0)
error = QObject::tr( "Curves only supported with GDAL2" );
return false;
#else
lineGeomType = wkbCompoundCurveZ;
hatchGeomType = wkbCurvePolygonZ;
#endif
}
else
{
Expand Down
8 changes: 1 addition & 7 deletions src/app/ogr/qgsnewogrconnection.cpp
Expand Up @@ -26,12 +26,6 @@
#include <ogr_api.h>
#include <cpl_error.h>

#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1800
#define TO8F(x) (x).toUtf8().constData()
#else
#define TO8F(x) QFile::encodeName( x ).constData()
#endif

QgsNewOgrConnection::QgsNewOgrConnection( QWidget *parent, const QString& connType, const QString& connName, Qt::WindowFlags fl )
: QDialog( parent, fl )
, mOriginalConnName( connName )
Expand Down Expand Up @@ -89,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() ) ) );
Expand Down
12 changes: 0 additions & 12 deletions src/app/qgisapp.cpp
Expand Up @@ -266,10 +266,6 @@
#include <gdal_version.h>
#include <proj_api.h>

#if defined(GDAL_COMPUTE_VERSION) && GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(1,11,0)
#define SUPPORT_GEOPACKAGE
#endif

//
// Other includes
//
Expand Down Expand Up @@ -1964,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 );
Expand Down Expand Up @@ -2241,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;
Expand All @@ -2258,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 );
Expand Down
2 changes: 0 additions & 2 deletions src/app/qgsalignrasterdialog.cpp
Expand Up @@ -393,13 +393,11 @@ QgsAlignRasterLayerConfigDialog::QgsAlignRasterLayerConfigDialog()
cboResample->addItem( tr( "Lanczos (6x6 kernel)" ), QgsAlignRaster::RA_Lanczos );
cboResample->addItem( tr( "Average" ), QgsAlignRaster::RA_Average );
cboResample->addItem( tr( "Mode" ), QgsAlignRaster::RA_Mode );
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 2000000
cboResample->addItem( tr( "Maximum" ), QgsAlignRaster::RA_Max );
cboResample->addItem( tr( "Minimum" ), QgsAlignRaster::RA_Min );
cboResample->addItem( tr( "Median" ), QgsAlignRaster::RA_Median );
cboResample->addItem( tr( "First Quartile (Q1)" ), QgsAlignRaster::RA_Q1 );
cboResample->addItem( tr( "Third Quartile (Q3)" ), QgsAlignRaster::RA_Q3 );
#endif

editOutput = new QLineEdit( this );
btnBrowse = new QPushButton( tr( "Browse..." ), this );
Expand Down
4 changes: 0 additions & 4 deletions src/app/qgsoptions.cpp
Expand Up @@ -1852,12 +1852,8 @@ void QgsOptions::loadGdalDriverList()

// in GDAL 2.0 vector and mixed drivers are returned by GDALGetDriver, so filter out non-raster drivers
// TODO add same UI for vector drivers
#ifdef GDAL_COMPUTE_VERSION
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,0,0)
if ( QString( GDALGetMetadataItem( myGdalDriver, GDAL_DCAP_RASTER, nullptr ) ) != "YES" )
continue;
#endif
#endif

myGdalDriverDescription = GDALGetDescription( myGdalDriver );
myDrivers << myGdalDriverDescription;
Expand Down
4 changes: 0 additions & 4 deletions src/core/qgis.cpp
Expand Up @@ -47,11 +47,7 @@ const int Qgis::QGIS_VERSION_INT = VERSION_INT;
// Release name
QString Qgis::QGIS_RELEASE_NAME( QStringLiteral( RELEASE_NAME ) );

#if GDAL_VERSION_NUM >= 1800
const QString GEOPROJ4 = QStringLiteral( "+proj=longlat +datum=WGS84 +no_defs" );
#else
const QString GEOPROJ4 = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs";
#endif

const QString GEOWKT =
"GEOGCS[\"WGS 84\", "
Expand Down
4 changes: 0 additions & 4 deletions src/core/qgscoordinatereferencesystem.cpp
Expand Up @@ -214,12 +214,10 @@ bool QgsCoordinateReferenceSystem::createFromUserInput( const QString &theDefini
OGRSpatialReferenceH crs = OSRNewSpatialReference( nullptr );

// make sure towgs84 parameter is loaded if using an ESRI definition and gdal >= 1.9
#if GDAL_VERSION_NUM >= 1900
if ( theDefinition.startsWith( QLatin1String( "ESRI::" ) ) )
{
setupESRIWktFix();
}
#endif

if ( OSRSetFromUserInput( crs, theDefinition.toLocal8Bit().constData() ) == OGRERR_NONE )
{
Expand All @@ -238,7 +236,6 @@ void QgsCoordinateReferenceSystem::setupESRIWktFix()
{
// make sure towgs84 parameter is loaded if gdal >= 1.9
// this requires setting GDAL_FIX_ESRI_WKT=GEOGCS (see qgis bug #5598 and gdal bug #4673)
#if GDAL_VERSION_NUM >= 1900
const char* configOld = CPLGetConfigOption( "GDAL_FIX_ESRI_WKT", "" );
const char* configNew = "GEOGCS";
// only set if it was not set, to let user change the value if needed
Expand All @@ -254,7 +251,6 @@ void QgsCoordinateReferenceSystem::setupESRIWktFix()
{
QgsDebugMsg( QString( "GDAL_FIX_ESRI_WKT was already set : %1" ).arg( configNew ) );
}
#endif
}

bool QgsCoordinateReferenceSystem::createFromOgcWmsCrs( const QString& theCrs )
Expand Down
4 changes: 0 additions & 4 deletions src/core/qgsgml.cpp
Expand Up @@ -868,11 +868,7 @@ void QgsGmlStreamingParser::endElement( const XML_Char* el )
{
const int wkbSize = OGR_G_WkbSize( hGeom );
unsigned char* pabyBuffer = new unsigned char[ wkbSize ];
#if GDAL_VERSION_MAJOR >= 2
OGR_G_ExportToIsoWkb( hGeom, wkbNDR, pabyBuffer );
#else
OGR_G_ExportToWkb( hGeom, wkbNDR, pabyBuffer );
#endif
QgsGeometry g;
g.fromWkb( pabyBuffer, wkbSize );
if ( mInvertAxisOrientation )
Expand Down

0 comments on commit 21ad4ed

Please sign in to comment.