Skip to content

Commit

Permalink
Bump minimum GDAL version to 3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 30, 2022
1 parent 01905bf commit c517d80
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 377 deletions.
2 changes: 1 addition & 1 deletion INSTALL.md
Expand Up @@ -105,7 +105,7 @@ Required build dependencies:
* Sqlite3 >= 3.0.0
* SpatiaLite >= 4.2.0
* libspatialindex
* GDAL/OGR >= 3.0.0
* GDAL/OGR >= 3.2.0
* Qwt >= 5.0 & (< 6.1 with internal QwtPolar)
* expat >= 1.95
* QScintilla2
Expand Down
8 changes: 4 additions & 4 deletions cmake/FindGDAL.cmake
Expand Up @@ -64,11 +64,11 @@ ELSE(WIN32)
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 3)
MESSAGE (FATAL_ERROR "GDAL version is too old (${GDAL_VERSION}). Use 3.0 or higher.")
MESSAGE (FATAL_ERROR "GDAL version is too old (${GDAL_VERSION}). Use 3.2 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 LESS 2) )
MESSAGE (FATAL_ERROR "GDAL version is too old (${GDAL_VERSION}). Use 3.2 or higher.")
ENDIF( (GDAL_VERSION_MAJOR EQUAL 3) AND (GDAL_VERSION_MINOR LESS 2) )

ENDIF (GDAL_LIBRARY)
SET (CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK_save} CACHE STRING "" FORCE)
Expand Down
8 changes: 0 additions & 8 deletions src/core/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -773,13 +773,11 @@ void QgsOgrProvider::loadFields()
width, prec, QString(), varSubType
);

#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,2,0)
const QString alias = textEncoding()->toUnicode( OGR_Fld_GetAlternativeNameRef( fldDef ) );
if ( !alias.isEmpty() )
{
newField.setAlias( alias );
}
#endif

// check if field is nullable
bool nullable = OGR_Fld_IsNullable( fldDef );
Expand Down Expand Up @@ -3563,14 +3561,12 @@ void QgsOgrProvider::open( OpenMode mode )
}

QStringList options( mOpenOptions );
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,1,0)
// assume trusted data to get more speed
if ( mGDALDriverName == QLatin1String( "FlatGeobuf" ) &&
!options.contains( QStringLiteral( "VERIFY_BUFFERS=YES" ) ) )
{
options << QStringLiteral( "VERIFY_BUFFERS=NO" );
}
#endif

// try to open read-only
if ( !mLayerName.isNull() )
Expand Down Expand Up @@ -3598,13 +3594,9 @@ void QgsOgrProvider::open( OpenMode mode )
{
// determine encoding from shapefile cpg or LDID information, if possible
QString shpEncoding;
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,1,0)
shpEncoding = mOgrLayer->GetMetadataItem( QStringLiteral( "ENCODING_FROM_CPG" ), QStringLiteral( "SHAPEFILE" ) );
if ( shpEncoding.isEmpty() )
shpEncoding = mOgrLayer->GetMetadataItem( QStringLiteral( "ENCODING_FROM_LDID" ), QStringLiteral( "SHAPEFILE" ) );
#else
shpEncoding = QgsOgrUtils::readShapefileEncoding( mFilePath );
#endif

if ( !shpEncoding.isEmpty() )
setEncoding( shpEncoding );
Expand Down
33 changes: 1 addition & 32 deletions src/core/providers/ogr/qgsogrproviderutils.cpp
Expand Up @@ -269,14 +269,12 @@ QString createFilters( const QString &type )
if ( !sDirectoryExtensions.contains( QStringLiteral( "gdb" ) ) )
sDirectoryExtensions << QStringLiteral( "gdb" );
}
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,1,0)
else if ( driverName.startsWith( QLatin1String( "FlatGeobuf" ) ) )
{
sProtocolDrivers += QLatin1String( "FlatGeobuf;" );
sFileFilters += createFileFilter_( QObject::tr( "FlatGeobuf" ), QStringLiteral( "*.fgb" ) );
sExtensions << QStringLiteral( "fgb" );
}
#endif
else if ( driverName.startsWith( QLatin1String( "PGeo" ) ) )
{
sDatabaseDrivers += QObject::tr( "ESRI Personal GeoDatabase" ) + ",PGeo;";
Expand Down Expand Up @@ -1286,18 +1284,6 @@ void QgsOgrProviderUtils::GDALCloseWrapper( GDALDatasetH hDS )
GDALClose( hDS );
}
}

