mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-17 00:04:02 -04:00
Try to do automatic choice of the reference layer in GUI (using smallest cell area)
This commit is contained in:
parent
fcc0160755
commit
11d1ac9540
@ -157,5 +157,8 @@ class QgsAlignRaster
|
|||||||
//! write contents of the object to standard error stream - for debugging
|
//! write contents of the object to standard error stream - for debugging
|
||||||
void dump() const;
|
void dump() const;
|
||||||
|
|
||||||
|
//! Return index of the layer which has smallest cell size (returns -1 on error)
|
||||||
|
int suggestedReferenceLayer() const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include <QPair>
|
#include <QPair>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
|
#include "qgscoordinatereferencesystem.h"
|
||||||
#include "qgsrectangle.h"
|
#include "qgsrectangle.h"
|
||||||
|
|
||||||
|
|
||||||
@ -386,6 +387,36 @@ void QgsAlignRaster::dump() const
|
|||||||
qDebug( "extent %s", e.toString().toAscii().constData() );
|
qDebug( "extent %s", e.toString().toAscii().constData() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int QgsAlignRaster::suggestedReferenceLayer() const
|
||||||
|
{
|
||||||
|
int bestIndex = -1;
|
||||||
|
double bestCellArea = qInf();
|
||||||
|
QSizeF cs;
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
// using WGS84 as a destination CRS... but maybe some projected CRS
|
||||||
|
// would be a better a choice to more accurately compute areas?
|
||||||
|
// (Why earth is not flat???)
|
||||||
|
QgsCoordinateReferenceSystem destCRS( "EPSG:4326" );
|
||||||
|
QString destWkt = destCRS.toWkt();
|
||||||
|
|
||||||
|
foreach ( const Item& raster, mRasters )
|
||||||
|
{
|
||||||
|
if ( !suggestedWarpOutput( RasterInfo( raster.inputFilename ), destWkt, &cs ) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
double cellArea = cs.width() * cs.height();
|
||||||
|
if ( cellArea < bestCellArea )
|
||||||
|
{
|
||||||
|
bestCellArea = cellArea;
|
||||||
|
bestIndex = i;
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return bestIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool QgsAlignRaster::createAndWarp( const Item& raster )
|
bool QgsAlignRaster::createAndWarp( const Item& raster )
|
||||||
{
|
{
|
||||||
|
@ -205,6 +205,9 @@ class ANALYSIS_EXPORT QgsAlignRaster
|
|||||||
//! write contents of the object to standard error stream - for debugging
|
//! write contents of the object to standard error stream - for debugging
|
||||||
void dump() const;
|
void dump() const;
|
||||||
|
|
||||||
|
//! Return index of the layer which has smallest cell size (returns -1 on error)
|
||||||
|
int suggestedReferenceLayer() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
//! Internal function for processing of one raster (1. create output, 2. do the alignment)
|
//! Internal function for processing of one raster (1. create output, 2. do the alignment)
|
||||||
|
@ -112,7 +112,10 @@ void QgsAlignRasterDialog::populateLayersView()
|
|||||||
{
|
{
|
||||||
mCboReferenceLayer->clear();
|
mCboReferenceLayer->clear();
|
||||||
|
|
||||||
|
int refLayerIndex = mAlign->suggestedReferenceLayer();
|
||||||
|
|
||||||
QStandardItemModel* model = new QStandardItemModel();
|
QStandardItemModel* model = new QStandardItemModel();
|
||||||
|
int i = 0;
|
||||||
foreach ( QgsAlignRaster::Item item, mAlign->rasters() )
|
foreach ( QgsAlignRaster::Item item, mAlign->rasters() )
|
||||||
{
|
{
|
||||||
QString layerName = _rasterLayerName( item.inputFilename );
|
QString layerName = _rasterLayerName( item.inputFilename );
|
||||||
@ -120,13 +123,20 @@ void QgsAlignRasterDialog::populateLayersView()
|
|||||||
QStandardItem* si = new QStandardItem( QgsLayerItem::iconRaster(), layerName );
|
QStandardItem* si = new QStandardItem( QgsLayerItem::iconRaster(), layerName );
|
||||||
model->appendRow( si );
|
model->appendRow( si );
|
||||||
|
|
||||||
|
if ( i == refLayerIndex )
|
||||||
|
layerName += tr( " [best reference]" );
|
||||||
|
|
||||||
mCboReferenceLayer->addItem( layerName );
|
mCboReferenceLayer->addItem( layerName );
|
||||||
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
mViewLayers->setModel( model );
|
mViewLayers->setModel( model );
|
||||||
|
|
||||||
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( model->rowCount() > 0 );
|
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( model->rowCount() > 0 );
|
||||||
|
|
||||||
|
if ( refLayerIndex >= 0 )
|
||||||
|
mCboReferenceLayer->setCurrentIndex( refLayerIndex );
|
||||||
|
|
||||||
updateAlignedRasterInfo();
|
updateAlignedRasterInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,6 +252,20 @@ class TestAlignRaster : public QObject
|
|||||||
QVERIFY( !res );
|
QVERIFY( !res );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void testSuggestedReferenceLayer()
|
||||||
|
{
|
||||||
|
QgsAlignRaster align;
|
||||||
|
|
||||||
|
QCOMPARE( align.suggestedReferenceLayer(), -1 );
|
||||||
|
|
||||||
|
QgsAlignRaster::List rasters;
|
||||||
|
rasters << QgsAlignRaster::Item( SRC_FILE, QString() );
|
||||||
|
align.setRasters( rasters );
|
||||||
|
|
||||||
|
QCOMPARE( align.suggestedReferenceLayer(), 0 );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
QTEST_MAIN( TestAlignRaster )
|
QTEST_MAIN( TestAlignRaster )
|
||||||
|
Loading…
x
Reference in New Issue
Block a user