|
@@ -16,8 +16,8 @@ |
|
|
* * |
|
|
***************************************************************************/ |
|
|
|
|
|
|
|
|
#include "qgslogger.h" |
|
|
#include "qgsgdalproviderbase.h" |
|
|
#include "qgsgdalprovider.h" |
|
|
#include "qgsconfig.h" |
|
|
|
|
@@ -91,6 +91,7 @@ int CPL_STDCALL progressCallback( double dfComplete, |
|
|
|
|
|
QgsGdalProvider::QgsGdalProvider( QString const & uri ) |
|
|
: QgsRasterDataProvider( uri ) |
|
|
, QgsGdalProviderBase() |
|
|
, mValid( true ) |
|
|
{ |
|
|
QgsDebugMsg( "QgsGdalProvider: constructing with uri '" + uri + "'." ); |
|
@@ -99,7 +100,7 @@ QgsGdalProvider::QgsGdalProvider( QString const & uri ) |
|
|
mGdalBaseDataset = 0; |
|
|
mGdalDataset = 0; |
|
|
|
|
|
registerGdalDrivers(); |
|
|
QgsGdalProviderBase::registerGdalDrivers(); |
|
|
|
|
|
// To get buildSupportedRasterFileFilter the provider is called with empty uri |
|
|
if ( uri.isEmpty() ) |
|
@@ -942,88 +943,7 @@ double QgsGdalProvider::maximumValue( int theBandNo ) const |
|
|
QList<QgsColorRampShader::ColorRampItem> QgsGdalProvider::colorTable( int theBandNumber )const |
|
|
{ |
|
|
QgsDebugMsg( "entered." ); |
|
|
QList<QgsColorRampShader::ColorRampItem> ct; |
|
|
|
|
|
|
|
|
//Invalid band number, segfault prevention |
|
|
if ( 0 >= theBandNumber ) |
|
|
{ |
|
|
QgsDebugMsg( "Invalid parameter" ); |
|
|
return ct; |
|
|
} |
|
|
|
|
|
GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, theBandNumber ); |
|
|
GDALColorTableH myGdalColorTable = GDALGetRasterColorTable( myGdalBand ); |
|
|
|
|
|
if ( myGdalColorTable ) |
|
|
{ |
|
|
QgsDebugMsg( "Color table found" ); |
|
|
int myEntryCount = GDALGetColorEntryCount( myGdalColorTable ); |
|
|
GDALColorInterp myColorInterpretation = GDALGetRasterColorInterpretation( myGdalBand ); |
|
|
QgsDebugMsg( "Color Interpretation: " + QString::number(( int )myColorInterpretation ) ); |
|
|
GDALPaletteInterp myPaletteInterpretation = GDALGetPaletteInterpretation( myGdalColorTable ); |
|
|
QgsDebugMsg( "Palette Interpretation: " + QString::number(( int )myPaletteInterpretation ) ); |
|
|
|
|
|
const GDALColorEntry* myColorEntry = 0; |
|
|
for ( int myIterator = 0; myIterator < myEntryCount; myIterator++ ) |
|
|
{ |
|
|
myColorEntry = GDALGetColorEntry( myGdalColorTable, myIterator ); |
|
|
|
|
|
if ( !myColorEntry ) |
|
|
{ |
|
|
continue; |
|
|
} |
|
|
else |
|
|
{ |
|
|
//Branch on the color interpretation type |
|
|
if ( myColorInterpretation == GCI_GrayIndex ) |
|
|
{ |
|
|
QgsColorRampShader::ColorRampItem myColorRampItem; |
|
|
myColorRampItem.label = ""; |
|
|
myColorRampItem.value = ( double )myIterator; |
|
|
myColorRampItem.color = QColor::fromRgb( myColorEntry->c1, myColorEntry->c1, myColorEntry->c1, myColorEntry->c4 ); |
|
|
ct.append( myColorRampItem ); |
|
|
} |
|
|
else if ( myColorInterpretation == GCI_PaletteIndex ) |
|
|
{ |
|
|
QgsColorRampShader::ColorRampItem myColorRampItem; |
|
|
myColorRampItem.value = ( double )myIterator; |
|
|
myColorRampItem.label = QString::number( myColorRampItem.value ); |
|
|
//Branch on palette interpretation |
|
|
if ( myPaletteInterpretation == GPI_RGB ) |
|
|
{ |
|
|
myColorRampItem.color = QColor::fromRgb( myColorEntry->c1, myColorEntry->c2, myColorEntry->c3, myColorEntry->c4 ); |
|
|
} |
|
|
else if ( myPaletteInterpretation == GPI_CMYK ) |
|
|
{ |
|
|
myColorRampItem.color = QColor::fromCmyk( myColorEntry->c1, myColorEntry->c2, myColorEntry->c3, myColorEntry->c4 ); |
|
|
} |
|
|
else if ( myPaletteInterpretation == GPI_HLS ) |
|
|
{ |
|
|
myColorRampItem.color = QColor::fromHsv( myColorEntry->c1, myColorEntry->c3, myColorEntry->c2, myColorEntry->c4 ); |
|
|
} |
|
|
else |
|
|
{ |
|
|
myColorRampItem.color = QColor::fromRgb( myColorEntry->c1, myColorEntry->c1, myColorEntry->c1, myColorEntry->c4 ); |
|
|
} |
|
|
ct.append( myColorRampItem ); |
|
|
} |
|
|
else |
|
|
{ |
|
|
QgsDebugMsg( "Color interpretation type not supported yet" ); |
|
|
return ct; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
else |
|
|
{ |
|
|
QgsDebugMsg( "No color table found for band " + QString::number( theBandNumber ) ); |
|
|
return ct; |
|
|
} |
|
|
|
|
|
QgsDebugMsg( "Color table loaded successfully" ); |
|
|
return ct; |
|
|
return QgsGdalProviderBase::colorTable( mGdalDataset, theBandNumber ); |
|
|
} |
|
|
|
|
|
QgsCoordinateReferenceSystem QgsGdalProvider::crs() |
|
@@ -1131,65 +1051,18 @@ int QgsGdalProvider::capabilities() const |
|
|
return capability; |
|
|
} |
|
|
|
|
|
int QgsGdalProvider::dataTypeFormGdal( int theGdalDataType ) const |
|
|
{ |
|
|
switch ( theGdalDataType ) |
|
|
{ |
|
|
case GDT_Unknown: |
|
|
return QgsRasterDataProvider::UnknownDataType; |
|
|
break; |
|
|
case GDT_Byte: |
|
|
return QgsRasterDataProvider::Byte; |
|
|
break; |
|
|
case GDT_UInt16: |
|
|
return QgsRasterDataProvider::UInt16; |
|
|
break; |
|
|
case GDT_Int16: |
|
|
return QgsRasterDataProvider::Int16; |
|
|
break; |
|
|
case GDT_UInt32: |
|
|
return QgsRasterDataProvider::UInt32; |
|
|
break; |
|
|
case GDT_Int32: |
|
|
return QgsRasterDataProvider::Int32; |
|
|
break; |
|
|
case GDT_Float32: |
|
|
return QgsRasterDataProvider::Float32; |
|
|
break; |
|
|
case GDT_Float64: |
|
|
return QgsRasterDataProvider::Float64; |
|
|
break; |
|
|
case GDT_CInt16: |
|
|
return QgsRasterDataProvider::CInt16; |
|
|
break; |
|
|
case GDT_CInt32: |
|
|
return QgsRasterDataProvider::CInt32; |
|
|
break; |
|
|
case GDT_CFloat32: |
|
|
return QgsRasterDataProvider::CFloat32; |
|
|
break; |
|
|
case GDT_CFloat64: |
|
|
return QgsRasterDataProvider::CFloat64; |
|
|
break; |
|
|
case GDT_TypeCount: |
|
|
// make gcc happy |
|
|
break; |
|
|
} |
|
|
return QgsRasterDataProvider::UnknownDataType; |
|
|
} |
|
|
|
|
|
int QgsGdalProvider::srcDataType( int bandNo ) const |
|
|
{ |
|
|
GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, bandNo ); |
|
|
GDALDataType myGdalDataType = GDALGetRasterDataType( myGdalBand ); |
|
|
return dataTypeFormGdal( myGdalDataType ); |
|
|
return dataTypeFromGdal( myGdalDataType ); |
|
|
} |
|
|
|
|
|
int QgsGdalProvider::dataType( int bandNo ) const |
|
|
{ |
|
|
if ( mGdalDataType.size() == 0 ) return QgsRasterDataProvider::UnknownDataType; |
|
|
|
|
|
return dataTypeFormGdal( mGdalDataType[bandNo-1] ); |
|
|
return dataTypeFromGdal( mGdalDataType[bandNo-1] ); |
|
|
} |
|
|
|
|
|
int QgsGdalProvider::bandCount() const |
|
@@ -1203,27 +1076,9 @@ int QgsGdalProvider::bandCount() const |
|
|
int QgsGdalProvider::colorInterpretation( int theBandNo ) const |
|
|
{ |
|
|
GDALRasterBandH myGdalBand = GDALGetRasterBand( mGdalDataset, theBandNo ); |
|
|
return GDALGetRasterColorInterpretation( myGdalBand ); |
|
|
return colorInterpretationFromGdal ( GDALGetRasterColorInterpretation( myGdalBand ) ); |
|
|
} |
|
|
|
|
|
void QgsGdalProvider::registerGdalDrivers() |
|
|
{ |
|
|
//GDALDestroyDriverManager(); |
|
|
GDALAllRegister(); |
|
|
QSettings mySettings; |
|
|
QString myJoinedList = mySettings.value( "gdal/skipList", "" ).toString(); |
|
|
if ( !myJoinedList.isEmpty() ) |
|
|
{ |
|
|
QStringList myList = myJoinedList.split( " " ); |
|
|
for ( int i = 0; i < myList.size(); ++i ) |
|
|
{ |
|
|
QgsApplication::skipGdalDriver( myList.at( i ) ); |
|
|
} |
|
|
QgsApplication::applyGdalSkippedDrivers(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool QgsGdalProvider::isValid() |
|
|
{ |
|
|
QgsDebugMsg( QString( "valid = %1" ).arg( mValid ) ); |
|
@@ -1652,8 +1507,6 @@ QGISEXTERN bool isProvider() |
|
|
void buildSupportedRasterFileFilterAndExtensions( QString & theFileFiltersString, QStringList & theExtensions, QStringList & theWildcards ) |
|
|
{ |
|
|
QgsDebugMsg( "Entered" ); |
|
|
// first get the GDAL driver manager |
|
|
QgsGdalProvider::registerGdalDrivers(); |
|
|
|
|
|
// then iterate through all of the supported drivers, adding the |
|
|
// corresponding file filter |
|
@@ -1862,7 +1715,7 @@ QGISEXTERN bool isValidRasterFileName( QString const & theFileNameQString, QStri |
|
|
{ |
|
|
GDALDatasetH myDataset; |
|
|
|
|
|
QgsGdalProvider::registerGdalDrivers(); |
|
|
QgsGdalProviderBase::registerGdalDrivers(); |
|
|
|
|
|
CPLErrorReset(); |
|
|
|
|
|