[GRASS-SVN] r62891 - grass/branches/releasebranch_7_0/raster/r.uslek
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Nov 24 09:16:14 PST 2014
Author: neteler
Date: 2014-11-24 09:16:14 -0800 (Mon, 24 Nov 2014)
New Revision: 62891
Modified:
grass/branches/releasebranch_7_0/raster/r.uslek/main.c
grass/branches/releasebranch_7_0/raster/r.uslek/prct2tex.c
grass/branches/releasebranch_7_0/raster/r.uslek/r.uslek.html
grass/branches/releasebranch_7_0/raster/r.uslek/tex2usle_k.c
Log:
r.uslek: sync to trunk (bugfixes; examples)
Modified: grass/branches/releasebranch_7_0/raster/r.uslek/main.c
===================================================================
--- grass/branches/releasebranch_7_0/raster/r.uslek/main.c 2014-11-24 17:15:23 UTC (rev 62890)
+++ grass/branches/releasebranch_7_0/raster/r.uslek/main.c 2014-11-24 17:16:14 UTC (rev 62891)
@@ -1,4 +1,3 @@
-
/****************************************************************************
*
* MODULE: r.uslek
@@ -19,6 +18,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <math.h>
#include <grass/gis.h>
#include <grass/raster.h>
#include <grass/glocale.h>
@@ -136,17 +136,19 @@
else {
/***************************************/
/* In case some map input not standard */
- if ((d_sand + d_clay + d_silt) != 1.0)
+ if (fabs(d_sand + d_clay + d_silt - 1.0) > GRASS_EPSILON )
Rast_set_d_null_value(&outrast[col], 1);
/* if OM==NULL then make it 0.0 */
- else if (Rast_is_d_null_value(&d_om))
- d_om = 0.0;
else {
- /************************************/
+ if (Rast_is_d_null_value(&d_om))
+ d_om = 0.0;
+ /************************************/
/* convert to usle_k */
d = (double)prct2tex(d_sand, d_clay, d_silt);
- d = tex2usle_k((int)d, d_om);
- outrast[col] = d;
+ if(d > 11.0) /* 11 is highest class */
+ Rast_set_d_null_value(&outrast[col], 1);
+ else
+ outrast[col] = tex2usle_k((int)d, d_om);
}
}
}
Modified: grass/branches/releasebranch_7_0/raster/r.uslek/prct2tex.c
===================================================================
--- grass/branches/releasebranch_7_0/raster/r.uslek/prct2tex.c 2014-11-24 17:15:23 UTC (rev 62890)
+++ grass/branches/releasebranch_7_0/raster/r.uslek/prct2tex.c 2014-11-24 17:16:14 UTC (rev 62891)
@@ -1,4 +1,5 @@
-#include<stdio.h>
+#include <stdio.h>
+#include <grass/gis.h>
#define POLYGON_DIMENSION 20
/* From FAOSOIL CD, after USDA 1951, p209 */
@@ -15,8 +16,8 @@
double t2_y, double t2_z, double t3_x, double t3_y,
double t3_z)
{
- /*G_message("in function: sand=%5.3f clay=%5.3f silt=%5.3f",
- point_x,point_y,point_z); */
+ G_debug(1,"point_in_triangle: sand=%5.3f clay=%5.3f silt=%5.3f",
+ point_x,point_y,point_z);
double answer;
double answer1_x, answer1_y, answer1_z;
double answer2_x, answer2_y, answer2_z;
@@ -100,7 +101,7 @@
int prct2tex(double sand_input, double clay_input, double silt_input)
{
- /*G_message("%5.3f||%5.3f||%5.3f",sand_input,clay_input,silt_input); */
+ G_debug(1,"%5.3f||%5.3f||%5.3f",sand_input,clay_input,silt_input);
/* set up index for soil texture classes */
int index = 20;
@@ -660,32 +661,32 @@
/* G_message("Silt: index labelled as 11"); */
}
}
- /* if(index==0){
- G_message("clay");
+ if(index==0){
+ G_debug(1,"clay");
} else if (index==1){
- G_message("sandy clay");
+ G_debug(1,"sandy clay");
} else if (index==2){
- G_message("silty clay");
+ G_debug(1,"silty clay");
} else if (index==3){
- G_message("sandy clay loam");
+ G_debug(1,"sandy clay loam");
} else if (index==4){
- G_message("clay loam");
+ G_debug(1,"clay loam");
} else if (index==5){
- G_message("silty clay loam");
+ G_debug(1,"silty clay loam");
} else if (index==6){
- G_message("sand");
+ G_debug(1,"sand");
} else if (index==7){
- G_message("loamy sand");
+ G_debug(1,"loamy sand");
} else if (index==8){
- G_message("sandy loam");
+ G_debug(1,"sandy loam");
} else if (index==9){
- G_message("loam");
+ G_debug(1,"loam");
} else if (index==10){
G_message("silt loam");
} else if (index==11){
- G_message("silt");
+ G_debug(1,"silt");
} else {
- G_message("Unable to allocate class");
- } */
+ G_debug(1,"Unable to allocate class");
+ }
return index;
}
Modified: grass/branches/releasebranch_7_0/raster/r.uslek/r.uslek.html
===================================================================
--- grass/branches/releasebranch_7_0/raster/r.uslek/r.uslek.html 2014-11-24 17:15:23 UTC (rev 62890)
+++ grass/branches/releasebranch_7_0/raster/r.uslek/r.uslek.html 2014-11-24 17:16:14 UTC (rev 62891)
@@ -12,14 +12,51 @@
<h2>NOTES</h2>
<em>r.watershed</em> provides for USLE L, S, LS factors.
-<h2>TODO</h2>
+<h2>EXAMPLE</h2>
+Calculate the USLE K factor (synthetic values, North Carolina sample dataset):
+<div class="code"><pre>
+# NC data: simulation
+g.region rural_1m -p
+
+r.mapcalc "sand = 0.11"
+r.mapcalc "clay = 0.47"
+r.mapcalc "silt = 0.42"
+r.mapcalc "organ = 0.0136"
+
+r.uslek psand=sand pclay=clay psilt=silt pomat=organ output=usle_k
+r.univar usle_k
+# Result: uslek = 0.25
+</pre></div>
+
+<p>
+Example with small variations (condition: d_sand + d_clay + d_silt => 1.0)
+<div class="code"><pre>
+# NC data: simulation
+r.mapcalc -s "sand_r = rand(0.09,0.13)"
+r.mapcalc -s "clay_r = rand(0.45,0.49)"
+r.mapcalc -s "silt_r = rand(0.40,0.44)"
+r.mapcalc -s "organ = rand(0.01,0.70)"
+
+r.mapcalc "temp_sum = sand_r + clay_r + silt_r"
+r.mapcalc "sand = sand_r / temp_sum"
+r.mapcalc "clay = clay_r / temp_sum"
+r.mapcalc "silt = silt_r / temp_sum"
+r.mapcalc "test = sand + clay + silt"
+r.info -r test
+g.remove -f rast name=sand_r,clay_r,silt_r,temp_sum,test
+
+r.uslek psand=sand pclay=clay psilt=silt pomat=organ output=usle_k
+r.univar usle_k
+# Result: uslek = variable values
+</pre></div>
+
<h2>SEE ALSO</h2>
<em>
-<a href="r.usler.html">r.usler</a><br>
-<a href="r.watershed.html">r.watershed</a><br>
+<a href="r.usler.html">r.usler</a>,
+<a href="r.watershed.html">r.watershed</a>
</em>
Modified: grass/branches/releasebranch_7_0/raster/r.uslek/tex2usle_k.c
===================================================================
--- grass/branches/releasebranch_7_0/raster/r.uslek/tex2usle_k.c 2014-11-24 17:15:23 UTC (rev 62890)
+++ grass/branches/releasebranch_7_0/raster/r.uslek/tex2usle_k.c 2014-11-24 17:16:14 UTC (rev 62891)
@@ -1,4 +1,5 @@
-#include<stdio.h>
+#include <stdio.h>
+#include <grass/gis.h>
/* From FAOSOIL CD, after USDA 1951, p209 */
@@ -6,8 +7,8 @@
{
double usle_k = 200.0; /* Initial value */
- /*G_message("texture=%i, om=%5.3f",texture, om_in); */
- if (om_in < 0.5) {
+ G_debug(1,"tex2usle_k: texture=%i, om=%5.3f", texture, om_in);
+ if (om_in < 0.05) {
if (texture == 0) /* G_message("clay"); */
usle_k = 0.29; /*Took max value @0.2 */
else if (texture == 1) /* G_message("sandy clay"); */
@@ -35,7 +36,7 @@
else /*G_message("Unable to allocate class"); */
usle_k = 500.0;/*change value to show it was processed */
}
- else if (om_in >= 0.5 && om_in < 0.2) {
+ else if (om_in >= 0.05 && om_in < 0.2) {
if (texture == 0) /* G_message("clay"); */
usle_k = 0.29; /*Range=[0.13-0.29]@0.2, took max */
else if (texture == 1) /* G_message("sandy clay"); */
More information about the grass-commit
mailing list