main.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /****************************************************************************
  2. *
  3. * MODULE: r.coin
  4. *
  5. * AUTHOR(S): Michael O'Shea - CERL
  6. * Michael Shapiro - CERL
  7. *
  8. * PURPOSE: Calculates the coincidence of two raster map layers.
  9. *
  10. * COPYRIGHT: (C) 2006 by the GRASS Development Team
  11. *
  12. * This program is free software under the GNU General Public
  13. * License (>=v2). Read the file COPYING that comes with GRASS
  14. * for details.
  15. *
  16. ***************************************************************************/
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <grass/gis.h>
  20. #include <grass/raster.h>
  21. #include <grass/glocale.h>
  22. #include "coin.h"
  23. struct Cell_head window;
  24. const char *title1, *title2;
  25. double window_cells;
  26. double window_area;
  27. struct stats_table *table;
  28. long *catlist1, *catlist2;
  29. int no_data1, no_data2;
  30. int Rndex, Cndex;
  31. const char *dumpname;
  32. const char *statname;
  33. FILE *dumpfile;
  34. const char *map1name, *map2name;
  35. int ncat1, ncat2;
  36. char *fill, *midline;
  37. int main(int argc, char *argv[])
  38. {
  39. struct GModule *module;
  40. struct
  41. {
  42. struct Option *map1, *map2, *units;
  43. } parm;
  44. struct
  45. {
  46. struct Flag *w;
  47. } flag;
  48. fill =
  49. " ";
  50. midline =
  51. "------------------------------------------------------------------------------------------------------------------------------------";
  52. G_gisinit(argv[0]);
  53. module = G_define_module();
  54. G_add_keyword(_("raster"));
  55. G_add_keyword(_("statistics"));
  56. module->description =
  57. _("Tabulates the mutual occurrence (coincidence) "
  58. "of categories for two raster map layers.");
  59. parm.map1 = G_define_standard_option(G_OPT_R_INPUT);
  60. parm.map1->key = "first";
  61. parm.map1->description = _("Name of first input raster map");
  62. parm.map2 = G_define_standard_option(G_OPT_R_INPUT);
  63. parm.map2->key = "second";
  64. parm.map2->description = _("Name of second input raster map");
  65. parm.units = G_define_option();
  66. parm.units->key = "units";
  67. parm.units->required = YES;
  68. parm.units->type = TYPE_STRING;
  69. parm.units->label = _("Unit of measure");
  70. parm.units->description =
  71. _("c(ells), p(ercent), x(percent of category [column]), "
  72. "y(percent of category [row]), a(cres), h(ectares), "
  73. "k(square kilometers), m(square miles)");
  74. parm.units->options = "c,p,x,y,a,h,k,m";
  75. flag.w = G_define_flag();
  76. flag.w->key = 'w';
  77. flag.w->description = _("Wide report, 132 columns (default: 80)");
  78. if (G_parser(argc, argv))
  79. exit(EXIT_FAILURE);
  80. G_get_window(&window);
  81. /* now make a temorary region with the same boundaries only 1 x 1 */
  82. window.rows = 1;
  83. window.cols = 1;
  84. G_adjust_Cell_head(&window, 1, 1);
  85. G_set_window(&window);
  86. G_begin_cell_area_calculations();
  87. window_area = G_area_of_cell_at_row(0);
  88. /* restore region back to the original */
  89. G_get_window(&window);
  90. Rast_set_window(&window);
  91. dumpname = G_tempfile();
  92. statname = G_tempfile();
  93. window_cells = Rast_window_rows() * Rast_window_cols();
  94. map1name = parm.map1->answer;
  95. map2name = parm.map2->answer;
  96. if (!G_find_raster2(map1name, ""))
  97. G_fatal_error(_("Raster map <%s> not found"), map1name);
  98. if (!G_find_raster2(map2name, ""))
  99. G_fatal_error(_("Raster map <%s> not found"), map2name);
  100. make_coin();
  101. print_coin(*parm.units->answer, flag.w->answer ? 132 : 80, 0);
  102. remove(dumpname);
  103. remove(statname);
  104. exit(EXIT_SUCCESS);
  105. }