[gdal-dev] Re: Slope in gdaldem

Joaquim Luis jluis at ualg.pt
Thu Dec 15 22:51:10 EST 2011


On 16-12-2011 03:31, Stephen Mather wrote:
> Hmm.  I don't follow?  The revision would be this:
>
> float GDALSlopeHydroAlg (float* afWin, float fDstNoDataValue, void* pData)
>
> {
>     // Hydrologic Slope is the max
>     //  local slope btw center cell and adjacent cells
>
>     const double radiansToDegrees = 180.0 / M_PI;
>     GDALSlopeAlgData* psData = (GDALSlopeAlgData*)pData;
>                 double key;
>
>     float pafLocalMin = afWin[0];
>      float pafLocalMax = afWin[0];
>
>     for ( int k = 1; k < 9; k++)
>     {
>         if (afWin[k] < pafLocalMin)
>         {
>             pafLocalMin=afWin[k];
>         }
>
>         if (afWin[k] > pafLocalMax)
>         {
>             pafLocalMax=afWin[k];
>         }
>     }
>
>     key = afWin[4] - pafLocalMin;
>
>     if (psData->slopeFormat == 1)
>         return (float) (atan(sqrt(key) / (2*psData->scale)) * 
> radiansToDegrees);
>     else
>         return (float) (100*(sqrt(key) / (2*psData->scale)));
> }
>
> But, clearly I'm not understanding something about the window.
>

Steve, there are more things I do not understand either. What is 
'psData->scale'? Is it the grid cell size?
So, if 'pafLocalMin' is on one of the 4 corners the distance is not cell 
size (let's call it DX) but instead sqrt(DX*DX + DX*DX).
And what if data is in geogs? Than DX is clearly different from DY and 
changes with latitude. You need to take that into account to compute the 
slope.

Joaquim


More information about the gdal-dev mailing list