[GRASS-SVN] r31674 - in grass-addons/gipe: . r.soilusda2tex
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Jun 11 04:26:23 EDT 2008
Author: ychemin
Date: 2008-06-11 04:26:23 -0400 (Wed, 11 Jun 2008)
New Revision: 31674
Added:
grass-addons/gipe/r.soilusda2tex/
grass-addons/gipe/r.soilusda2tex/Makefile
grass-addons/gipe/r.soilusda2tex/description.html
grass-addons/gipe/r.soilusda2tex/main.c
grass-addons/gipe/r.soilusda2tex/usda2pclay.c
grass-addons/gipe/r.soilusda2tex/usda2psand.c
grass-addons/gipe/r.soilusda2tex/usda2psilt.c
Modified:
grass-addons/gipe/gmmenu.tcl
grass-addons/gipe/menudata.py
Log:
Added a module to convert USDA soil classes into fractions of sand, silt and clay (3 output layers)
Modified: grass-addons/gipe/gmmenu.tcl
===================================================================
--- grass-addons/gipe/gmmenu.tcl 2008-06-11 07:12:10 UTC (rev 31673)
+++ grass-addons/gipe/gmmenu.tcl 2008-06-11 08:26:23 UTC (rev 31674)
@@ -297,7 +297,10 @@
{command {[G_msg "Thin"]} {} "r.thin: Thin linear features" {} -command {execute r.thin }}
}}
{separator}
- {cascad {[G_msg "Universal Soil Loss Equation (USLE)"]} {} "" $tmenu {
+ {cascad {[G_msg "Soil and USLE"]} {} "" $tmenu {
+ {command {[G_msg "USDA soil classes to soil fractions"]} {} "r.soilusda2tex" {} -command {execute r.soilusda2tex }}
+ {command {[G_msg "Soil Fractions to soil properties"]} {} "r.soiltex2prop" {} -command {execute r.soiltex2prop }}
+ {separator}
{command {[G_msg "Rainfall Erosivity (R)"]} {} "r.usler" {} -command {execute r.usler }}
{command {[G_msg "Soil Erodibility (K)"]} {} "r.uslek" {} -command {execute r.uslek }}
{command {[G_msg "Length Slope and Slope (LS)"]} {} "r.watershed" {} -command {execute r.watershed }}
Modified: grass-addons/gipe/menudata.py
===================================================================
--- grass-addons/gipe/menudata.py 2008-06-11 07:12:10 UTC (rev 31673)
+++ grass-addons/gipe/menudata.py 2008-06-11 08:26:23 UTC (rev 31674)
@@ -612,10 +612,6 @@
_("Textural features analysis"),
"self.OnMenuCmd",
"r.texture"),
- (_("Soil Texture->properties"),
- _("Soil Texture to Ksat/Porosity/Hf"),
- "self.OnMenuCmd",
- "r.soiltex2prop"),
("","","", ""),
(_("Visibility"),
_("Visibility and line of sight"),
@@ -639,7 +635,16 @@
)
),
("","","", ""),
- (_("Universal Soil Loss Equation (USLE)"), (
+ (_("Soil and USLE"), (
+ (_("Soil Classes->Soil Fractions"),
+ _("Soil USDA classes to sand,silt,clay"),
+ "self.OnMenuCmd",
+ "r.soilusda2tex"),
+ (_("Soil Texture->properties"),
+ _("Soil Texture to Ksat/Porosity/Hf"),
+ "self.OnMenuCmd",
+ "r.soiltex2prop"),
+ ("","","", ""),
(_("Rainfall Erosivity (R)"),
_("Rainfall Erosivity (R)"),
"self.OnMenuCmd",
Added: grass-addons/gipe/r.soilusda2tex/Makefile
===================================================================
--- grass-addons/gipe/r.soilusda2tex/Makefile (rev 0)
+++ grass-addons/gipe/r.soilusda2tex/Makefile 2008-06-11 08:26:23 UTC (rev 31674)
@@ -0,0 +1,10 @@
+MODULE_TOPDIR = ../..
+
+PGM = r.soilusda2tex
+
+LIBES = $(GISLIB)
+DEPENDENCIES = $(GISDEP)
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+default: cmd
Added: grass-addons/gipe/r.soilusda2tex/description.html
===================================================================
--- grass-addons/gipe/r.soilusda2tex/description.html (rev 0)
+++ grass-addons/gipe/r.soilusda2tex/description.html 2008-06-11 08:26:23 UTC (rev 31674)
@@ -0,0 +1,40 @@
+<H2>DESCRIPTION</H2>
+
+<EM>r.soilusda2tex</EM> calculates the soil texture fractions using USDA soil classes.
+
+It outputs soil texture proportions (sand, silt, clay) in range [0.0-1.0].
+<H2>NOTES</H2>
+
+Soil Classes
+------------
+0 clay
+1 sandy clay
+2 silty clay
+3 sandy clay loam
+4 clay loam
+5 silty clay loam
+6 sand
+7 loamy sand
+8 sandy loam
+9 loam
+10 silt loam
+11 silt
+
+<H2>TODO</H2>
+
+
+<H2>SEE ALSO</H2>
+
+<em>
+<A HREF="r.uslek.html">r.uslek</A><br>
+<A HREF="r.soiltex2prop.html">r.soiltex2prop</A><br>
+</em>
+
+
+<H2>AUTHORS</H2>
+
+Yann Chemin, International Rice Research Institute, The Philippines<BR>
+
+
+<p>
+<i>Last changed: $Date: 2008/06/11 15:20:43 $</i>
Added: grass-addons/gipe/r.soilusda2tex/main.c
===================================================================
--- grass-addons/gipe/r.soilusda2tex/main.c (rev 0)
+++ grass-addons/gipe/r.soilusda2tex/main.c 2008-06-11 08:26:23 UTC (rev 31674)
@@ -0,0 +1,183 @@
+/****************************************************************************
+ *
+ * MODULE: r.soilusda2tex
+ * AUTHOR(S): Yann Chemin - yann.chemin at gmail.com
+ * PURPOSE: Transforms USDA 1951 (p209) soil classes into
+ * maps of percentage of texture (sand/clay/silt).
+ *
+ * COPYRIGHT: (C) 2008 by the GRASS Development Team
+ *
+ * This program is free software under the GNU General Public
+ * License (>=v2). Read the file COPYING that comes with GRASS
+ * for details.
+ *
+ *****************************************************************************/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
+
+#define POLYGON_DIMENSION 20
+double usda2psand(int texture);
+double usda2psilt(int texture);
+double usda2pclay(int texture);
+
+int main(int argc, char *argv[])
+{
+ struct Cell_head cellhd; //region+header info
+ char *mapset; // mapset name
+ int nrows, ncols;
+ int row,col;
+
+ struct GModule *module;
+ struct Option *input1,*output1,*output2,*output3,*output4;
+
+ struct Flag *flag1;
+ struct History history; //metadata
+
+ /************************************/
+ /* FMEO Declarations*****************/
+ char *name; // input raster name
+ char *result1,*result2,*result3; //output raster name
+ //File Descriptors
+ int infd_soilusda;
+ int outfd1, outfd2, outfd3;
+
+ char *soilusda;
+
+ int i=0,j=0;
+
+ void *inrast_soilusda;
+ DCELL *outrast1, *outrast2, *outrast3;
+ RASTER_MAP_TYPE data_type_output=DCELL_TYPE;
+ RASTER_MAP_TYPE data_type_soilusda;
+
+ /************************************/
+ G_gisinit(argv[0]);
+
+ module = G_define_module();
+ module->keywords = _("soil, USDA, classification");
+ module->description = _("USDA Soil classes conversion to texture fractions");
+
+ /* Define the different options */
+ input1 = G_define_standard_option(G_OPT_R_INPUT) ;
+ input1->key = _("soilusda");
+ input1->description=_("Name of the USDA Soil classes reclassified [1-12]");
+
+ output1 = G_define_standard_option(G_OPT_R_OUTPUT) ;
+ output1->key =_("pclay");
+ output1->description=_("Name of the Soil clay fraction layer [0.0-1.0]");
+ output1->answer =_("pclay");
+
+ output2 = G_define_standard_option(G_OPT_R_OUTPUT) ;
+ output2->key =_("psilt");
+ output2->description=_("Name of the Soil silt fraction layer [0.0-1.0]");
+ output2->answer =_("psilt");
+
+ output3 = G_define_standard_option(G_OPT_R_OUTPUT) ;
+ output3->key =_("psand");
+ output3->description=_("Name of the Soil sand fraction layer [0.0-1.0]");
+ output3->answer =_("psand");
+
+ /********************/
+ if (G_parser(argc, argv))
+ exit (EXIT_FAILURE);
+
+ soilusda = input1->answer;
+ result1 = output1->answer;
+ result2 = output2->answer;
+ result3 = output3->answer;
+
+ /***************************************************/
+ mapset = G_find_cell2(soilusda, "");
+ if (mapset == NULL) {
+ G_fatal_error(_("cell file [%s] not found"), soilusda);
+ }
+ data_type_soilusda = G_raster_map_type(soilusda,mapset);
+ if ( (infd_soilusda = G_open_cell_old (soilusda,mapset)) < 0)
+ G_fatal_error (_("Cannot open cell file [%s]"), soilusda);
+ if (G_get_cellhd (soilusda, mapset, &cellhd) < 0)
+ G_fatal_error (_("Cannot read file header of [%s])"), soilusda);
+ inrast_soilusda = G_allocate_raster_buf(data_type_soilusda);
+ /***************************************************/
+ G_debug(3, "number of rows %d",cellhd.rows);
+ nrows = G_window_rows();
+ ncols = G_window_cols();
+ outrast1 = G_allocate_raster_buf(data_type_output);
+ outrast2 = G_allocate_raster_buf(data_type_output);
+ outrast3 = G_allocate_raster_buf(data_type_output);
+ /* Create New raster files */
+ if ( (outfd1 = G_open_raster_new (result1,data_type_output)) < 0)
+ G_fatal_error(_("Could not open <%s>"),result1);
+ if ( (outfd2 = G_open_raster_new (result2,data_type_output)) < 0)
+ G_fatal_error(_("Could not open <%s>"),result2);
+ if ( (outfd3 = G_open_raster_new (result3,data_type_output)) < 0)
+ G_fatal_error(_("Could not open <%s>"),result3);
+ /* Process pixels */
+ for (row = 0; row < nrows; row++)
+ {
+ DCELL d;
+ DCELL d_sand;
+ DCELL d_clay;
+ DCELL d_silt;
+ DCELL d_soilusda;
+ G_percent(row,nrows,2);
+ /* read soil classes [0-11] input map */
+ if(G_get_raster_row(infd_soilusda,inrast_soilusda,row,data_type_soilusda)<0)
+ G_fatal_error(_("Could not read from <%s>"),soilusda);
+ /*process the data */
+ for (col=0; col < ncols; col++)
+ {
+ d_soilusda = ((DCELL *) inrast_soilusda)[col];
+ // printf("inrast_pomat = %f\n", d_om);
+ if(G_is_d_null_value(&d_soilusda)){
+ G_set_d_null_value(&outrast1[col],1);
+ G_set_d_null_value(&outrast2[col],1);
+ G_set_d_null_value(&outrast3[col],1);
+ }else {
+ /************************************/
+ /* convert to prct */
+ d_clay = usda2pclay(d_soilusda);
+ d_silt = usda2psilt(d_soilusda);
+ d_sand = usda2psand(d_soilusda);
+ /************************************/
+ outrast1[col] = d_clay;
+ outrast2[col] = d_silt;
+ outrast3[col] = d_sand;
+ }
+ }
+ if (G_put_raster_row (outfd1, outrast1, data_type_output) < 0)
+ G_fatal_error(_("Cannot write to output raster file clay"));
+ if (G_put_raster_row (outfd2, outrast2, data_type_output) < 0)
+ G_fatal_error(_("Cannot write to output raster file silt"));
+ if (G_put_raster_row (outfd3, outrast3, data_type_output) < 0)
+ G_fatal_error(_("Cannot write to output raster file sand"));
+ }
+
+ G_free (inrast_soilusda);
+ G_close_cell (infd_soilusda);
+
+ G_free (outrast1);
+ G_close_cell (outfd1);
+ G_free (outrast2);
+ G_close_cell (outfd2);
+ G_free (outrast3);
+ G_close_cell (outfd3);
+
+ G_short_history(result1, "raster", &history);
+ G_command_history(&history);
+ G_write_history(result1,&history);
+
+ G_short_history(result2, "raster", &history);
+ G_command_history(&history);
+ G_write_history(result2,&history);
+
+ G_short_history(result3, "raster", &history);
+ G_command_history(&history);
+ G_write_history(result3,&history);
+
+ exit(EXIT_SUCCESS);
+}
+
Added: grass-addons/gipe/r.soilusda2tex/usda2pclay.c
===================================================================
--- grass-addons/gipe/r.soilusda2tex/usda2pclay.c (rev 0)
+++ grass-addons/gipe/r.soilusda2tex/usda2pclay.c 2008-06-11 08:26:23 UTC (rev 31674)
@@ -0,0 +1,74 @@
+#include<stdio.h>
+
+// From FAOSOIL CD, after USDA 1951, p209
+
+double usda2pclay(int texture){
+ double psand;
+ double psilt;
+ double pclay;
+ if(texture==0){
+// printf("clay\n");
+ psand=0.2;
+ psilt=0.2;
+ pclay=0.8;
+ } else if (texture==1){
+// printf("sandy clay\n");
+ psand=0.5;
+ psilt=0.1;
+ pclay=0.4;
+ } else if (texture==2){
+// printf("silty clay\n");
+ psand=0.05;
+ psilt=0.5;
+ pclay=0.45;
+ } else if (texture==3){
+// printf("sandy clay loam\n");
+ psand=0.6;
+ psilt=0.15;
+ pclay=0.25;
+ } else if (texture==4){
+// printf("clay loam\n");
+ psand=0.3;
+ psilt=0.35;
+ pclay=0.35;
+ } else if (texture==5){
+// printf("silty clay loam\n");
+ psand=0.1;
+ psilt=0.55;
+ pclay=0.35;
+ } else if (texture==6){
+// printf("sand\n");
+ psand=0.9;
+ psilt=0.05;
+ pclay=0.05;
+ } else if (texture==7){
+// printf("loamy sand\n");
+ psand=0.85;
+ psilt=0.05;
+ pclay=0.1;
+ } else if (texture==8){
+// printf("sandy loam\n");
+ psand=0.65;
+ psilt=0.25;
+ pclay=0.1;
+ } else if (texture==9){
+// printf("loam\n");
+ psand=0.4;
+ psilt=0.4;
+ pclay=0.2;
+ } else if (texture==10){
+// printf("silt loam\n");
+ psand=0.2;
+ psilt=0.65;
+ pclay=0.15;
+ } else if (texture==11){
+// printf("silt\n");
+ psand=0.05;
+ psilt=0.9;
+ pclay=0.05;
+ } else {
+ //printf("i am confused here...Can you do it yourself please?\n");
+ }
+ return pclay;
+}
+
Added: grass-addons/gipe/r.soilusda2tex/usda2psand.c
===================================================================
--- grass-addons/gipe/r.soilusda2tex/usda2psand.c (rev 0)
+++ grass-addons/gipe/r.soilusda2tex/usda2psand.c 2008-06-11 08:26:23 UTC (rev 31674)
@@ -0,0 +1,74 @@
+#include<stdio.h>
+
+// From FAOSOIL CD, after USDA 1951, p209
+
+double usda2psand(int texture){
+ double psand;
+ double psilt;
+ double pclay;
+ if(texture==0){
+// printf("clay\n");
+ psand=0.2;
+ psilt=0.2;
+ pclay=0.8;
+ } else if (texture==1){
+// printf("sandy clay\n");
+ psand=0.5;
+ psilt=0.1;
+ pclay=0.4;
+ } else if (texture==2){
+// printf("silty clay\n");
+ psand=0.05;
+ psilt=0.5;
+ pclay=0.45;
+ } else if (texture==3){
+// printf("sandy clay loam\n");
+ psand=0.6;
+ psilt=0.15;
+ pclay=0.25;
+ } else if (texture==4){
+// printf("clay loam\n");
+ psand=0.3;
+ psilt=0.35;
+ pclay=0.35;
+ } else if (texture==5){
+// printf("silty clay loam\n");
+ psand=0.1;
+ psilt=0.55;
+ pclay=0.35;
+ } else if (texture==6){
+// printf("sand\n");
+ psand=0.9;
+ psilt=0.05;
+ pclay=0.05;
+ } else if (texture==7){
+// printf("loamy sand\n");
+ psand=0.85;
+ psilt=0.05;
+ pclay=0.1;
+ } else if (texture==8){
+// printf("sandy loam\n");
+ psand=0.65;
+ psilt=0.25;
+ pclay=0.1;
+ } else if (texture==9){
+// printf("loam\n");
+ psand=0.4;
+ psilt=0.4;
+ pclay=0.2;
+ } else if (texture==10){
+// printf("silt loam\n");
+ psand=0.2;
+ psilt=0.65;
+ pclay=0.15;
+ } else if (texture==11){
+// printf("silt\n");
+ psand=0.05;
+ psilt=0.9;
+ pclay=0.05;
+ } else {
+ //printf("i am confused here...Can you do it yourself please?\n");
+ }
+ return psand;
+}
+
Added: grass-addons/gipe/r.soilusda2tex/usda2psilt.c
===================================================================
--- grass-addons/gipe/r.soilusda2tex/usda2psilt.c (rev 0)
+++ grass-addons/gipe/r.soilusda2tex/usda2psilt.c 2008-06-11 08:26:23 UTC (rev 31674)
@@ -0,0 +1,74 @@
+#include<stdio.h>
+
+// From FAOSOIL CD, after USDA 1951, p209
+
+double usda2psilt(int texture){
+ double psand;
+ double psilt;
+ double pclay;
+ if(texture==0){
+// printf("clay\n");
+ psand=0.2;
+ psilt=0.2;
+ pclay=0.8;
+ } else if (texture==1){
+// printf("sandy clay\n");
+ psand=0.5;
+ psilt=0.1;
+ pclay=0.4;
+ } else if (texture==2){
+// printf("silty clay\n");
+ psand=0.05;
+ psilt=0.5;
+ pclay=0.45;
+ } else if (texture==3){
+// printf("sandy clay loam\n");
+ psand=0.6;
+ psilt=0.15;
+ pclay=0.25;
+ } else if (texture==4){
+// printf("clay loam\n");
+ psand=0.3;
+ psilt=0.35;
+ pclay=0.35;
+ } else if (texture==5){
+// printf("silty clay loam\n");
+ psand=0.1;
+ psilt=0.55;
+ pclay=0.35;
+ } else if (texture==6){
+// printf("sand\n");
+ psand=0.9;
+ psilt=0.05;
+ pclay=0.05;
+ } else if (texture==7){
+// printf("loamy sand\n");
+ psand=0.85;
+ psilt=0.05;
+ pclay=0.1;
+ } else if (texture==8){
+// printf("sandy loam\n");
+ psand=0.65;
+ psilt=0.25;
+ pclay=0.1;
+ } else if (texture==9){
+// printf("loam\n");
+ psand=0.4;
+ psilt=0.4;
+ pclay=0.2;
+ } else if (texture==10){
+// printf("silt loam\n");
+ psand=0.2;
+ psilt=0.65;
+ pclay=0.15;
+ } else if (texture==11){
+// printf("silt\n");
+ psand=0.05;
+ psilt=0.9;
+ pclay=0.05;
+ } else {
+ //printf("i am confused here...Can you do it yourself please?\n");
+ }
+ return psilt;
+}
+
More information about the grass-commit
mailing list