Here's what I've settled on. Let me know your thoughts. The algorithm now correctly calculates angle to lowest nearby point. If it's a local minima, it instead calculates angle to the nearest high point, which will be a negative number, so if the user wants to nullify these or use them in additional processing steps they can. How does adding code to gdal work?<br>
<br>Best,<br>Steve<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><br> key = afWin[4] - pafLocalMin;<br><br> if (key < 0)<br> {<br> key = afWin[4] - pafLocalMax;<br> }<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>}