main.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /****************************************************************************
  2. *
  3. * MODULE: r.clump
  4. *
  5. * AUTHOR(S): Michael Shapiro - CERL
  6. *
  7. * PURPOSE: Recategorizes data in a raster map layer by grouping cells
  8. * that form physically discrete areas into unique categories.
  9. *
  10. * COPYRIGHT: (C) 2006-2008 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 "local_proto.h"
  23. int main(int argc, char *argv[])
  24. {
  25. struct Colors colr;
  26. struct Range range;
  27. CELL min, max;
  28. int in_fd, out_fd;
  29. char title[512];
  30. char name[GNAME_MAX];
  31. char *OUTPUT;
  32. char *INPUT;
  33. struct GModule *module;
  34. struct Option *opt_in;
  35. struct Option *opt_out;
  36. struct Option *opt_title;
  37. G_gisinit(argv[0]);
  38. /* Define the different options */
  39. module = G_define_module();
  40. G_add_keyword(_("raster"));
  41. G_add_keyword(_("statistics"));
  42. G_add_keyword(_("reclass"));
  43. module->description =
  44. _("Recategorizes data in a raster map by grouping cells "
  45. "that form physically discrete areas into unique categories.");
  46. opt_in = G_define_standard_option(G_OPT_R_INPUT);
  47. opt_out = G_define_standard_option(G_OPT_R_OUTPUT);
  48. opt_title = G_define_option();
  49. opt_title->key = "title";
  50. opt_title->type = TYPE_STRING;
  51. opt_title->required = NO;
  52. opt_title->description = _("Title for output raster map");
  53. /* parse options */
  54. if (G_parser(argc, argv))
  55. exit(EXIT_FAILURE);
  56. INPUT = opt_in->answer;
  57. OUTPUT = opt_out->answer;
  58. strcpy(name, INPUT);
  59. in_fd = Rast_open_old(name, "");
  60. out_fd = Rast_open_c_new(OUTPUT);
  61. clump(in_fd, out_fd);
  62. G_debug(1, "Creating support files...");
  63. Rast_close(in_fd);
  64. Rast_close(out_fd);
  65. /* build title */
  66. if (opt_title->answer != NULL)
  67. strcpy(title, opt_title->answer);
  68. else
  69. sprintf(title, "clump of <%s@%s>", name, G_mapset());
  70. Rast_put_cell_title(OUTPUT, title);
  71. Rast_read_range(OUTPUT, G_mapset(), &range);
  72. Rast_get_range_min_max(&range, &min, &max);
  73. Rast_make_random_colors(&colr, min, max);
  74. Rast_write_colors(OUTPUT, G_mapset(), &colr);
  75. G_done_msg(_("%d clumps."), range.max);
  76. exit(EXIT_SUCCESS);
  77. }