#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,1,0) && GDAL_VERSION_NUM <= GDAL_COMPUTE_VERSION(3,1,3)
else if ( mGDALDriverName == QLatin1String( "XLSX" ) ||
mGDALDriverName == QLatin1String( "ODS" ) )
{
// Workaround bug in GDAL 3.1.0 to 3.1.3 that creates XLSX and ODS files incompatible with LibreOffice due to use of ZIP64
CPLSetThreadLocalConfigOption( "CPL_CREATE_ZIP64", "NO" );
GDALClose( hDS );
CPLSetThreadLocalConfigOption( "CPL_CREATE_ZIP64", nullptr );
}
#endif

else
{
GDALClose( hDS );
Expand Down Expand Up @@ -3088,24 +3074,7 @@ OGRErr QgsOgrLayer::SyncToDisk()
{
QMutexLocker locker( &ds->mutex );

OGRErr eErr;
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(3,1,0) && GDAL_VERSION_NUM <= GDAL_COMPUTE_VERSION(3,1,3)
// Workaround bug in GDAL 3.1.0 to 3.1.3 that creates XLSX and ODS files incompatible with LibreOffice due to use of ZIP64
QString drvName = GDALGetDriverShortName( GDALGetDatasetDriver( ds->hDS ) );
if ( drvName == QLatin1String( "XLSX" ) ||
drvName == QLatin1String( "ODS" ) )
{
CPLSetThreadLocalConfigOption( "CPL_CREATE_ZIP64", "NO" );
eErr = OGR_L_SyncToDisk( hLayer );
CPLSetThreadLocalConfigOption( "CPL_CREATE_ZIP64", nullptr );
}
else
#endif
{
eErr = OGR_L_SyncToDisk( hLayer );
}

return eErr;
return OGR_L_SyncToDisk( hLayer );
}

void QgsOgrLayer::ExecuteSQLNoReturn( const QByteArray &sql )
Expand Down
18 changes: 0 additions & 18 deletions src/core/qgscplhttpfetchoverrider.cpp
Expand Up @@ -20,22 +20,6 @@
#include "cpl_http.h"
#include "gdal.h"

#if GDAL_VERSION_NUM < GDAL_COMPUTE_VERSION(3,2,0)

QgsCPLHTTPFetchOverrider::QgsCPLHTTPFetchOverrider( const QString &authCfg, QgsFeedback *feedback )
{
Q_UNUSED( authCfg );
Q_UNUSED( feedback );
Q_UNUSED( mAuthCfg );
Q_UNUSED( mFeedback );
}

QgsCPLHTTPFetchOverrider::~QgsCPLHTTPFetchOverrider()
{
}

#else

QgsCPLHTTPFetchOverrider::QgsCPLHTTPFetchOverrider( const QString &authCfg, QgsFeedback *feedback ):
mAuthCfg( authCfg ),
mFeedback( feedback )
Expand Down Expand Up @@ -200,8 +184,6 @@ CPLHTTPResult *QgsCPLHTTPFetchOverrider::callback( const char *pszURL,
return psResult;
}

#endif

void QgsCPLHTTPFetchOverrider::setAttribute( QNetworkRequest::Attribute code, const QVariant &value )
{
mAttributes[code] = value;
Expand Down
142 changes: 0 additions & 142 deletions src/core/qgsgdalutils.cpp
Expand Up @@ -328,148 +328,6 @@ QString QgsGdalUtils::validateCreationOptionsFormat( const QStringList &createOp
return QString();
}

#if GDAL_VERSION_NUM < GDAL_COMPUTE_VERSION(3,2,0)

GDALDatasetH GDALAutoCreateWarpedVRTEx( GDALDatasetH hSrcDS, const char *pszSrcWKT, const char *pszDstWKT, GDALResampleAlg eResampleAlg,
double dfMaxError, const GDALWarpOptions *psOptionsIn, char **papszTransformerOptions )
{
VALIDATE_POINTER1( hSrcDS, "GDALAutoCreateWarpedVRT", nullptr );

/* -------------------------------------------------------------------- */
/* Populate the warp options. */
/* -------------------------------------------------------------------- */
GDALWarpOptions *psWO = nullptr;
if ( psOptionsIn != nullptr )
psWO = GDALCloneWarpOptions( psOptionsIn );
else
psWO = GDALCreateWarpOptions();

psWO->eResampleAlg = eResampleAlg;

psWO->hSrcDS = hSrcDS;

GDALWarpInitDefaultBandMapping( psWO, GDALGetRasterCount( hSrcDS ) );

/* -------------------------------------------------------------------- */
/* Setup no data values */
/* -------------------------------------------------------------------- */
for ( int i = 0; i < psWO->nBandCount; i++ )
{
GDALRasterBandH rasterBand = GDALGetRasterBand( psWO->hSrcDS, psWO->panSrcBands[i] );

int hasNoDataValue;
double noDataValue = GDALGetRasterNoDataValue( rasterBand, &hasNoDataValue );

if ( hasNoDataValue )
{
// Check if the nodata value is out of range
int bClamped = FALSE;
int bRounded = FALSE;
CPL_IGNORE_RET_VAL(
GDALAdjustValueToDataType( GDALGetRasterDataType( rasterBand ),
noDataValue, &bClamped, &bRounded ) );
if ( !bClamped )
{
GDALWarpInitNoDataReal( psWO, -1e10 );

psWO->padfSrcNoDataReal[i] = noDataValue;
psWO->padfDstNoDataReal[i] = noDataValue;
}
}
}

if ( psWO->padfDstNoDataReal != nullptr )
{
if ( CSLFetchNameValue( psWO->papszWarpOptions, "INIT_DEST" ) == nullptr )
{
psWO->papszWarpOptions =
CSLSetNameValue( psWO->papszWarpOptions, "INIT_DEST", "NO_DATA" );
}
}

/* -------------------------------------------------------------------- */
/* Create the transformer. */
/* -------------------------------------------------------------------- */
psWO->pfnTransformer = GDALGenImgProjTransform;

char **papszOptions = nullptr;
if ( pszSrcWKT != nullptr )
papszOptions = CSLSetNameValue( papszOptions, "SRC_SRS", pszSrcWKT );
if ( pszDstWKT != nullptr )
papszOptions = CSLSetNameValue( papszOptions, "DST_SRS", pszDstWKT );
papszOptions = CSLMerge( papszOptions, papszTransformerOptions );
psWO->pTransformerArg =
GDALCreateGenImgProjTransformer2( psWO->hSrcDS, nullptr,
papszOptions );
CSLDestroy( papszOptions );

if ( psWO->pTransformerArg == nullptr )
{
GDALDestroyWarpOptions( psWO );
return nullptr;
}

/* -------------------------------------------------------------------- */
/* Figure out the desired output bounds and resolution. */
/* -------------------------------------------------------------------- */
double adfDstGeoTransform[6] = { 0.0 };
int nDstPixels = 0;
int nDstLines = 0;
CPLErr eErr =
GDALSuggestedWarpOutput( hSrcDS, psWO->pfnTransformer,
psWO->pTransformerArg,
adfDstGeoTransform, &nDstPixels, &nDstLines );
if ( eErr != CE_None )
{
GDALDestroyTransformer( psWO->pTransformerArg );
GDALDestroyWarpOptions( psWO );
return nullptr;
}

/* -------------------------------------------------------------------- */
/* Update the transformer to include an output geotransform */
/* back to pixel/line coordinates. */
/* */
/* -------------------------------------------------------------------- */
GDALSetGenImgProjTransformerDstGeoTransform(
psWO->pTransformerArg, adfDstGeoTransform );

/* -------------------------------------------------------------------- */
/* Do we want to apply an approximating transformation? */
/* -------------------------------------------------------------------- */
if ( dfMaxError > 0.0 )
{
psWO->pTransformerArg =
GDALCreateApproxTransformer( psWO->pfnTransformer,
psWO->pTransformerArg,
dfMaxError );
psWO->pfnTransformer = GDALApproxTransform;
GDALApproxTransformerOwnsSubtransformer( psWO->pTransformerArg, TRUE );
}

/* -------------------------------------------------------------------- */
/* Create the VRT file. */
/* -------------------------------------------------------------------- */
GDALDatasetH hDstDS
= GDALCreateWarpedVRT( hSrcDS, nDstPixels, nDstLines,
adfDstGeoTransform, psWO );

GDALDestroyWarpOptions( psWO );

if ( pszDstWKT != nullptr )
GDALSetProjection( hDstDS, pszDstWKT );
else if ( pszSrcWKT != nullptr )
GDALSetProjection( hDstDS, pszSrcWKT );
else if ( GDALGetGCPCount( hSrcDS ) > 0 )
GDALSetProjection( hDstDS, GDALGetGCPProjection( hSrcDS ) );
else
GDALSetProjection( hDstDS, GDALGetProjectionRef( hSrcDS ) );

return hDstDS;
}
#endif


GDALDatasetH QgsGdalUtils::rpcAwareAutoCreateWarpedVrt(
GDALDatasetH hSrcDS,
const char *pszSrcWKT,
Expand Down

0 comments on commit c517d80

Please sign in to comment.