7
7
* Hamish Bowman <hamish_b yahoo.com>, Jan-Oliver Wagner <jan intevation.de>,
8
8
* Markus Neteler <neteler itc.it>
10
* COPYRIGHT: (C) 1999-2013 by the GRASS Development Team
10
* COPYRIGHT: (C) 1999-2006, 2010 by the GRASS Development Team
12
12
* This program is free software under the GNU General Public
13
13
* License (>=v2). Read the file COPYING that comes with GRASS
46
47
G_gisinit(argv[0]);
48
49
module = G_define_module();
49
module->keywords = _("raster, reclassification");
50
G_add_keyword(_("raster"));
51
G_add_keyword(_("reclassification"));
50
52
module->label = _("Reclassify raster map based on category values.");
51
53
module->description =
52
54
_("Creates a new raster map whose category values are based "
53
55
"upon a reclassification of the categories in an existing "
56
58
parm.input = G_define_standard_option(G_OPT_R_INPUT);
57
parm.input->description = _("Raster map to be reclassified");
59
parm.input->description = _("Name of raster map to be reclassified");
59
61
parm.output = G_define_standard_option(G_OPT_R_OUTPUT);
61
63
parm.rules = G_define_standard_option(G_OPT_F_INPUT);
62
64
parm.rules->key = "rules";
63
65
parm.rules->label = _("File containing reclass rules");
64
parm.rules->description = _("\"-\" to read from stdin");
65
parm.rules->required = NO;
66
parm.rules->guisection = _("Required");
66
parm.rules->description = _("'-' for standard input");
68
68
parm.title = G_define_option();
69
69
parm.title->key = "title";
70
70
parm.title->required = NO;
71
71
parm.title->type = TYPE_STRING;
72
parm.title->description = _("Title for the resulting raster map");
72
parm.title->description = _("Title for output raster map");
74
74
if (G_parser(argc, argv))
75
75
exit(EXIT_FAILURE);
77
old_mapset = G_find_cell2(parm.input->answer, "");
77
old_mapset = G_find_raster2(parm.input->answer, "");
78
78
if (old_mapset == NULL)
79
79
G_fatal_error(_("Raster map <%s> not found"), parm.input->answer);
81
if (G_legal_filename(parm.output->answer) < 0)
82
G_fatal_error(_("<%s> is an illegal file name"), parm.output->answer);
84
81
if (strcmp(parm.input->answer, parm.output->answer) == 0 &&
85
82
strcmp(old_mapset, G_mapset()) == 0)
86
83
G_fatal_error(_("Input map can NOT be the same as output map"));
89
if (parm.rules->answer && strcmp("-", parm.rules->answer) != 0) {
86
if (strcmp(parm.rules->answer, "-") != 0) {
90
87
srcfp = fopen(parm.rules->answer, "r");
92
89
G_fatal_error(_("Cannot open rules file <%s>"),
95
92
tty = isatty(fileno(srcfp));
97
G_init_cats(0, "", &cats);
98
map_type = G_raster_map_type(parm.input->answer, old_mapset);
99
G_read_fp_range(parm.input->answer, old_mapset, &range);
100
G_get_fp_range_min_max(&range, &min, &max);
94
Rast_init_cats("", &cats);
95
map_type = Rast_map_type(parm.input->answer, old_mapset);
96
Rast_read_fp_range(parm.input->answer, old_mapset, &range);
97
Rast_get_fp_range_min_max(&range, &min, &max);
101
98
rules = tail = NULL;
106
103
_("Enter rule(s), \"end\" when done, \"help\" if you need it\n"));
107
104
if (map_type == FCELL_TYPE)
108
fprintf(stdout, _("FCELL: Data range is %.7g to %.7g\n"),
105
fprintf(stderr, _("FCELL: Data range is %.7g to %.7g\n"),
109
106
(double)min, (double)max);
110
107
else if (map_type == DCELL_TYPE)
111
fprintf(stdout, _("DCELL: Data range is %.15g to %.15g\n"),
112
(double)min, (double)max);
108
fprintf(stderr, _("DCELL: Data range is %.15g to %.15g\n"),
109
(double)min, (double)max);
114
fprintf(stdout, _("CELL: Data range is %ld to %ld\n"), (long)min,
111
fprintf(stderr, _("CELL: Data range is %ld to %ld\n"), (long)min,