Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add support for GDAL 4.0 RFC95 #54680

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2237,6 +2237,10 @@ if (MSVC)
target_compile_definitions(qgis_core PUBLIC _HAS_AUTO_PTR_ETC=1)
endif()

# Add compatibility for deprecated integer data types no longer available
# by default in GDAL 4.0
target_compile_definitions(qgis_core PUBLIC GDAL_USE_OLD_INT_TYPES=1)

target_include_directories(qgis_core SYSTEM PUBLIC
${${QT_VERSION_BASE}Core_INCLUDE_DIRS}
${${QT_VERSION_BASE}Gui_INCLUDE_DIRS}
Expand Down
8 changes: 8 additions & 0 deletions src/core/providers/gdal/qgsgdalprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1911,7 +1911,11 @@ bool QgsGdalProvider::hasHistogram( int bandNo,
double myMinVal, myMaxVal;
int myBinCount;

#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(4,0,0)
uint64_t *myHistogramArray = nullptr;
#else
GUIntBig *myHistogramArray = nullptr;
#endif
CPLErr myError = GDALGetDefaultHistogramEx( myGdalBand, &myMinVal, &myMaxVal,
&myBinCount, &myHistogramArray, false,
nullptr, nullptr );
Expand Down Expand Up @@ -2067,7 +2071,11 @@ QgsRasterHistogram QgsGdalProvider::histogram( int bandNo,
}
#endif

#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(4,0,0)
uint64_t *myHistogramArray = new uint64_t[myHistogram.binCount];
#else
GUIntBig *myHistogramArray = new GUIntBig[myHistogram.binCount];
#endif
CPLErr myError = GDALGetRasterHistogramEx( myGdalBand, myMinVal, myMaxVal,
myHistogram.binCount, myHistogramArray,
includeOutOfRange, bApproxOK, progressCallback,
Expand Down
8 changes: 8 additions & 0 deletions src/core/providers/ogr/qgsogrprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1631,7 +1631,11 @@ bool QgsOgrProvider::addFeaturePrivate( QgsFeature &f, Flags flags, QgsFeatureId
{
const QVariantList list = attrVal.toList();
const int count = list.count();
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(4,0,0)
int64_t *lst = new int64_t[count];
#else
long long *lst = new long long[count];
#endif
if ( count > 0 )
{
int pos = 0;
Expand Down Expand Up @@ -2427,7 +2431,11 @@ bool QgsOgrProvider::changeAttributeValues( const QgsChangedAttributesMap &attr_
{
const QVariantList list = it2->toList();
const int count = list.count();
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(4,0,0)
int64_t *lst = new int64_t[count];
#else
long long *lst = new long long[count];
#endif
if ( count > 0 )
{
int pos = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/core/providers/ogr/qgsogrproviderconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ QVariantList QgsOgrProviderResultIterator::nextRowInternal()
// PK
if ( ! mPrimaryKeyColumnName.isEmpty() )
{
row.push_back( OGR_F_GetFID( fet.get() ) );
row.push_back( static_cast<qint64>( OGR_F_GetFID( fet.get() ) ) );
}

if ( ! mFields.isEmpty() )
Expand Down
10 changes: 5 additions & 5 deletions src/core/qgsogrutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ QVariant QgsOgrUtils::OGRFieldtoVariant( const OGRField *value, OGRFieldType typ
return value->Integer;

case OFTInteger64:
return value->Integer64;
return static_cast<qint64>( value->Integer64 );

case OFTReal:
return value->Real;
Expand Down Expand Up @@ -200,7 +200,7 @@ QVariant QgsOgrUtils::OGRFieldtoVariant( const OGRField *value, OGRFieldType typ
QVariantList res;
res.reserve( value->Integer64List.nCount );
for ( int i = 0; i < value->Integer64List.nCount; ++i )
res << value->Integer64List.paList[ i ];
res << static_cast<qint64>( value->Integer64List.paList[ i ] );
return res;
}

Expand Down Expand Up @@ -568,7 +568,7 @@ QVariant QgsOgrUtils::getOgrFeatureAttribute( OGRFeatureH ogrFet, const QgsField
value = QVariant( bool( OGR_F_GetFieldAsInteger( ogrFet, attIndex ) ) );
break;
case QVariant::LongLong:
value = QVariant( OGR_F_GetFieldAsInteger64( ogrFet, attIndex ) );
value = QVariant( static_cast<qint64>( OGR_F_GetFieldAsInteger64( ogrFet, attIndex ) ) );
break;
case QVariant::Double:
value = QVariant( OGR_F_GetFieldAsDouble( ogrFet, attIndex ) );
Expand Down Expand Up @@ -694,13 +694,13 @@ QVariant QgsOgrUtils::getOgrFeatureAttribute( OGRFeatureH ogrFet, const QgsField
{
QVariantList list;
int count = 0;
const long long *lst = OGR_F_GetFieldAsInteger64List( ogrFet, attIndex, &count );
const auto *lst = OGR_F_GetFieldAsInteger64List( ogrFet, attIndex, &count );
if ( count > 0 )
{
list.reserve( count );
for ( int i = 0; i < count; i++ )
{
list << lst[i];
list << static_cast<qint64>( lst[i] );
}
}
value = list;
Expand Down
4 changes: 4 additions & 0 deletions src/core/qgsvectorfilewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2970,7 +2970,11 @@ gdal::ogr_feature_unique_ptr QgsVectorFileWriter::createFeature( const QgsFeatur
if ( mSupportedListSubTypes.contains( QVariant::LongLong ) )
{
const int count = list.count();
#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(4,0,0)
int64_t *lst = new int64_t[count];
#else
long long *lst = new long long[count];
#endif
if ( count > 0 )
{
int pos = 0;
Expand Down
Loading