Skip to content
Permalink
Browse files

Require GDAL 3.0+

Drop compatibility with GDAL v2
  • Loading branch information
nyalldawson committed Feb 23, 2021
1 parent e11801d commit af69dc7c0b5df3e6ba0fb968cf0fc9b12b5a8618
@@ -63,12 +63,12 @@ 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 2)
MESSAGE (FATAL_ERROR "GDAL version is too old (${GDAL_VERSION}). Use 2.1 or higher.")
ENDIF (GDAL_VERSION_MAJOR LESS 2)
IF ( (GDAL_VERSION_MAJOR EQUAL 2) AND (GDAL_VERSION_MINOR LESS 1) )
MESSAGE (FATAL_ERROR "GDAL version is too old (${GDAL_VERSION}). Use 2.1 or higher.")
ENDIF( (GDAL_VERSION_MAJOR EQUAL 2) AND (GDAL_VERSION_MINOR LESS 1) )
IF (GDAL_VERSION_MAJOR LESS 3)
MESSAGE (FATAL_ERROR "GDAL version is too old (${GDAL_VERSION}). Use 3.0 or higher.")
ENDIF (GDAL_VERSION_MAJOR LESS 3)
#IF ( (GDAL_VERSION_MAJOR EQUAL 2) AND (GDAL_VERSION_MINOR LESS 1) )
# MESSAGE (FATAL_ERROR "GDAL version is too old (${GDAL_VERSION}). Use 2.1 or higher.")
#ENDIF( (GDAL_VERSION_MAJOR EQUAL 2) AND (GDAL_VERSION_MINOR LESS 1) )

ENDIF (GDAL_LIBRARY)
SET (CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK_save} CACHE STRING "" FORCE)
@@ -109,12 +109,12 @@ ELSE(WIN32)
# check for gdal version
# version 1.2.5 is known NOT to be supported (missing CPL_STDCALL macro)
# According to INSTALL, 2.1+ is required
IF (GDAL_VERSION_MAJOR LESS 2)
MESSAGE (FATAL_ERROR "GDAL version is too old (${GDAL_VERSION}). Use 2.1 or higher.")
ENDIF (GDAL_VERSION_MAJOR LESS 2)
IF ( (GDAL_VERSION_MAJOR EQUAL 2) AND (GDAL_VERSION_MINOR LESS 1) )
MESSAGE (FATAL_ERROR "GDAL version is too old (${GDAL_VERSION}). Use 2.1 or higher.")
ENDIF( (GDAL_VERSION_MAJOR EQUAL 2) AND (GDAL_VERSION_MINOR LESS 1) )
IF (GDAL_VERSION_MAJOR LESS 3)
MESSAGE (FATAL_ERROR "GDAL version is too old (${GDAL_VERSION}). Use 3.0 or higher.")
ENDIF (GDAL_VERSION_MAJOR LESS 3)
#IF ( (GDAL_VERSION_MAJOR EQUAL 2) AND (GDAL_VERSION_MINOR LESS 1) )
# MESSAGE (FATAL_ERROR "GDAL version is too old (${GDAL_VERSION}). Use 2.1 or higher.")
#ENDIF( (GDAL_VERSION_MAJOR EQUAL 2) AND (GDAL_VERSION_MINOR LESS 1) )
IF ( (GDAL_VERSION_MAJOR EQUAL 3) AND (GDAL_VERSION_MINOR EQUAL 0) AND (GDAL_VERSION_MICRO LESS 3) )
MESSAGE (FATAL_ERROR "GDAL version is too old (${GDAL_VERSION}). Use 3.0.3 or higher.")
ENDIF( (GDAL_VERSION_MAJOR EQUAL 3) AND (GDAL_VERSION_MINOR EQUAL 0) AND (GDAL_VERSION_MICRO LESS 3) )
@@ -303,46 +303,6 @@ QgsGdalProvider *QgsGdalProvider::clone() const
return new QgsGdalProvider( *this );
}

#if GDAL_VERSION_NUM < GDAL_COMPUTE_VERSION(3,0,0)
bool QgsGdalProvider::crsFromWkt( const char *wkt )
{

OGRSpatialReferenceH hCRS = OSRNewSpatialReference( nullptr );

if ( OSRImportFromWkt( hCRS, ( char ** ) &wkt ) == OGRERR_NONE )
{
if ( OSRAutoIdentifyEPSG( hCRS ) == OGRERR_NONE )
{
QString authid = QStringLiteral( "%1:%2" )
.arg( OSRGetAuthorityName( hCRS, nullptr ),
OSRGetAuthorityCode( hCRS, nullptr ) );
QgsDebugMsgLevel( "authid recognized as " + authid, 2 );
mCrs = QgsCoordinateReferenceSystem::fromOgcWmsCrs( authid );
}
else
{
// get the proj4 text
char *pszProj4 = nullptr;
OSRExportToProj4( hCRS, &pszProj4 );
QgsDebugMsgLevel( pszProj4, 2 );
CPLFree( pszProj4 );

char *pszWkt = nullptr;
OSRExportToWkt( hCRS, &pszWkt );
QString myWktString = QString( pszWkt );
CPLFree( pszWkt );

// create CRS from Wkt
mCrs = QgsCoordinateReferenceSystem::fromWkt( myWktString );
}
}

OSRRelease( hCRS );

return mCrs.isValid();
}
#endif

