Skip to content

Commit

Permalink
Bump minimum GDAL version to 2.0, remove old version #ifdefs
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 3, 2017
1 parent f59acad commit b0bc763
Show file tree
Hide file tree
Showing 41 changed files with 18 additions and 512 deletions.
22 changes: 7 additions & 15 deletions cmake/FindGDAL.cmake
Original file line number Diff line number Diff line change
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
4 changes: 0 additions & 4 deletions src/analysis/raster/qgskde.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@
#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 )
Expand Down
4 changes: 0 additions & 4 deletions src/analysis/raster/qgsninecellfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@
#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 )
Expand Down
5 changes: 0 additions & 5 deletions src/analysis/raster/qgsrastercalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,8 @@
#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 )
Expand Down
4 changes: 0 additions & 4 deletions src/analysis/raster/qgsrelief.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@
#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 )
Expand Down
4 changes: 0 additions & 4 deletions src/analysis/vector/qgszonalstatistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@
#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 )
Expand Down
5 changes: 0 additions & 5 deletions src/app/dwg/qgsdwgimportdialog.cpp
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
4 changes: 0 additions & 4 deletions src/app/ogr/qgsnewogrconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@
#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 )
Expand Down
2 changes: 0 additions & 2 deletions src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,7 @@
#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
2 changes: 0 additions & 2 deletions src/app/qgsalignrasterdialog.cpp
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
12 changes: 0 additions & 12 deletions src/core/qgsogrutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,9 @@
#include <QTextCodec>
#include <QUuid>

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

QgsFeature QgsOgrUtils::readOgrFeature( OGRFeatureH ogrFet, const QgsFields& fields, QTextCodec* encoding )
{
Expand Down Expand Up @@ -80,15 +74,12 @@ QgsFields QgsOgrUtils::readOgrFields( OGRFeatureH ogrFet, QTextCodec* encoding )
case OFTInteger:
varType = QVariant::Int;
break;
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 2000000
case OFTInteger64:
varType = QVariant::LongLong;
break;
#endif
case OFTReal:
varType = QVariant::Double;
break;
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1400
case OFTDate:
varType = QVariant::Date;
break;
Expand All @@ -99,7 +90,6 @@ QgsFields QgsOgrUtils::readOgrFields( OGRFeatureH ogrFet, QTextCodec* encoding )
varType = QVariant::DateTime;
break;
case OFTString:
#endif
default:
varType = QVariant::String; // other unsupported, leave it as a string
}
Expand Down Expand Up @@ -148,11 +138,9 @@ QVariant QgsOgrUtils::getOgrFeatureAttribute( OGRFeatureH ogrFet, const QgsField
case QVariant::Int:
value = QVariant( OGR_F_GetFieldAsInteger( ogrFet, attIndex ) );
break;
#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 2000000
case QVariant::LongLong:
value = QVariant( OGR_F_GetFieldAsInteger64( ogrFet, attIndex ) );
break;
#endif
case QVariant::Double:
value = QVariant( OGR_F_GetFieldAsDouble( ogrFet, attIndex ) );
break;
Expand Down
Loading

0 comments on commit b0bc763

Please sign in to comment.