Skip to content

Commit fecc59a

Browse files
AsgerPetersenNathanW2
authored andcommitted
Hillshaderenderer: Fix calculation of aspect (#3152)
1 parent 593fa68 commit fecc59a

File tree

1 file changed

+2
-29
lines changed

1 file changed

+2
-29
lines changed

src/core/raster/qgshillshaderenderer.cpp

+2-29
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ QgsRasterBlock *QgsHillshadeRenderer::block( int bandNo, const QgsRectangle &ext
103103
double cellYSize = extent.height() / double( height );
104104
double zenithRad = qMax( 0.0, 90 - mLightAngle ) * M_PI / 180.0;
105105
double azimuthRad = -1 * mLightAzimuth * M_PI / 180.0;
106-
double aspectRad = 0;
107106
double cosZenithRad = cos( zenithRad );
108107
double sinZenithRad = sin( zenithRad );
109108

@@ -121,12 +120,6 @@ QgsRasterBlock *QgsHillshadeRenderer::block( int bandNo, const QgsRectangle &ext
121120
continue;
122121
}
123122

124-
if ( inputBlock->isNoData( i, j ) )
125-
{
126-
outputBlock->setColor( i, j, myDefaultColor );
127-
continue;
128-
}
129-
130123
qgssize iUp, iDown, jLeft, jRight;
131124
if ( i == 0 )
132125
{
@@ -189,26 +182,7 @@ QgsRasterBlock *QgsHillshadeRenderer::block( int bandNo, const QgsRectangle &ext
189182
double derY = calcFirstDerY( x11, x21, x31, x12, x22, x32, x13, x23, x33, cellYSize );
190183

191184
double slope_rad = atan( mZFactor * sqrt( derX * derX + derY * derY ) );
192-
193-
if ( derX != 0 )
194-
{
195-
aspectRad = atan2( derX, -derY );
196-
if ( aspectRad < 0 )
197-
{
198-
aspectRad = 2 * M_PI + aspectRad;
199-
}
200-
}
201-
else if ( derX == 0 )
202-
{
203-
if ( derY > 0 )
204-
{
205-
aspectRad = M_PI_2;
206-
}
207-
else if ( derY < 0 )
208-
{
209-
aspectRad = 2 * M_PI - M_PI_2;
210-
}
211-
}
185+
double aspectRad = atan2( derX, -derY );
212186

213187
double colorvalue = qBound( 0.0, 255.0 * (( cosZenithRad * cos( slope_rad ) ) +
214188
( sinZenithRad * sin( slope_rad ) *
@@ -250,9 +224,8 @@ double QgsHillshadeRenderer::calcFirstDerX( double x11, double x21, double x31,
250224

251225
double QgsHillshadeRenderer::calcFirstDerY( double x11, double x21, double x31, double x12, double x22, double x32, double x13, double x23, double x33, double cellsize )
252226
{
253-
Q_UNUSED( x22 );
254-
Q_UNUSED( x32 );
255227
Q_UNUSED( x21 );
228+
Q_UNUSED( x22 );
256229
Q_UNUSED( x23 );
257230
return (( x31 + x32 + x32 + x33 ) - ( x11 + x12 + x12 + x13 ) ) / ( 8 * -cellsize );
258231
}

0 commit comments

Comments
 (0)