Skip to content

Commit

Permalink
raster identify sip fix
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Oct 18, 2012
1 parent b3bf419 commit b5412cb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
6 changes: 5 additions & 1 deletion python/core/raster/qgsrasterdataprovider.sip
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
Histogram,
Size,
Create,
Remove
Remove,
IdentifyValue,
IdentifyText,
IdentifyHtml,
IdentifyFeature
};

// This is modified copy of GDALColorInterp
Expand Down
21 changes: 11 additions & 10 deletions src/providers/gdal/qgsgdalprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,6 @@ void QgsGdalProvider::readBlock( int theBandNo, QgsRectangle const & theExtent,
int width = right - left + 1;
int height = bottom - top + 1;


int srcLeft = 0; // source raster x offset
int srcTop = 0; // source raster x offset
int srcBottom = ySize() - 1;
Expand Down Expand Up @@ -521,7 +520,7 @@ void QgsGdalProvider::readBlock( int theBandNo, QgsRectangle const & theExtent,
QgsDebugMsg( QString( "tmpXMin = %1 tmpYMax = %2 tmpWidth = %3 tmpHeight = %4" ).arg( tmpXMin ).arg( tmpYMax ).arg( tmpWidth ).arg( tmpHeight ) );

// Allocate temporary block
char *tmpBlock = ( char * )malloc( dataSize * tmpWidth * tmpHeight );
char *tmpBlock = ( char * )QgsMalloc( dataSize * tmpWidth * tmpHeight );
if ( ! tmpBlock )
{
QgsDebugMsg( QString( "Coudn't allocate temporary buffer of %1 bytes" ).arg( dataSize * tmpWidth * tmpHeight ) );
Expand All @@ -540,7 +539,7 @@ void QgsGdalProvider::readBlock( int theBandNo, QgsRectangle const & theExtent,
{
QgsLogger::warning( "RasterIO error: " + QString::fromUtf8( CPLGetLastErrorMsg() ) );
QgsDebugMsg( "RasterIO error: " + QString::fromUtf8( CPLGetLastErrorMsg() ) );
free( tmpBlock );
QgsFree( tmpBlock );
return;
}

Expand Down Expand Up @@ -569,7 +568,7 @@ void QgsGdalProvider::readBlock( int theBandNo, QgsRectangle const & theExtent,
}
}

free( tmpBlock );
QgsFree( tmpBlock );
QgsDebugMsg( QString( "resample time (ms): %1" ).arg( time.elapsed() ) );

return;
Expand Down Expand Up @@ -830,11 +829,7 @@ int QgsGdalProvider::ySize() const { return mHeight; }

QMap<int, QVariant> QgsGdalProvider::identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent, int theWidth, int theHeight )
{
Q_UNUSED( theFormat );
Q_UNUSED( theExtent );
Q_UNUSED( theWidth );
Q_UNUSED( theHeight );
QgsDebugMsg( QString( "thePoint = %1 %2" ).arg( thePoint.x() ).arg( thePoint.y() ) );
QgsDebugMsg( QString( "thePoint = %1 %2" ).arg( thePoint.x(), 0, 'g', 10 ).arg( thePoint.y(), 0, 'g', 10 ) );

QMap<int, QVariant> results;

Expand All @@ -853,17 +848,23 @@ QMap<int, QVariant> QgsGdalProvider::identify( const QgsPoint & thePoint, Identi
QgsRectangle myExtent = theExtent;
if ( myExtent.isEmpty() ) myExtent = extent();

QgsDebugMsg( "myExtent = " + myExtent.toString() );

if ( theWidth == 0 ) theWidth = xSize();
if ( theHeight == 0 ) theHeight = ySize();

QgsDebugMsg( QString( "theWidth = %1 theHeight = %2" ).arg( theWidth ).arg( theHeight ) );

// Calculate the row / column where the point falls
double xres = ( myExtent.width() ) / theWidth;
double yres = ( myExtent.height() ) / theHeight;

// Offset, not the cell index -> flor
// Offset, not the cell index -> floor
int col = ( int ) floor(( thePoint.x() - myExtent.xMinimum() ) / xres );
int row = ( int ) floor(( myExtent.yMaximum() - thePoint.y() ) / yres );

QgsDebugMsg( QString( "row = %1 col = %2" ).arg( row ).arg( col ) );

// QgsDebugMsg( "row = " + QString::number( row ) + " col = " + QString::number( col ) );

int r = 0;
Expand Down
9 changes: 5 additions & 4 deletions src/providers/wcs/qgswcsprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1634,10 +1634,11 @@ QString QgsWcsProvider:: htmlRow( const QString &text1, const QString &text2 )
return "<tr>" + htmlCell( text1 ) + htmlCell( text2 ) + "</tr>";
}

//QMap<int, void *> QgsWcsProvider::identify( const QgsPoint & thePoint )
QMap<int, QVariant> QgsWcsProvider::identify( const QgsPoint & thePoint, IdentifyFormat theFormat, const QgsRectangle &theExtent, int theWidth, int theHeight )
{
QgsDebugMsg( "Entered" );
QgsDebugMsg( QString( "thePoint = %1 %2" ).arg( thePoint.x(), 0, 'g', 10 ).arg( thePoint.y(), 0, 'g', 10 ) );
QgsDebugMsg( QString( "theWidth = %1 theHeight = %2" ).arg( theWidth ).arg( theHeight ) );
QgsDebugMsg( "theExtent = " + theExtent.toString() );
QMap<int, QVariant> results;

if ( theFormat != IdentifyFormatValue ) return results;
Expand Down Expand Up @@ -1706,8 +1707,8 @@ QMap<int, QVariant> QgsWcsProvider::identify( const QgsPoint & thePoint, Identif
double y = thePoint.y();

// Calculate the row / column where the point falls
double xRes = ( mCachedViewExtent.width() ) / mCachedViewWidth;
double yRes = ( mCachedViewExtent.height() ) / mCachedViewHeight;
double xRes = mCachedViewExtent.width() / mCachedViewWidth;
double yRes = mCachedViewExtent.height() / mCachedViewHeight;

// Offset, not the cell index -> flor
int col = ( int ) floor(( x - mCachedViewExtent.xMinimum() ) / xRes );
Expand Down

0 comments on commit b5412cb

Please sign in to comment.