main.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. G_add_keyword(_("reclassification"));
  45. module->description = _("Recodes categorical raster maps.");
  46. parm.input = G_define_standard_option(G_OPT_R_INPUT);
  47. parm.input->description = _("Name of raster map to be recoded");
  48. parm.output = G_define_standard_option(G_OPT_R_OUTPUT);
  49. parm.rules = G_define_standard_option(G_OPT_F_INPUT);
  50. parm.rules->key = "rules";
  51. parm.rules->label = _("File containing recode rules");
  52. parm.rules->description = _("'-' for standard input");
  53. parm.title = G_define_option();
  54. parm.title->key = "title";
  55. parm.title->required = NO;
  56. parm.title->type = TYPE_STRING;
  57. parm.title->description = _("Title for output raster map");
  58. parm.a = G_define_flag();
  59. parm.a->key = 'a';
  60. parm.a->description = _("Align the current region to the input raster map");
  61. parm.d = G_define_flag();
  62. parm.d->key = 'd';
  63. parm.d->description = _("Force output to 'double' raster map type (DCELL)");
  64. if (G_parser(argc, argv))
  65. exit(EXIT_FAILURE);
  66. name = parm.input->answer;
  67. result = parm.output->answer;
  68. title = parm.title->answer;
  69. align_wind = parm.a->answer;
  70. make_dcell = parm.d->answer;
  71. srcfp = stdin;
  72. if (strcmp(parm.rules->answer, "-") != 0) {
  73. srcfp = fopen(parm.rules->answer, "r");
  74. if (!srcfp)
  75. G_fatal_error(_("Unable to open file <%s>"),
  76. parm.rules->answer);
  77. }
  78. if (!read_rules(srcfp)) {
  79. if (isatty(fileno(srcfp)))
  80. G_fatal_error(_("No rules specified. Raster map <%s> not created."),
  81. result);
  82. else
  83. G_fatal_error(_("No rules specified"));
  84. }
  85. no_mask = 0;
  86. do_recode();
  87. if(title)
  88. Rast_put_cell_title(result, title);
  89. exit(EXIT_SUCCESS);
  90. }