Skip to content

Commit

Permalink
Merge pull request #43370 from rouault/cleanup_deprecated_gdal_stuff
Browse files Browse the repository at this point in the history
Cleanup relative to GDAL version checking
  • Loading branch information
rouault committed May 24, 2021
2 parents ffc500d + 11e2ba8 commit 2fdb4a8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 31 deletions.
6 changes: 2 additions & 4 deletions src/core/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -5348,11 +5348,9 @@ void QgsOgrProvider::open( OpenMode mode )
mValid = false;

// In the case where we deal with a shapefile, it is possible that it has
// pre-existing holes in the DBF (see #15407), so if using a GDAL version
// recent enough to have reliable packing, do a packing at the first edit
// pre-existing holes in the DBF (see #15407), so do a packing at the first edit
// action.
if ( mGDALDriverName == QLatin1String( "ESRI Shapefile" ) &&
atoi( GDALVersionInfo( "VERSION_NUM" ) ) >= GDAL_COMPUTE_VERSION( 2, 1, 2 ) )
if ( mGDALDriverName == QLatin1String( "ESRI Shapefile" ) )
{
mShapefileMayBeCorrupted = true;
}
Expand Down
36 changes: 9 additions & 27 deletions src/core/qgsvectorfilewriter.cpp
Expand Up @@ -58,29 +58,6 @@
#include <cpl_string.h>
#include <gdal.h>

// Thin wrapper around OGROpen() to workaround a bug in GDAL < 2.3.1
// where a existing BNA file is wrongly reported to be openable in update mode
// but attempting to add features in it crashes the BNA driver.
static OGRDataSourceH myOGROpen( const char *pszName, int bUpdate, OGRSFDriverH *phDriver )
{
OGRSFDriverH hDriver = nullptr;
OGRDataSourceH hDS = OGROpen( pszName, bUpdate, &hDriver );
if ( hDS && bUpdate )
{
QString drvName = OGR_Dr_GetName( hDriver );
if ( drvName == QLatin1String( "BNA" ) )
{
OGR_DS_Destroy( hDS );
if ( phDriver )
*phDriver = nullptr;
return nullptr;
}
}
if ( phDriver )
*phDriver = hDriver;
return hDS;
}

QgsField QgsVectorFileWriter::FieldValueConverter::fieldDefinition( const QgsField &field )
{
return field;
Expand Down Expand Up @@ -369,7 +346,7 @@ void QgsVectorFileWriter::init( QString vectorFileName,
if ( action == CreateOrOverwriteFile )
mDS.reset( OGR_Dr_CreateDataSource( poDriver, vectorFileName.toUtf8().constData(), options ) );
else
mDS.reset( myOGROpen( vectorFileName.toUtf8().constData(), TRUE, nullptr ) );
mDS.reset( OGROpen( vectorFileName.toUtf8().constData(), TRUE, nullptr ) );

if ( options )
{
Expand Down Expand Up @@ -954,6 +931,10 @@ class QgsVectorFileWriterMetadataContainer
)
);


#if GDAL_VERSION_NUM < GDAL_COMPUTE_VERSION(3,3,0)
// Support for Atlas BNA was removed in GDAL 3.3

// Atlas BNA
datasetOptions.clear();
layerOptions.clear();
Expand Down Expand Up @@ -1018,6 +999,7 @@ class QgsVectorFileWriterMetadataContainer
layerOptions
)
);
#endif

// Comma Separated Value
datasetOptions.clear();
Expand Down Expand Up @@ -4104,7 +4086,7 @@ QStringList QgsVectorFileWriter::concatenateOptions( const QMap<QString, QgsVect
QgsVectorFileWriter::EditionCapabilities QgsVectorFileWriter::editionCapabilities( const QString &datasetName )
{
OGRSFDriverH hDriver = nullptr;
gdal::ogr_datasource_unique_ptr hDS( myOGROpen( datasetName.toUtf8().constData(), TRUE, &hDriver ) );
gdal::ogr_datasource_unique_ptr hDS( OGROpen( datasetName.toUtf8().constData(), TRUE, &hDriver ) );
if ( !hDS )
return QgsVectorFileWriter::EditionCapabilities();
QString drvName = OGR_Dr_GetName( hDriver );
Expand Down Expand Up @@ -4144,7 +4126,7 @@ bool QgsVectorFileWriter::targetLayerExists( const QString &datasetName,
const QString &layerNameIn )
{
OGRSFDriverH hDriver = nullptr;
gdal::ogr_datasource_unique_ptr hDS( myOGROpen( datasetName.toUtf8().constData(), TRUE, &hDriver ) );
gdal::ogr_datasource_unique_ptr hDS( OGROpen( datasetName.toUtf8().constData(), TRUE, &hDriver ) );
if ( !hDS )
return false;

Expand All @@ -4162,7 +4144,7 @@ bool QgsVectorFileWriter::areThereNewFieldsToCreate( const QString &datasetName,
const QgsAttributeList &attributes )
{
OGRSFDriverH hDriver = nullptr;
gdal::ogr_datasource_unique_ptr hDS( myOGROpen( datasetName.toUtf8().constData(), TRUE, &hDriver ) );
gdal::ogr_datasource_unique_ptr hDS( OGROpen( datasetName.toUtf8().constData(), TRUE, &hDriver ) );
if ( !hDS )
return false;
OGRLayerH hLayer = OGR_DS_GetLayerByName( hDS.get(), layerName.toUtf8().constData() );
Expand Down

0 comments on commit 2fdb4a8

Please sign in to comment.