mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
Use Even's code suggestions + add tests
This commit is contained in:
parent
49f0059a9d
commit
dda53897a2
@ -2999,20 +2999,23 @@ void QgsGdalProvider::initBaseDataset()
|
||||
{
|
||||
QgsLogger::warning( QStringLiteral( "Creating Warped VRT." ) );
|
||||
|
||||
// Add alpha band to the output VRT dataset if it does not exist already
|
||||
// so that pixels in empty regions (e.g. when the raster is rotated) will be transparent
|
||||
gdal::warp_options_unique_ptr psWarpOptions( GDALCreateWarpOptions() );
|
||||
if ( GDALGetRasterColorInterpretation( GDALGetRasterBand( mGdalBaseDataset, GDALGetRasterCount( mGdalBaseDataset ) ) ) != GCI_AlphaBand )
|
||||
{
|
||||
psWarpOptions->nDstAlphaBand = GDALGetRasterCount( mGdalBaseDataset ) + 1;
|
||||
}
|
||||
|
||||
if ( GDALGetMetadata( mGdalBaseDataset, "RPC" ) )
|
||||
{
|
||||
mGdalDataset =
|
||||
QgsGdalUtils::rpcAwareAutoCreateWarpedVrt( mGdalBaseDataset, nullptr, nullptr,
|
||||
GRA_NearestNeighbour, 0.2, nullptr );
|
||||
GRA_NearestNeighbour, 0.2, psWarpOptions.get() );
|
||||
mGdalTransformerArg = QgsGdalUtils::rpcAwareCreateTransformer( mGdalBaseDataset );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Add alpha band to the output VRT dataset so that pixels in empty regions
|
||||
// (e.g. when the raster is rotated) will be transparent
|
||||
gdal::warp_options_unique_ptr psWarpOptions( GDALCreateWarpOptions() );
|
||||
psWarpOptions->nDstAlphaBand = GDALGetRasterCount( mGdalBaseDataset ) + 1;
|
||||
|
||||
mGdalDataset =
|
||||
GDALAutoCreateWarpedVRT( mGdalBaseDataset, nullptr, nullptr,
|
||||
GRA_NearestNeighbour, 0.2, psWarpOptions.get() );
|
||||
|
@ -100,6 +100,7 @@ class TestQgsRasterLayer : public QObject
|
||||
void testRefreshRendererIfNeeded();
|
||||
void sample();
|
||||
void testTemporalProperties();
|
||||
void rotatedRaster();
|
||||
|
||||
|
||||
private:
|
||||
@ -1040,5 +1041,24 @@ void TestQgsRasterLayer::testTemporalProperties()
|
||||
QCOMPARE( temporalProperties->fixedTemporalRange().end(), dateTimeRange.end() );
|
||||
}
|
||||
|
||||
void TestQgsRasterLayer::rotatedRaster()
|
||||
{
|
||||
mMapSettings->setExtent( QgsRectangle( 994, 922, 1174, 1102 ) );
|
||||
|
||||
std::unique_ptr< QgsRasterLayer> rgb = std::make_unique< QgsRasterLayer >( mTestDataDir + "raster/rotated_rgb.png",
|
||||
QStringLiteral( "rgb" ) );
|
||||
QVERIFY( rgb->isValid() );
|
||||
|
||||
mMapSettings->setLayers( QList<QgsMapLayer *>() << rgb.get() );
|
||||
QVERIFY( render( QStringLiteral( "raster_rotated_rgb" ) ) );
|
||||
|
||||
std::unique_ptr< QgsRasterLayer> rgba = std::make_unique< QgsRasterLayer >( mTestDataDir + "raster/rotated_rgba.png",
|
||||
QStringLiteral( "rgba" ) );
|
||||
QVERIFY( rgba->isValid() );
|
||||
|
||||
mMapSettings->setLayers( QList<QgsMapLayer *>() << rgba.get() );
|
||||
QVERIFY( render( QStringLiteral( "raster_rotated_rgba" ) ) );
|
||||
}
|
||||
|
||||
QGSTEST_MAIN( TestQgsRasterLayer )
|
||||
#include "testqgsrasterlayer.moc"
|
||||
|
BIN
tests/testdata/control_images/expected_raster_rotated_rgb/expected_raster_rotated_rgb.png
vendored
Normal file
BIN
tests/testdata/control_images/expected_raster_rotated_rgb/expected_raster_rotated_rgb.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 56 KiB |
BIN
tests/testdata/control_images/expected_raster_rotated_rgba/expected_raster_rotated_rgba.png
vendored
Normal file
BIN
tests/testdata/control_images/expected_raster_rotated_rgba/expected_raster_rotated_rgba.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 56 KiB |
BIN
tests/testdata/raster/rotated_rgb.png
vendored
Normal file
BIN
tests/testdata/raster/rotated_rgb.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 321 B |
6
tests/testdata/raster/rotated_rgb.pngw
vendored
Normal file
6
tests/testdata/raster/rotated_rgb.pngw
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
0.72744
|
||||
0.97092
|
||||
0.97092
|
||||
-0.7274
|
||||
1000
|
||||
1000
|
BIN
tests/testdata/raster/rotated_rgba.png
vendored
Normal file
BIN
tests/testdata/raster/rotated_rgba.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 722 B |
6
tests/testdata/raster/rotated_rgba.pngw
vendored
Normal file
6
tests/testdata/raster/rotated_rgba.pngw
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
0.72744
|
||||
0.97092
|
||||
0.97092
|
||||
-0.7274
|
||||
1000
|
||||
1000
|
Loading…
x
Reference in New Issue
Block a user