Skip to content

Commit

Permalink
r.clump (OSGeo#1792)
Browse files Browse the repository at this point in the history
With threshold=0, FCELL/DCELL maps are truncated to CELL, resulting in clumps of input cells with different values. Fixes OSGeo#1599.
  • Loading branch information
metzm authored and neteler committed Nov 7, 2023
1 parent bee8edf commit 342a49a
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions raster/r.clump/main.c
Expand Up @@ -41,6 +41,7 @@ int main(int argc, char *argv[])
char name[GNAME_MAX];
char *OUTPUT;
char *INPUT;
RASTER_MAP_TYPE map_type;
struct GModule *module;
struct Option *opt_in;
struct Option *opt_out;
Expand Down Expand Up @@ -106,17 +107,6 @@ int main(int argc, char *argv[])
if (G_parser(argc, argv))
exit(EXIT_FAILURE);

#if defined(int64_t)
G_message("have int64_t");
#endif
#if defined(_int64_t)
G_message("have _int64_t");
#endif
#if defined(__int64_t)
G_message("have __int64_t");
#endif


threshold = atof(opt_thresh->answer);
if (threshold < 0 || threshold >= 1)
G_fatal_error(_("Valid range for option <%s> is 0 <= value < 1"),
Expand All @@ -130,8 +120,12 @@ int main(int argc, char *argv[])

in_fd = G_malloc(sizeof(int) * n);

for (i = 0; i < n; i++)
map_type = CELL_TYPE;
for (i = 0; i < n; i++) {
in_fd[i] = Rast_open_old(opt_in->answers[i], "");
if (Rast_get_map_type(in_fd[i]) != CELL_TYPE)
map_type = Rast_get_map_type(in_fd[i]);
}

INPUT = opt_in->answers[0];
strcpy(name, INPUT);
Expand All @@ -143,7 +137,7 @@ int main(int argc, char *argv[])
out_fd = Rast_open_c_new(OUTPUT);
}

if (n == 1 && threshold == 0)
if (n == 1 && threshold == 0 && map_type == CELL_TYPE)
clump(in_fd, out_fd, flag_diag->answer, minsize);
else
clump_n(in_fd, opt_in->answers, n, threshold, out_fd,
Expand Down

0 comments on commit 342a49a

Please sign in to comment.