Skip to content
Permalink
Browse files
Added raster test for a multiband image
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 4392c31e0fe6d150476935c38024612f40604e5b
Showing with 43 additions and 12 deletions.
  1. +13 −1 src/core/raster/qgsrasterlayer.cpp
  2. +4 −1 src/core/raster/qgsrasterlayer.h
  3. +26 −10 tests/src/core/testqgsrasterlayer.cpp
  4. BIN tests/testdata/landsat_clip.tif
@@ -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() ),
@@ -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;

@@ -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
@@ -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();
@@ -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;
};
@@ -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;
@@ -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 );
@@ -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;
Binary file not shown.

0 comments on commit 4392c31

Please sign in to comment.