@@ -844,15 +844,31 @@ bool QgsGdalProvider::identify( const QgsPoint & point, QMap<int, QString>& resu
844
844
for ( int i = 1 ; i <= GDALGetRasterCount ( mGdalDataset ); i++ )
845
845
{
846
846
GDALRasterBandH gdalBand = GDALGetRasterBand ( mGdalDataset , i );
847
- double value ;
847
+ double data[ 4 ] ;
848
848
849
- CPLErr err = GDALRasterIO ( gdalBand, GF_Read, col, row, 1 , 1 ,
850
- &value, 1 , 1 , GDT_Float64, 0 , 0 );
849
+ // GDAL ECW driver reads whole row if single pixel (nYSize == 1) is requested
850
+ // and it makes identify very slow -> use 2x2 matrix
851
+ int r = 0 ;
852
+ int c = 0 ;
853
+ if ( col == mWidth - 1 && mWidth > 1 )
854
+ {
855
+ col--;
856
+ c++;
857
+ }
858
+ if ( row == mHeight - 1 && mHeight > 1 )
859
+ {
860
+ row--;
861
+ r++;
862
+ }
863
+
864
+ CPLErr err = GDALRasterIO ( gdalBand, GF_Read, col, row, 2 , 2 ,
865
+ data, 2 , 2 , GDT_Float64, 0 , 0 );
851
866
852
867
if ( err != CPLE_None )
853
868
{
854
869
QgsLogger::warning ( " RasterIO error: " + QString::fromUtf8 ( CPLGetLastErrorMsg () ) );
855
870
}
871
+ double value = data[r*2 +c];
856
872
857
873
// double value = readValue( data, type, 0 );
858
874
// QgsDebugMsg( QString( "value=%1" ).arg( value ) );
@@ -878,62 +894,12 @@ bool QgsGdalProvider::identify( const QgsPoint & point, QMap<int, QString>& resu
878
894
879
895
bool QgsGdalProvider::identify ( const QgsPoint& thePoint, QMap<QString, QString>& theResults )
880
896
{
881
- // QgsDebugMsg( "Entered" );
882
- if ( !mExtent .contains ( thePoint ) )
897
+ QMap<int , QString> results;
898
+ identify ( thePoint, results );
899
+ for ( int i = 1 ; i <= GDALGetRasterCount ( mGdalDataset ); i++ )
883
900
{
884
- // Outside the raster
885
- for ( int i = 1 ; i <= GDALGetRasterCount ( mGdalDataset ); i++ )
886
- {
887
- theResults[ generateBandName ( i )] = tr ( " out of extent" );
888
- }
901
+ theResults[ generateBandName ( i )] = results.value ( i );
889
902
}
890
- else
891
- {
892
- double x = thePoint.x ();
893
- double y = thePoint.y ();
894
-
895
- // Calculate the row / column where the point falls
896
- double xres = ( mExtent .xMaximum () - mExtent .xMinimum () ) / mWidth ;
897
- double yres = ( mExtent .yMaximum () - mExtent .yMinimum () ) / mHeight ;
898
-
899
- // Offset, not the cell index -> flor
900
- int col = ( int ) floor (( x - mExtent .xMinimum () ) / xres );
901
- int row = ( int ) floor (( mExtent .yMaximum () - y ) / yres );
902
-
903
- // QgsDebugMsg( "row = " + QString::number( row ) + " col = " + QString::number( col ) );
904
-
905
- for ( int i = 1 ; i <= GDALGetRasterCount ( mGdalDataset ); i++ )
906
- {
907
- GDALRasterBandH gdalBand = GDALGetRasterBand ( mGdalDataset , i );
908
- double value;
909
-
910
- CPLErr err = GDALRasterIO ( gdalBand, GF_Read, col, row, 1 , 1 ,
911
- &value, 1 , 1 , GDT_Float64, 0 , 0 );
912
-
913
- if ( err != CPLE_None )
914
- {
915
- QgsLogger::warning ( " RasterIO error: " + QString::fromUtf8 ( CPLGetLastErrorMsg () ) );
916
- }
917
-
918
- // double value = readValue( data, type, 0 );
919
- // QgsDebugMsg( QString( "value=%1" ).arg( value ) );
920
- QString v;
921
-
922
- if ( mValidNoDataValue && ( fabs ( value - mNoDataValue [i-1 ] ) <= TINY_VALUE || value != value ) )
923
- {
924
- v = tr ( " null (no data)" );
925
- }
926
- else
927
- {
928
- v.setNum ( value );
929
- }
930
-
931
- theResults[ generateBandName ( i )] = v;
932
-
933
- // CPLFree( data );
934
- }
935
- }
936
-
937
903
return true ;
938
904
}
939
905
0 commit comments