Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
add option to export mesh dataset to raster block (for processing algs)
- Loading branch information
1 parent
8db14d8
commit 7423a74
Showing
6 changed files
with
264 additions
and
7 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
python/core/auto_generated/mesh/qgsmeshlayerinterpolator.sip.in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/mesh/qgsmeshlayerinterpolator.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
|
||
|
||
|
||
|
||
%ModuleHeaderCode | ||
#include "qgsmeshlayerinterpolator.h" | ||
%End | ||
|
||
|
||
|
||
|
||
namespace QgsMeshUtils | ||
{ | ||
|
||
QgsRasterBlock *exportRasterBlock( | ||
const QgsMeshLayer &layer, | ||
const QgsMeshDatasetIndex &datasetIndex, | ||
const QgsCoordinateReferenceSystem &destination, | ||
const QgsCoordinateTransformContext &context, | ||
double mapUnitsPerPixel, | ||
const QgsRectangle &extent, | ||
QgsRasterBlockFeedback *feedback = 0 | ||
) /Factory/; | ||
%Docstring | ||
Exports mesh layer's dataset values as raster block | ||
|
||
:param layer: mesh layer | ||
:param datasetIndex: index from layer defining group and dataset (time) to export | ||
:param destination: destination/map CRS. Used to create triangular mesh from native mesh | ||
:param context: Transform context to transform layer CRS to destination CRS | ||
:param mapUnitsPerPixel: map units per pixel for block | ||
:param extent: extent of block in destination CRS | ||
:param feedback: optional raster feedback object for cancelation/preview | ||
|
||
:return: raster block with Float.64 values. None on error | ||
|
||
.. versionadded:: 3.6 | ||
%End | ||
}; | ||
|
||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/mesh/qgsmeshlayerinterpolator.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/*************************************************************************** | ||
testqgsmeshlayerinterpolator.cpp | ||
-------------------------------- | ||
Date : January 2019 | ||
Copyright : (C) 2019 by Peter Petrik | ||
Email : zilolv at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
#include "qgstest.h" | ||
#include <QObject> | ||
#include <QString> | ||
#include <QApplication> | ||
|
||
//qgis includes... | ||
#include <qgsrasterblock.h> | ||
#include <qgsmeshlayer.h> | ||
#include <qgsmeshlayerinterpolator.h> | ||
#include <qgsapplication.h> | ||
#include <qgscoordinatereferencesystem.h> | ||
#include <qgsproject.h> | ||
|
||
/** | ||
* \ingroup UnitTests | ||
* This is a unit test for the TestQgsMeshLayerInterpolator class | ||
*/ | ||
class TestQgsMeshLayerInterpolator: public QObject | ||
{ | ||
Q_OBJECT | ||
private slots: | ||
void initTestCase();// will be called before the first testfunction is executed. | ||
void cleanupTestCase();// will be called after the last testfunction was executed. | ||
void init() {} // will be called before each testfunction is executed. | ||
void cleanup() {} // will be called after every testfunction. | ||
|
||
void testExportRasterBand(); | ||
private: | ||
QString mTestDataDir; | ||
}; | ||
|
||
//runs before all tests | ||
void TestQgsMeshLayerInterpolator::initTestCase() | ||
{ | ||
// init QGIS's paths - true means that all path will be inited from prefix | ||
QgsApplication::init(); | ||
QgsApplication::initQgis(); | ||
QgsApplication::showSettings(); | ||
mTestDataDir = QStringLiteral( TEST_DATA_DIR ); //defined in CmakeLists.txt | ||
} | ||
//runs after all tests | ||
void TestQgsMeshLayerInterpolator::cleanupTestCase() | ||
{ | ||
QgsApplication::exitQgis(); | ||
} | ||
|
||
void TestQgsMeshLayerInterpolator::testExportRasterBand() | ||
{ | ||
QgsMeshLayer memoryLayer( mTestDataDir + "/mesh/quad_and_triangle.2dm", | ||
"Triangle and Quad Mdal", | ||
"mdal" ); | ||
QVERIFY( memoryLayer.isValid() ); | ||
QgsMeshDatasetIndex index( 0, 0 ); // bed elevation | ||
memoryLayer.setCrs( QgsCoordinateReferenceSystem::fromEpsgId( 27700 ) ); | ||
|
||
QgsRasterBlock *block = QgsMeshUtils::exportRasterBlock( | ||
memoryLayer, | ||
index, | ||
memoryLayer.crs(), | ||
QgsProject::instance()->transformContext(), | ||
100, | ||
memoryLayer.extent() | ||
); | ||
|
||
QCOMPARE( block->width(), 20 ); | ||
QCOMPARE( block->height(), 10 ); | ||
QVERIFY( block->isValid() ); | ||
QVERIFY( !block->isEmpty() ); | ||
QCOMPARE( block->dataType(), Qgis::Float64 ); | ||
QVERIFY( block->hasNoDataValue() ); | ||
QVERIFY( block->hasNoData() ); | ||
|
||
QCOMPARE( block->value( 0, 0 ), 10.0 ); | ||
QCOMPARE( block->value( 5, 5 ), 35.0 ); | ||
QVERIFY( block->isNoData( 10, 10 ) ); | ||
} | ||
|
||
QGSTEST_MAIN( TestQgsMeshLayerInterpolator ) | ||
#include "testqgsmeshlayerinterpolator.moc" |