|
47 | 47 | #include <QTime> |
48 | 48 | #include <QSettings> |
49 | 49 | #include <QTextDocument> |
| 50 | +#include <QDebug> |
50 | 51 |
|
51 | 52 | #include "gdalwarper.h" |
52 | 53 | #include "ogr_spatialref.h" |
@@ -875,6 +876,78 @@ int QgsGdalProvider::yBlockSize() const |
875 | 876 | int QgsGdalProvider::xSize() const { return mWidth; } |
876 | 877 | int QgsGdalProvider::ySize() const { return mHeight; } |
877 | 878 |
|
| 879 | +QString QgsGdalProvider::generateBandName( int theBandNumber ) const |
| 880 | +{ |
| 881 | +#ifdef GDAL_COMPUTE_VERSION /* only available in GDAL 1.10 or later */ |
| 882 | +#if GDAL_VERSION_NUM >= GDAL_COMPUTE_VERSION(1,10,0) |
| 883 | + if ( strcmp( GDALGetDriverShortName( GDALGetDatasetDriver( mGdalDataset ) ), "netCDF" ) == 0 ) |
| 884 | + { |
| 885 | + char ** GDALmetadata = GDALGetMetadata( mGdalDataset, NULL ); |
| 886 | + |
| 887 | + if ( GDALmetadata ) |
| 888 | + { |
| 889 | + QStringList metadata = cStringList2Q_( GDALmetadata ); |
| 890 | + QStringList dimExtraValues; |
| 891 | + QMap< QString, QString > unitsMap; |
| 892 | + for ( QStringList::const_iterator i = metadata.begin(); |
| 893 | + i != metadata.end(); ++i ) |
| 894 | + { |
| 895 | + QString val( *i ); |
| 896 | + if ( !val.startsWith( "NETCDF_DIM_EXTRA" ) && !val.contains( "#units=" ) ) |
| 897 | + continue; |
| 898 | + QStringList values = val.split( "=" ); |
| 899 | + val = values.at( 1 ); |
| 900 | + if ( values.at( 0 ) == "NETCDF_DIM_EXTRA" ) |
| 901 | + { |
| 902 | + dimExtraValues = val.replace( QString( "{" ), QString( "" ) ).replace( QString( "}" ), QString( "" ) ).split( "," ); |
| 903 | + //http://qt-project.org/doc/qt-4.8/qregexp.html#capturedTexts |
| 904 | + } |
| 905 | + else |
| 906 | + { |
| 907 | + unitsMap[ values.at( 0 ).split( "#" ).at( 0 )] = val; |
| 908 | + } |
| 909 | + } |
| 910 | + if ( dimExtraValues.count() > 0 ) |
| 911 | + { |
| 912 | + QStringList bandNameValues; |
| 913 | + GDALRasterBandH gdalBand = GDALGetRasterBand( mGdalDataset, theBandNumber ); |
| 914 | + GDALmetadata = GDALGetMetadata( gdalBand, NULL ); |
| 915 | + |
| 916 | + if ( GDALmetadata ) |
| 917 | + { |
| 918 | + metadata = cStringList2Q_( GDALmetadata ); |
| 919 | + for ( QStringList::const_iterator i = metadata.begin(); |
| 920 | + i != metadata.end(); ++i ) |
| 921 | + { |
| 922 | + QString val( *i ); |
| 923 | + if ( !val.startsWith( "NETCDF_DIM_" ) ) |
| 924 | + continue; |
| 925 | + QStringList values = val.split( "=" ); |
| 926 | + for ( QStringList::const_iterator j = dimExtraValues.begin(); |
| 927 | + j != dimExtraValues.end(); ++j ) |
| 928 | + { |
| 929 | + QString dim = ( *j ); |
| 930 | + if ( values.at( 0 ) != "NETCDF_DIM_" + dim ) |
| 931 | + continue; |
| 932 | + if ( unitsMap.contains( dim ) && unitsMap[ dim ] != "" && unitsMap[ dim ] != "none" ) |
| 933 | + bandNameValues.append( dim + "=" + values.at( 1 ) + " (" + unitsMap[ dim ] + ")" ); |
| 934 | + else |
| 935 | + bandNameValues.append( dim + "=" + values.at( 1 ) ); |
| 936 | + } |
| 937 | + } |
| 938 | + } |
| 939 | + |
| 940 | + if ( bandNameValues.count() > 0 ) |
| 941 | + return tr( "Band" ) + QString( " %1 / %2" ) .arg( theBandNumber, 1 + ( int ) log10(( float ) bandCount() ), 10, QChar( '0' ) ).arg( bandNameValues.join( " / " ) ); |
| 942 | + } |
| 943 | + } |
| 944 | + } |
| 945 | +#endif |
| 946 | +#endif |
| 947 | + |
| 948 | + return QgsRasterDataProvider::generateBandName( theBandNumber ); |
| 949 | +} |
| 950 | + |
878 | 951 | QgsRasterIdentifyResult QgsGdalProvider::identify( const QgsPoint & thePoint, QgsRaster::IdentifyFormat theFormat, const QgsRectangle &theExtent, int theWidth, int theHeight ) |
879 | 952 | { |
880 | 953 | QgsDebugMsg( QString( "thePoint = %1 %2" ).arg( thePoint.x(), 0, 'g', 10 ).arg( thePoint.y(), 0, 'g', 10 ) ); |
|
0 commit comments