Skip to content
Permalink
Browse files
Merge pull request #43370 from rouault/cleanup_deprecated_gdal_stuff
Cleanup relative to GDAL version checking
  • Loading branch information
rouault committed May 24, 2021
2 parents ffc500d + 11e2ba8 commit 2fdb4a81153458dad94661e6978c6202c9622cfe
Showing with 11 additions and 31 deletions.
  1. +2 −4 src/core/providers/ogr/qgsogrprovider.cpp
  2. +9 −27 src/core/qgsvectorfilewriter.cpp
@@ -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;
}
@@ -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;
@@ -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 )
{
@@ -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();
@@ -1018,6 +999,7 @@ class QgsVectorFileWriterMetadataContainer
layerOptions
)
);
#endif

// Comma Separated Value
datasetOptions.clear();
@@ -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 );
@@ -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;

@@ -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() );

0 comments on commit 2fdb4a8

Please sign in to comment.