|
| 1 | +/*************************************************************************** |
| 2 | + testprojectionissues.cpp |
| 3 | + --------------------------- |
| 4 | + begin : September 2012 |
| 5 | + copyright : (C) 2012 by Magnus Homann |
| 6 | + email : magnus at homann dot se |
| 7 | + ***************************************************************************/ |
| 8 | + |
| 9 | +/*************************************************************************** |
| 10 | + * * |
| 11 | + * This program is free software; you can redistribute it and/or modify * |
| 12 | + * it under the terms of the GNU General Public License as published by * |
| 13 | + * the Free Software Foundation; either version 2 of the License, or * |
| 14 | + * (at your option) any later version. * |
| 15 | + * * |
| 16 | + ***************************************************************************/ |
| 17 | + |
| 18 | +#include "qgsapplication.h" |
| 19 | +#include "qgsmapcanvas.h" |
| 20 | +#include "qgsmaplayerregistry.h" |
| 21 | +#include "qgsmaprenderer.h" |
| 22 | +#include "qgsmultibandcolorrenderer.h" |
| 23 | +#include "qgsrasterlayer.h" |
| 24 | +#include <QObject> |
| 25 | +#include <QtTest> |
| 26 | + |
| 27 | +class TestProjectionIssues: public QObject |
| 28 | +{ |
| 29 | + Q_OBJECT; |
| 30 | + private slots: |
| 31 | + void initTestCase();// will be called before the first testfunction is executed. |
| 32 | + void cleanupTestCase();// will be called after the last testfunction was executed. |
| 33 | + void init();// will be called before each testfunction is executed. |
| 34 | + void cleanup();// will be called after every testfunction. |
| 35 | + void issue5895();// test for #5895 |
| 36 | + private: |
| 37 | + QgsRasterLayer* mRasterLayer; |
| 38 | + QgsMapCanvas* mMapCanvas; |
| 39 | +}; |
| 40 | + |
| 41 | +void TestProjectionIssues::initTestCase() |
| 42 | +{ |
| 43 | + QgsApplication::init(); |
| 44 | + QgsApplication::initQgis(); |
| 45 | + |
| 46 | + //create maplayer from testdata and add to layer registry |
| 47 | + QFileInfo rasterFileInfo( QString( TEST_DATA_DIR ) + QDir::separator() + "checker360by180.asc" ); |
| 48 | + mRasterLayer = new QgsRasterLayer( rasterFileInfo.filePath(), |
| 49 | + rasterFileInfo.completeBaseName() ); |
| 50 | + // Set to WGS84 |
| 51 | + QgsCoordinateReferenceSystem sourceCRS; |
| 52 | + sourceCRS.createFromId( 4326, QgsCoordinateReferenceSystem::EpsgCrsId ); |
| 53 | + mRasterLayer->setCrs( sourceCRS, false); |
| 54 | + |
| 55 | + QgsMultiBandColorRenderer* rasterRenderer = new QgsMultiBandColorRenderer( mRasterLayer->dataProvider(), 2, 3, 4 ); |
| 56 | + mRasterLayer->setRenderer( rasterRenderer ); |
| 57 | + |
| 58 | + QList<QgsMapLayer *> mapLayers; |
| 59 | + mapLayers.append( mRasterLayer ); |
| 60 | + QgsMapLayerRegistry::instance()->addMapLayers( mapLayers ); |
| 61 | + |
| 62 | + // Add all layers in registry to the canvas |
| 63 | + QList<QgsMapCanvasLayer> canvasLayers; |
| 64 | + foreach ( QgsMapLayer* layer, QgsMapLayerRegistry::instance()->mapLayers().values() ) |
| 65 | + { |
| 66 | + canvasLayers.append( QgsMapCanvasLayer( layer ) ); |
| 67 | + } |
| 68 | + |
| 69 | + // create canvas |
| 70 | + mMapCanvas = new QgsMapCanvas(); |
| 71 | + mMapCanvas->setLayerSet( canvasLayers ); |
| 72 | + |
| 73 | + //reproject to SWEDREF 99 TM |
| 74 | + QgsCoordinateReferenceSystem destCRS; |
| 75 | + destCRS.createFromId( 3006, QgsCoordinateReferenceSystem::EpsgCrsId ); |
| 76 | + mMapCanvas->mapRenderer()->setDestinationCrs( destCRS ); |
| 77 | + mMapCanvas->mapRenderer()->setProjectionsEnabled( true ); |
| 78 | + |
| 79 | +}; |
| 80 | + |
| 81 | +void TestProjectionIssues::cleanupTestCase() |
| 82 | +{ |
| 83 | + delete mMapCanvas; |
| 84 | + delete mRasterLayer; |
| 85 | +}; |
| 86 | + |
| 87 | +void TestProjectionIssues::init() |
| 88 | +{ |
| 89 | + |
| 90 | +}; |
| 91 | + |
| 92 | +void TestProjectionIssues::cleanup() |
| 93 | +{ |
| 94 | + |
| 95 | +}; |
| 96 | + |
| 97 | +void TestProjectionIssues::issue5895() |
| 98 | +{ |
| 99 | + QgsRectangle largeExtent( -610861, 5101721, 2523921, 6795055 ); |
| 100 | + mMapCanvas->setExtent( largeExtent ); |
| 101 | + mMapCanvas->zoomByFactor( 2.0 ); // Zoom out. This should exceed the transform limits. |
| 102 | +}; |
| 103 | + |
| 104 | +QTEST_MAIN( TestProjectionIssues ) |
| 105 | +#include "moc_testprojectionissues.cxx" |
0 commit comments