Skip to content

Commit

Permalink
prepare for GRASS raster provider
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@12879 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek committed Feb 4, 2010
1 parent 2034de2 commit 9f6a286
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 57 deletions.
7 changes: 7 additions & 0 deletions src/core/qgsrasterdataprovider.cpp
Expand Up @@ -19,6 +19,8 @@
#include "qgsrasterdataprovider.h"
#include "qgslogger.h"

#include <QMap>

QgsRasterDataProvider::QgsRasterDataProvider(): mDpi( -1 )
{
}
Expand All @@ -45,5 +47,10 @@ QString QgsRasterDataProvider::capabilitiesString() const
return abilitiesList.join( ", " );
}

bool QgsRasterDataProvider::identify( const QgsPoint& thePoint, QMap<QString, QString>& theResults )
{
theResults.clear();
return false;
}

// ENDS
3 changes: 3 additions & 0 deletions src/core/qgsrasterdataprovider.h
Expand Up @@ -115,6 +115,9 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider
*/
virtual QString metadata() = 0;

/** \brief Identify raster value(s) found on the point position */
virtual bool identify( const QgsPoint & point, QMap<QString, QString>& results );

/**
* \brief Identify details from a server (e.g. WMS) from the last screen update
*
Expand Down
80 changes: 23 additions & 57 deletions src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -490,58 +490,6 @@ QDateTime QgsRasterLayer::lastModified( QString const & name )

t = fi.lastModified();

// Check also color table for GRASS
if ( name.contains( "cellhd" ) > 0 )
{ // most probably GRASS
QString dir = fi.path();
QString map = fi.fileName();
fi.setFile( dir + "/../colr/" + map );

if ( fi.exists() )
{
if ( fi.lastModified() > t ) t = fi.lastModified();
}
}

// Check GRASS group members (bands)
if ( name.contains( "group" ) > 0 )
{ // probably GRASS group
fi.setFile( name + "/REF" );

if ( fi.exists() )
{ // most probably GRASS group
QFile f( name + "/REF" );
if ( f.open( QIODevice::ReadOnly ) )
{
QString dir = fi.path() + "/../../../";

char buf[101];
while ( f.readLine( buf, 100 ) != -1 )
{
QString ln = QString( buf );
QStringList sl = ln.trimmed().split( ' ', QString::SkipEmptyParts );
QString map = sl.first();
sl.pop_front();
QString mapset = sl.first();

// header
fi.setFile( dir + mapset + "/cellhd/" + map );
if ( fi.exists() )
{
if ( fi.lastModified() > t ) t = fi.lastModified();
}

// color
fi.setFile( dir + mapset + "/colr/" + map );
if ( fi.exists() )
{
if ( fi.lastModified() > t ) t = fi.lastModified();
}
}
}
}
}

QgsDebugMsg( "last modified = " + t.toString() );

return t;
Expand Down Expand Up @@ -1170,6 +1118,9 @@ QgsRasterLayer::RasterPyramidList QgsRasterLayer::buildPyramidList()
int myWidth = mWidth;
int myHeight = mHeight;
int myDivisor = 2;

if ( mDataProvider ) return mPyramidList;

GDALRasterBandH myGDALBand = GDALGetRasterBand( mGdalDataset, 1 ); //just use the first band

mPyramidList.clear();
Expand Down Expand Up @@ -1928,6 +1879,12 @@ bool QgsRasterLayer::identify( const QgsPoint& thePoint, QMap<QString, QString>&

QgsDebugMsg( thePoint.toString() );

if ( !mProviderKey.isEmpty() )
{
QgsDebugMsg( "identify provider : " + mProviderKey ) ;
return ( mDataProvider->identify( thePoint, theResults ) );
}

if ( !mLayerExtent.contains( thePoint ) )
{
// Outside the raster
Expand Down Expand Up @@ -3270,8 +3227,15 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
mDrawingStyle = MultiBandColor; //sensible default

// Setup source CRS
*mCRS = QgsCoordinateReferenceSystem();
mCRS->createFromOgcWmsCrs( crs );
if ( mProviderKey == "wms" )
{
*mCRS = QgsCoordinateReferenceSystem();
mCRS->createFromOgcWmsCrs( crs );
}
else
{
*mCRS = QgsCoordinateReferenceSystem( mDataProvider->crs() );
}
}
}
else
Expand Down Expand Up @@ -5453,9 +5417,11 @@ bool QgsRasterLayer::update()

if ( mLastModified < QgsRasterLayer::lastModified( source() ) )
{
QgsDebugMsg( "Outdated -> reload" );
closeDataset();
return readFile( source() );
if ( !usesProvider() ) {
QgsDebugMsg( "Outdated -> reload" );
closeDataset();
return readFile( source() );
}
}
return true;
}
Expand Down

0 comments on commit 9f6a286

Please sign in to comment.