Skip to content

Commit

Permalink
Require GDAL 3.0+
Browse files Browse the repository at this point in the history
Drop compatibility with GDAL v2
  • Loading branch information
nyalldawson committed Feb 23, 2021
1 parent e11801d commit af69dc7
Show file tree
Hide file tree
Showing 25 changed files with 44 additions and 454 deletions.
24 changes: 12 additions & 12 deletions cmake/FindGDAL.cmake
Expand Up @@ -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)
Expand Down Expand Up @@ -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) )
Expand Down
46 changes: 0 additions & 46 deletions src/core/providers/gdal/qgsgdalprovider.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -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 ) )
{
Expand All @@ -3052,11 +3011,6 @@ void QgsGdalProvider::initBaseDataset()
}
else
{
#else
if ( !crsFromWkt( GDALGetProjectionRef( mGdalDataset ) ) &&
!crsFromWkt( GDALGetGCPProjection( mGdalDataset ) ) )
{
#endif
if ( mGdalBaseDataset != mGdalDataset &&
GDALGetMetadata( mGdalBaseDataset, "RPC" ) )
{
Expand Down
5 changes: 0 additions & 5 deletions src/core/providers/gdal/qgsgdalprovider.h
Expand Up @@ -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();

Expand Down
6 changes: 2 additions & 4 deletions src/core/providers/ogr/qgsgeopackageproviderconnection.cpp
Expand Up @@ -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,
Expand Down
7 changes: 0 additions & 7 deletions src/core/providers/ogr/qgsogrfeatureiterator.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -306,7 +305,6 @@ bool QgsOgrFeatureIterator::fetchFeatureWithId( QgsFeatureId id, QgsFeature &fea
}
}
else
#endif
{
fet.reset( OGR_L_GetFeature( mOgrLayer, FID_TO_NUMBER( id ) ) );
}
Expand Down Expand Up @@ -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;
Expand All @@ -393,7 +389,6 @@ bool QgsOgrFeatureIterator::fetchFeature( QgsFeature &feature )
}
}
else
#endif
{

while ( fet.reset( OGR_L_GetNextFeature( mOgrLayer ) ), fet )
Expand All @@ -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 );
}
Expand Down

0 comments on commit af69dc7

Please sign in to comment.