Skip to content

Commit

Permalink
Hillshaderenderer: Fix calculation of aspect (#3152)
Browse files Browse the repository at this point in the history
  • Loading branch information
AsgerPetersen authored and NathanW2 committed May 30, 2016
1 parent 593fa68 commit fecc59a
Showing 1 changed file with 2 additions and 29 deletions.
31 changes: 2 additions & 29 deletions src/core/raster/qgshillshaderenderer.cpp
Expand Up @@ -103,7 +103,6 @@ QgsRasterBlock *QgsHillshadeRenderer::block( int bandNo, const QgsRectangle &ext
double cellYSize = extent.height() / double( height );
double zenithRad = qMax( 0.0, 90 - mLightAngle ) * M_PI / 180.0;
double azimuthRad = -1 * mLightAzimuth * M_PI / 180.0;
double aspectRad = 0;
double cosZenithRad = cos( zenithRad );
double sinZenithRad = sin( zenithRad );

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

if ( inputBlock->isNoData( i, j ) )
{
outputBlock->setColor( i, j, myDefaultColor );
continue;
}

qgssize iUp, iDown, jLeft, jRight;
if ( i == 0 )
{
Expand Down Expand Up @@ -189,26 +182,7 @@ QgsRasterBlock *QgsHillshadeRenderer::block( int bandNo, const QgsRectangle &ext
double derY = calcFirstDerY( x11, x21, x31, x12, x22, x32, x13, x23, x33, cellYSize );

double slope_rad = atan( mZFactor * sqrt( derX * derX + derY * derY ) );

if ( derX != 0 )
{
aspectRad = atan2( derX, -derY );
if ( aspectRad < 0 )
{
aspectRad = 2 * M_PI + aspectRad;
}
}
else if ( derX == 0 )
{
if ( derY > 0 )
{
aspectRad = M_PI_2;
}
else if ( derY < 0 )
{
aspectRad = 2 * M_PI - M_PI_2;
}
}
double aspectRad = atan2( derX, -derY );

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

double QgsHillshadeRenderer::calcFirstDerY( double x11, double x21, double x31, double x12, double x22, double x32, double x13, double x23, double x33, double cellsize )
{
Q_UNUSED( x22 );
Q_UNUSED( x32 );
Q_UNUSED( x21 );
Q_UNUSED( x22 );
Q_UNUSED( x23 );
return (( x31 + x32 + x32 + x33 ) - ( x11 + x12 + x12 + x13 ) ) / ( 8 * -cellsize );
}
Expand Down

0 comments on commit fecc59a

Please sign in to comment.