Hmm. I don't follow? The revision would be this:<br><br>float GDALSlopeHydroAlg (float* afWin, float fDstNoDataValue, void* pData)<br><br>{<br> // Hydrologic Slope is the max<br> // local slope btw center cell and adjacent cells<br>
<br> const double radiansToDegrees = 180.0 / M_PI;<br> GDALSlopeAlgData* psData = (GDALSlopeAlgData*)pData; <br> double key;<br> <br> float pafLocalMin = afWin[0];<br> float pafLocalMax = afWin[0];<br>
<br> for ( int k = 1; k < 9; k++)<br> {<br> if (afWin[k] < pafLocalMin)<br> {<br> pafLocalMin=afWin[k];<br> }<br><br> if (afWin[k] > pafLocalMax)<br> {<br> pafLocalMax=afWin[k];<br>
}<br> }<br><br> key = afWin[4] - pafLocalMin;<br> <br> if (psData->slopeFormat == 1)<br> return (float) (atan(sqrt(key) / (2*psData->scale)) * radiansToDegrees);<br> else<br>
return (float) (100*(sqrt(key) / (2*psData->scale)));<br>}<br><br>But, clearly I'm not understanding something about the window.<br><br>Steve<br><br><div class="gmail_quote">On Thu, Dec 15, 2011 at 10:05 PM, Joaquim Luis <span dir="ltr"><<a href="mailto:jluis@ualg.pt">jluis@ualg.pt</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
float pafLocalMin = afWin[0];<br>
float pafLocalMax = afWin[0];<br>
<br>
for ( int k = 1; k < 9; k++)<br>
{<br>
if (afWin[k] < pafLocalMin)<br>
{<br>
pafLocalMin=afWin[k];<br>
}<br>
<br>
if (afWin[k] > pafLocalMax)<br>
{<br>
pafLocalMax=afWin[k];<br>
}<br>
<br>
}<br>
<br>
</blockquote>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
key = afWin[4] - pafLocalMin;<br>
<br>
if (key < 0)<br>
{<br>
key = afWin[4] - pafLocalMax;<br>
}<br>
<br>
</blockquote>
<br></div>
Stephen<br>
<br>
'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.<br><font color="#888888">
<br>
Joaquim<br>
</font></blockquote></div><br>