main.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /****************************************************************************
  2. *
  3. * MODULE: r.recode
  4. * AUTHOR(S): CERL
  5. * Bob Covill <bcovill tekmap.ns.ca>, Hamish Bowman <hamish_b yahoo.com>,
  6. * Jan-Oliver Wagner <jan intevation.de>
  7. * PURPOSE: Recode categorical raster maps
  8. * COPYRIGHT: (C) 1999-2011 by the GRASS Development Team
  9. *
  10. * This program is free software under the GNU General
  11. * Public License (>=v2). Read the file COPYING that
  12. * comes with GRASS for details.
  13. *
  14. *****************************************************************************/
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include <unistd.h>
  19. #include <grass/gis.h>
  20. #include <grass/glocale.h>
  21. #include "global.h"
  22. RASTER_MAP_TYPE in_type;
  23. RASTER_MAP_TYPE out_type;
  24. struct FPReclass rcl_struct;
  25. CELL old_min, old_max;
  26. DCELL old_dmin, old_dmax;
  27. int in_fd, out_fd, no_mask, align_wind, make_dcell, nrules, rule_size;
  28. char *name, *result, *title;
  29. char **rules;
  30. int main(int argc, char *argv[])
  31. {
  32. char *title;
  33. FILE *srcfp;
  34. struct GModule *module;
  35. struct
  36. {
  37. struct Option *input, *output, *title, *rules;
  38. struct Flag *a, *d;
  39. } parm;
  40. G_gisinit(argv[0]);
  41. module = G_define_module();
  42. G_add_keyword(_("raster"));
  43. G_add_keyword(_("recode categories"));
  44. module->description = _("Recodes categorical raster maps.");
  45. parm.input = G_define_standard_option(G_OPT_R_INPUT);
  46. parm.input->description = _("Name of raster map to be recoded");
  47. parm.output = G_define_standard_option(G_OPT_R_OUTPUT);
  48. parm.rules = G_define_standard_option(G_OPT_F_INPUT);
  49. parm.rules->key = "rules";
  50. parm.rules->label = _("File containing recode rules");
  51. parm.rules->description = _("\"-\" to read from stdin");
  52. parm.title = G_define_option();
  53. parm.title->key = "title";
  54. parm.title->required = NO;
  55. parm.title->type = TYPE_STRING;
  56. parm.title->description = _("Title for output raster map");
  57. parm.a = G_define_flag();
  58. parm.a->key = 'a';
  59. parm.a->description = _("Align the current region to the input raster map");
  60. parm.d = G_define_flag();
  61. parm.d->key = 'd';
  62. parm.d->description = _("Force output to 'double' raster map type (DCELL)");
  63. if (G_parser(argc, argv))
  64. exit(EXIT_FAILURE);
  65. name = parm.input->answer;
  66. result = parm.output->answer;
  67. title = parm.title->answer;
  68. align_wind = parm.a->answer;
  69. make_dcell = parm.d->answer;
  70. srcfp = stdin;
  71. if (strcmp(parm.rules->answer, "-") != 0) {
  72. srcfp = fopen(parm.rules->answer, "r");
  73. if (!srcfp)
  74. G_fatal_error(_("Unable to open file <%s>"),
  75. parm.rules->answer);
  76. }
  77. if (!read_rules(srcfp)) {
  78. if (isatty(fileno(srcfp)))
  79. G_fatal_error(_("No rules specified. Raster map <%s> not created."),
  80. result);
  81. else
  82. G_fatal_error(_("No rules specified"));
  83. }
  84. no_mask = 0;
  85. do_recode();
  86. if(title)
  87. Rast_put_cell_title(result, title);
  88. exit(EXIT_SUCCESS);
  89. }