Skip to content

Commit

Permalink
Added raster test for a multiband image
Browse files Browse the repository at this point in the history
Added missing loadDefaultStyle to raster ctor (its not enabled in ui for 0.9.2 since its untested and unstable)
Added test image for testing multiband raster images


git-svn-id: http://svn.osgeo.org/qgis/trunk@8038 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Jan 24, 2008
1 parent f2dab12 commit 4392c31
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 12 deletions.
14 changes: 13 additions & 1 deletion src/core/raster/qgsrasterlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,10 @@ bool QgsRasterLayer::isValidRasterFileName(QString const & theFileNameQString)
// Non Static methods now....
//
/////////////////////////////////////////////////////////
QgsRasterLayer::QgsRasterLayer(QString const & path, QString const & baseName)
QgsRasterLayer::QgsRasterLayer(
QString const & path,
QString const & baseName,
bool loadDefaultStyleFlag)
: QgsMapLayer(RASTER, baseName, path),
// XXX where is this? popMenu(0), //popMenu is the contextmenu obtained by right clicking on the legend
mRasterXDim( std::numeric_limits<int>::max() ),
Expand All @@ -390,6 +393,15 @@ QgsRasterLayer::QgsRasterLayer(QString const & path, QString const & baseName)
mStandardDeviations(0),
mDataProvider(0)
{
if ( loadDefaultStyleFlag )
{
bool defaultLoadedFlag = false;
loadDefaultStyle( defaultLoadedFlag );
if ( defaultLoadedFlag )
{
return;
}
}
mUserDefinedRGBMinMaxFlag = false; //defaults needed to bypass stretch
mUserDefinedGrayMinMaxFlag = false;

Expand Down
5 changes: 4 additions & 1 deletion src/core/raster/qgsrasterlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
*
* The main tasks carried out by the constructor are:
*
* -Load the rasters default style (.qml) file if it exists
*
* -Populate the RasterStatsVector with initial values for each band.
*
* -Calculate the layer extents
Expand All @@ -213,7 +215,8 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
* -
* */
QgsRasterLayer(const QString & path = QString::null,
const QString & baseName = QString::null);
const QString & baseName = QString::null,
bool loadDefaultStyleFlag = true );

/** \brief The destuctor. */
~QgsRasterLayer();
Expand Down
36 changes: 26 additions & 10 deletions tests/src/core/testqgsrasterlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ class TestQgsRasterLayer: public QObject

void isValid();
void pseudoColor();
void landsatBasic();
void checkDimensions();
private:
bool render(QString theFileName);
QgsRasterLayer * mpRasterLayer;
QgsRasterLayer * mpLandsatRasterLayer;
QgsMapRender * mpMapRenderer;
QString mReport;
};
Expand All @@ -77,13 +79,18 @@ void TestQgsRasterLayer::initTestCase()
std::cout << "User DB PATH: " << QgsApplication::qgisUserDbFilePath().toLocal8Bit().data() << std::endl;

//create a raster layer that will be used in all tests...
QString myFileName (TEST_DATA_DIR); //defined in CmakeLists.txt
myFileName = myFileName + QDir::separator() + "tenbytenraster.asc";
QString myTestDir (TEST_DATA_DIR); //defined in CmakeLists.txt
QString myFileName = myTestDir + QDir::separator() + "tenbytenraster.asc";
QString myLandsatFileName = myTestDir + QDir::separator() + "landsat_clip.tif";
QFileInfo myRasterFileInfo ( myFileName );
mpRasterLayer = new QgsRasterLayer ( myRasterFileInfo.filePath(),
myRasterFileInfo.completeBaseName() );
QFileInfo myLandsatRasterFileInfo ( myLandsatFileName );
mpLandsatRasterLayer = new QgsRasterLayer ( myLandsatRasterFileInfo.filePath(),
myLandsatRasterFileInfo.completeBaseName() );
// Register the layer with the registry
QgsMapLayerRegistry::instance()->addMapLayer(mpRasterLayer);
QgsMapLayerRegistry::instance()->addMapLayer(mpLandsatRasterLayer);
// add the test layer to the maprender
mpMapRenderer = new QgsMapRender();
QStringList myLayers;
Expand All @@ -109,20 +116,30 @@ void TestQgsRasterLayer::cleanupTestCase()
void TestQgsRasterLayer::isValid()
{
QVERIFY ( mpRasterLayer->isValid() );
mpMapRenderer->setExtent(mpRasterLayer->extent());
QVERIFY ( render("raster") );
}

void TestQgsRasterLayer::pseudoColor()
{
mpRasterLayer->setDrawingStyle(QgsRasterLayer::SINGLE_BAND_PSEUDO_COLOR);
mpRasterLayer->setColorShadingAlgorithm(QgsRasterLayer::PSEUDO_COLOR);
mpRasterLayer->setContrastEnhancementAlgorithm(
QgsContrastEnhancement::STRETCH_TO_MINMAX, false);
mpRasterLayer->setMinimumValue(mpRasterLayer->getGrayBandName(),0.0, false);
mpRasterLayer->setMaximumValue(mpRasterLayer->getGrayBandName(),0.0);
QVERIFY(render("raster_pseudo"));
mpRasterLayer->setDrawingStyle(QgsRasterLayer::SINGLE_BAND_PSEUDO_COLOR);
mpRasterLayer->setColorShadingAlgorithm(QgsRasterLayer::PSEUDO_COLOR);
mpRasterLayer->setContrastEnhancementAlgorithm(
QgsContrastEnhancement::STRETCH_TO_MINMAX, false);
mpRasterLayer->setMinimumValue(mpRasterLayer->getGrayBandName(),0.0, false);
mpRasterLayer->setMaximumValue(mpRasterLayer->getGrayBandName(),10.0);
mpMapRenderer->setExtent(mpRasterLayer->extent());
QVERIFY(render("raster_pseudo"));
}

void TestQgsRasterLayer::landsatBasic()
{
QStringList myLayers;
myLayers << mpLandsatRasterLayer->getLayerID();
mpMapRenderer->setLayerSet(myLayers);
mpMapRenderer->setExtent(mpLandsatRasterLayer->extent());
QVERIFY(render("landsat_basic"));
}
void TestQgsRasterLayer::checkDimensions()
{
QVERIFY ( mpRasterLayer->getRasterXDim() == 10 );
Expand All @@ -135,7 +152,6 @@ void TestQgsRasterLayer::checkDimensions()
bool TestQgsRasterLayer::render(QString theTestType)
{
mReport += "<h2>" + theTestType + "</h2>\n";
mpMapRenderer->setExtent(mpRasterLayer->extent());
QString myDataDir (TEST_DATA_DIR); //defined in CmakeLists.txt
QString myTestDataDir = myDataDir + QDir::separator();
QgsRenderChecker myChecker;
Expand Down
Binary file added tests/testdata/landsat_clip.tif
Binary file not shown.

0 comments on commit 4392c31

Please sign in to comment.