-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change how "Get Z value from project terrain" tool is presented in Mesh Editing #60709
base: master
Are you sure you want to change the base?
Changes from 10 commits
3b6d8ff
a109937
9f2bcb8
1581dbd
e98faf2
f5206ed
aa49ad7
4117830
43b56f8
ffe09e1
50bc27f
88ec139
430b0d4
3cd3747
5f9e7b8
1eb57e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,9 @@ | |
#include "qgsmeshlayer.h" | ||
#include "qgsexpression.h" | ||
#include "qgsexpressioncontextutils.h" | ||
|
||
#include "qgsproject.h" | ||
#include "qgsprojectelevationproperties.h" | ||
#include "qgsterrainprovider.h" | ||
|
||
QgsMeshAdvancedEditing::QgsMeshAdvancedEditing() = default; | ||
|
||
|
@@ -610,7 +612,7 @@ QString QgsMeshEditRefineFaces::text() const | |
return QObject::tr( "Refine %n face(s)", nullptr, mInputFaces.count() ); | ||
} | ||
|
||
bool QgsMeshTransformVerticesByExpression::calculate( QgsMeshLayer *layer ) | ||
bool QgsMeshTransformVerticesByExpression::calculate( QgsMeshLayer *layer, QgsProject *project ) | ||
{ | ||
if ( !layer || !layer->meshEditor() || !layer->nativeMesh() ) | ||
return false; | ||
|
@@ -657,14 +659,29 @@ bool QgsMeshTransformVerticesByExpression::calculate( QgsMeshLayer *layer ) | |
} | ||
|
||
QgsExpression expressionZ; | ||
if ( calcZ ) | ||
if ( calcZ || mZFromTerrain ) | ||
{ | ||
expressionZ = QgsExpression( mExpressionZ ); | ||
expressionZ.prepare( &context ); | ||
mNewZValues.reserve( inputCount ); | ||
mOldZValues.reserve( inputCount ); | ||
} | ||
|
||
QgsCoordinateTransform transformation; | ||
const QgsAbstractTerrainProvider *terrainProvider = nullptr; | ||
|
||
if ( mZFromTerrain ) | ||
{ | ||
if ( project ) | ||
{ | ||
JanCaha marked this conversation as resolved.
Show resolved
Hide resolved
|
||
terrainProvider = project->elevationProperties()->terrainProvider(); | ||
if ( terrainProvider ) | ||
{ | ||
transformation = QgsCoordinateTransform( layer->crs(), terrainProvider->crs(), project ); | ||
} | ||
} | ||
} | ||
|
||
for ( int i = 0; i < mInputVertices.count(); ++i ) | ||
{ | ||
const int vertexIndex = mInputVertices.at( i ); | ||
|
@@ -721,7 +738,7 @@ bool QgsMeshTransformVerticesByExpression::calculate( QgsMeshLayer *layer ) | |
return false; | ||
} | ||
|
||
if ( calcZ ) | ||
if ( calcZ && !mZFromTerrain ) | ||
{ | ||
double z = std::numeric_limits<double>::quiet_NaN(); | ||
if ( zvar.isValid() ) | ||
|
@@ -734,6 +751,38 @@ bool QgsMeshTransformVerticesByExpression::calculate( QgsMeshLayer *layer ) | |
mNewZValues.append( z ); | ||
mOldZValues.append( vert.z() ); | ||
} | ||
|
||
if ( mZFromTerrain ) | ||
{ | ||
if ( terrainProvider ) | ||
{ | ||
Comment on lines
+753
to
+756
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Group those two? if ( mZFromTerrain && terrainProvider )
{ |
||
QgsPointXY point; | ||
bool vertexTransformed; | ||
double elevation; | ||
|
||
try | ||
{ | ||
point = transformation.transform( vert.x(), vert.y() ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Harissou has a point, if |
||
vertexTransformed = true; | ||
} | ||
catch ( const QgsCsException & ) | ||
{ | ||
vertexTransformed = false; | ||
} | ||
|
||
if ( vertexTransformed ) | ||
{ | ||
Comment on lines
+771
to
+772
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm, I wonder if it is safe to skip vertices that failed the transform, or if |
||
elevation = terrainProvider->heightAt( point.x(), point.y() ); | ||
// if elevation at terrain provider is NaN, use the original vertex Z value | ||
if ( std::isnan( elevation ) ) | ||
{ | ||
elevation = vert.z(); | ||
} | ||
mNewZValues.append( elevation ); | ||
mOldZValues.append( vert.z() ); | ||
} | ||
} | ||
} | ||
} | ||
|
||
auto transformFunction = [this, layer ]( int vi )-> const QgsMeshVertex | ||
|
@@ -789,3 +838,8 @@ QgsMeshVertex QgsMeshTransformVerticesByExpression::transformedVertex( QgsMeshLa | |
else | ||
return layer->nativeMesh()->vertex( vertexIndex ); | ||
} | ||
|
||
void QgsMeshTransformVerticesByExpression::setZFromTerrain( bool enable ) | ||
{ | ||
mZFromTerrain = enable; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if this is public API, but anyway, could you update these sentences while at it, please? Thanks.