Skip to content

Commit

Permalink
raster: Work with any mask name (r.surf.contour, r.random.cells, r.ra…
Browse files Browse the repository at this point in the history
…ndom.surface) (#4634)

Use Rast_mask_status instead of hardcoded name MASK for r.surf.contour, r.random.cells, and r.random.surface. Raster mask if present, is loaded in a special way in these tools. After this change, the name of the mask is retrieved from the library (that's the important part) and the library is at the same time used to test the presence of the mask (as opposed to testing presence of raster directly, but that's just more convenient rather than conceptual).

The change in r.random.surface code switching the if and else branches is to make it easier to write and more consistent with the other two.
  • Loading branch information
wenzeslaus authored Nov 6, 2024
1 parent 9537d74 commit 54d613f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
6 changes: 4 additions & 2 deletions raster/r.random.cells/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ void Init(void)

Cells = FlagCreate(Rs, Cs);
CellCount = 0;
if (G_find_raster2("MASK", G_mapset())) {
FD = Rast_open_old("MASK", G_mapset());
char mask_name[GNAME_MAX];
char mask_mapset[GMAPSET_MAX];
if (Rast_mask_status(mask_name, mask_mapset, NULL, NULL, NULL)) {
FD = Rast_open_old(mask_name, mask_mapset);
{
for (row = 0; row < Rs; row++) {
Rast_get_c_row_nomask(FD, CellBuffer, row);
Expand Down
14 changes: 8 additions & 6 deletions raster/r.random.surface/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@ void Init(void)
else
MinRes = NS;

if (NULL == G_find_file("cell", "MASK", G_mapset())) {
MapCount = Rs * Cs;
FDM = -1;
}
else {
FDM = Rast_open_old("MASK", G_mapset());
char mask_name[GNAME_MAX];
char mask_mapset[GMAPSET_MAX];
if (Rast_mask_status(mask_name, mask_mapset, NULL, NULL, NULL)) {
FDM = Rast_open_old(mask_name, mask_mapset);
{
MapCount = 0;
CellBuffer = Rast_allocate_c_buf();
Expand All @@ -53,6 +51,10 @@ void Init(void)
}
}
}
else {
MapCount = Rs * Cs;
FDM = -1;
}

if (Uniform->answer)
sprintf(Buf, "Uni. R. S.");
Expand Down
6 changes: 4 additions & 2 deletions raster/r.surf.contour/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ int main(int argc, char *argv[])
alt_row = (DCELL *)G_malloc(ncols * sizeof(DCELL));
seen = flag_create(nrows, ncols);
mask = flag_create(nrows, ncols);
if (NULL != G_find_file("cell", "MASK", G_mapset())) {
file_fd = Rast_open_old("MASK", G_mapset());
char mask_name[GNAME_MAX];
char mask_mapset[GMAPSET_MAX];
if (Rast_mask_status(mask_name, mask_mapset, NULL, NULL, NULL)) {
file_fd = Rast_open_old(mask_name, mask_mapset);
for (r = 0; r < nrows; r++) {
Rast_get_d_row_nomask(file_fd, alt_row, r);
for (c = 0; c < ncols; c++)
Expand Down

0 comments on commit 54d613f

Please sign in to comment.