bool QgsGdalProvider::getCachedGdalHandles( QgsGdalProvider *provider,
GDALDatasetH &gdalBaseDataset,
GDALDatasetH &gdalDataset )
@@ -3033,7 +2993,6 @@ void QgsGdalProvider::initBaseDataset()
// Get the layer's projection info and set up the
// QgsCoordinateTransform for this layer
// NOTE: we must do this before metadata is called
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,0,0)
QString crsWkt;
if ( OGRSpatialReferenceH spatialRefSys = GDALGetSpatialRef( mGdalDataset ) )
{
@@ -3052,11 +3011,6 @@ void QgsGdalProvider::initBaseDataset()
}
else
{
#else
if ( !crsFromWkt( GDALGetProjectionRef( mGdalDataset ) ) &&
!crsFromWkt( GDALGetGCPProjection( mGdalDataset ) ) )
{
#endif
if ( mGdalBaseDataset != mGdalDataset &&
GDALGetMetadata( mGdalBaseDataset, "RPC" ) )
{
@@ -246,11 +246,6 @@ class QgsGdalProvider final: public QgsRasterDataProvider, QgsGdalProviderBase
// update mode
bool mUpdate;

#if GDAL_VERSION_NUM < GDAL_COMPUTE_VERSION(3,0,0)
// initialize CRS from wkt
bool crsFromWkt( const char *wkt );
#endif

//! Do some initialization on the dataset (e.g. handling of south-up datasets)
void initBaseDataset();

@@ -352,11 +352,9 @@ void QgsGeoPackageProviderConnection::setDefaultCapabilities()
Capability::SpatialIndexExists,
Capability::DeleteSpatialIndex,
Capability::DeleteField,
Capability::AddField
Capability::AddField,
Capability::DropRasterTable
};
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,4,0)
mCapabilities |= Capability::DropRasterTable;
#endif
mGeometryColumnCapabilities =
{
GeometryColumnCapability::Z,
@@ -270,7 +270,6 @@ bool QgsOgrFeatureIterator::fetchFeatureWithId( QgsFeatureId id, QgsFeature &fea
feature.setValid( false );
gdal::ogr_feature_unique_ptr fet;

#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,2,0)
if ( mAllowResetReading && !QgsOgrProviderUtils::canDriverShareSameDatasetAmongLayers( mSource->mDriverName ) )
{
OGRLayerH nextFeatureBelongingLayer;
@@ -306,7 +305,6 @@ bool QgsOgrFeatureIterator::fetchFeatureWithId( QgsFeatureId id, QgsFeature &fea
}
}
else
#endif
{
fet.reset( OGR_L_GetFeature( mOgrLayer, FID_TO_NUMBER( id ) ) );
}
@@ -379,8 +377,6 @@ bool QgsOgrFeatureIterator::fetchFeature( QgsFeature &feature )

// OSM layers (especially large ones) need the GDALDataset::GetNextFeature() call rather than OGRLayer::GetNextFeature()
// see more details here: https://trac.osgeo.org/gdal/wiki/rfc66_randomlayerreadwrite

#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,2,0)
if ( !QgsOgrProviderUtils::canDriverShareSameDatasetAmongLayers( mSource->mDriverName ) )
{
OGRLayerH nextFeatureBelongingLayer;
@@ -393,7 +389,6 @@ bool QgsOgrFeatureIterator::fetchFeature( QgsFeature &feature )
}
}
else
#endif
{

while ( fet.reset( OGR_L_GetNextFeature( mOgrLayer ) ), fet )
@@ -415,13 +410,11 @@ void QgsOgrFeatureIterator::resetReading()
{
return;
}
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(2,2,0)
if ( !QgsOgrProviderUtils::canDriverShareSameDatasetAmongLayers( mSource->mDriverName ) )
{
GDALDatasetResetReading( mConn->ds );
}
else
#endif
{
OGR_L_ResetReading( mOgrLayer );
}

0 comments on commit af69dc7

Please sign in to comment.