|
| 1 | +/*************************************************************************** |
| 2 | + testninecellfilters.cpp |
| 3 | + -------------------------------------- |
| 4 | + Date : April 2018 |
| 5 | + Copyright : (C) 2018 by Alessandro Pasotti |
| 6 | + Email : elpaso at itopen dot it |
| 7 | + *************************************************************************** |
| 8 | + * * |
| 9 | + * This program is free software; you can redistribute it and/or modify * |
| 10 | + * it under the terms of the GNU General Public License as published by * |
| 11 | + * the Free Software Foundation; either version 2 of the License, or * |
| 12 | + * (at your option) any later version. * |
| 13 | + * * |
| 14 | + ***************************************************************************/ |
| 15 | + |
| 16 | +#include "qgstest.h" |
| 17 | +#include "qgsalignraster.h" |
| 18 | +#include "qgsaspectfilter.h" |
| 19 | +#include "qgsslopefilter.h" |
| 20 | +#include "qgshillshadefilter.h" |
| 21 | +#include "qgsruggednessfilter.h" |
| 22 | +#include "qgstotalcurvaturefilter.h" |
| 23 | +#include "qgsapplication.h" |
| 24 | + |
| 25 | +#include <QDir> |
| 26 | + |
| 27 | + |
| 28 | +class TestNineCellFilters : public QObject |
| 29 | +{ |
| 30 | + Q_OBJECT |
| 31 | + |
| 32 | + QString SRC_FILE; |
| 33 | + private slots: |
| 34 | + |
| 35 | + void initTestCase(); |
| 36 | + void testSlope(); |
| 37 | + void testAspect(); |
| 38 | + void testHillshade(); |
| 39 | + void testRuggedness(); |
| 40 | + void testTotalCurvature(); |
| 41 | + |
| 42 | + private: |
| 43 | + |
| 44 | + template <class T> void _testAlg( const QString &name ); |
| 45 | + |
| 46 | + static QString referenceFile( const QString &name ) |
| 47 | + { |
| 48 | + return QStringLiteral( "%1/analysis/%2.tif" ).arg( TEST_DATA_DIR, name ); |
| 49 | + } |
| 50 | + |
| 51 | + static QString tempFile( const QString &name ) |
| 52 | + { |
| 53 | + return QStringLiteral( "%1/ninecellfilterstest-%2.tif" ).arg( QDir::tempPath(), name ); |
| 54 | + } |
| 55 | +}; |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | +void TestNineCellFilters::initTestCase() |
| 60 | +{ |
| 61 | + GDALAllRegister(); |
| 62 | + |
| 63 | + SRC_FILE = QStringLiteral( TEST_DATA_DIR ) + "/analysis/dem.tif"; |
| 64 | + QgsApplication::init(); // needed for CRS database |
| 65 | +} |
| 66 | + |
| 67 | +template <class T> |
| 68 | +void TestNineCellFilters::_testAlg( const QString &name ) |
| 69 | +{ |
| 70 | + QString tmpFile( tempFile( name ) ); |
| 71 | + QString refFile( referenceFile( name ) ); |
| 72 | + |
| 73 | + QgsAlignRaster::RasterInfo in( SRC_FILE ); |
| 74 | + QSize inSize( in.rasterSize() ); |
| 75 | + QSizeF inCellSize( in.cellSize( ) ); |
| 76 | + T slopefilter( SRC_FILE, tmpFile, "GTiff" ); |
| 77 | + int res = slopefilter.processRaster(); |
| 78 | + QVERIFY( res == 0 ); |
| 79 | + |
| 80 | + // Produced file |
| 81 | + QgsAlignRaster::RasterInfo out( tmpFile ); |
| 82 | + QVERIFY( out.isValid() ); |
| 83 | + |
| 84 | + // Reference file |
| 85 | + QgsAlignRaster::RasterInfo ref( refFile ); |
| 86 | + QSize refSize( ref.rasterSize() ); |
| 87 | + QSizeF refCellSize( ref.cellSize( ) ); |
| 88 | + |
| 89 | + QCOMPARE( out.rasterSize(), inSize ); |
| 90 | + QCOMPARE( out.cellSize(), inCellSize ); |
| 91 | + QCOMPARE( out.rasterSize(), refSize ); |
| 92 | + QCOMPARE( out.cellSize(), refCellSize ); |
| 93 | + |
| 94 | + double refId1( ref.identify( 4081812, 2431750 ) ); |
| 95 | + double refId2( ref.identify( 4081312, 2431350 ) ); |
| 96 | + QCOMPARE( out.identify( 4081812, 2431750 ), refId1 ); |
| 97 | + QCOMPARE( out.identify( 4081312, 2431350 ), refId2 ); |
| 98 | + |
| 99 | +} |
| 100 | + |
| 101 | + |
| 102 | +void TestNineCellFilters::testSlope() |
| 103 | +{ |
| 104 | + _testAlg<QgsSlopeFilter>( QStringLiteral( "slope" ) ); |
| 105 | +} |
| 106 | + |
| 107 | + |
| 108 | +void TestNineCellFilters::testAspect() |
| 109 | +{ |
| 110 | + _testAlg<QgsAspectFilter>( QStringLiteral( "aspect" ) ); |
| 111 | +} |
| 112 | + |
| 113 | + |
| 114 | +void TestNineCellFilters::testHillshade() |
| 115 | +{ |
| 116 | + _testAlg<QgsHillshadeFilter>( QStringLiteral( "hillshade" ) ); |
| 117 | +} |
| 118 | + |
| 119 | + |
| 120 | +void TestNineCellFilters::testRuggedness() |
| 121 | +{ |
| 122 | + _testAlg<QgsRuggednessFilter>( QStringLiteral( "ruggedness" ) ); |
| 123 | +} |
| 124 | + |
| 125 | + |
| 126 | +void TestNineCellFilters::testTotalCurvature() |
| 127 | +{ |
| 128 | + _testAlg<QgsTotalCurvatureFilter>( QStringLiteral( "totalcurvature" ) ); |
| 129 | +} |
| 130 | + |
| 131 | +QGSTEST_MAIN( TestNineCellFilters ) |
| 132 | + |
| 133 | +#include "testqgsninecellfilters.moc" |
0 commit comments