[gdal-dev] Re: Slope in gdaldem

Stephen Mather mather.stephen at gmail.com
Thu Dec 15 22:31:41 EST 2011


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

On Thu, Dec 15, 2011 at 10:05 PM, Joaquim Luis <jluis at ualg.pt> wrote:

>
>
>>    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 (key < 0)
>>     {
>>        key = afWin[4] - pafLocalMax;
>>     }
>>
>>
> Stephen
>
> 'key' can never be negative because pafLocalMin is computed from 'afWin'
> alone. The min val it can have is 0, when the minimum value is the central
> node itself.
>
> Joaquim
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20111215/6219f8bf/attachment-0001.html


More information about the gdal-dev mailing list