Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r.horizon: adjust bufferzone to multiples of resolution #3384

Merged
merged 5 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions raster/r.horizon/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ int main(int argc, char *argv[])
parm.bufferzone->description =
_("For horizon rasters, read from the DEM an extra buffer around the "
"present region");
parm.bufferzone->options = "0-";
echoix marked this conversation as resolved.
Show resolved Hide resolved
parm.bufferzone->guisection = _("Raster mode");

parm.e_buff = G_define_option();
Expand All @@ -241,6 +242,7 @@ int main(int argc, char *argv[])
parm.e_buff->required = NO;
parm.e_buff->description = _("For horizon rasters, read from the DEM an "
"extra buffer eastward the present region");
parm.e_buff->options = "0-";
parm.e_buff->guisection = _("Raster mode");

parm.w_buff = G_define_option();
Expand All @@ -249,6 +251,7 @@ int main(int argc, char *argv[])
parm.w_buff->required = NO;
parm.w_buff->description = _("For horizon rasters, read from the DEM an "
"extra buffer westward the present region");
parm.w_buff->options = "0-";
parm.w_buff->guisection = _("Raster mode");

parm.n_buff = G_define_option();
Expand All @@ -257,6 +260,7 @@ int main(int argc, char *argv[])
parm.n_buff->required = NO;
parm.n_buff->description = _("For horizon rasters, read from the DEM an "
"extra buffer northward the present region");
parm.n_buff->options = "0-";
parm.n_buff->guisection = _("Raster mode");

parm.s_buff = G_define_option();
Expand All @@ -265,6 +269,7 @@ int main(int argc, char *argv[])
parm.s_buff->required = NO;
parm.s_buff->description = _("For horizon rasters, read from the DEM an "
"extra buffer southward the present region");
parm.s_buff->options = "0-";
parm.s_buff->guisection = _("Raster mode");

parm.maxdistance = G_define_option();
Expand Down Expand Up @@ -499,6 +504,12 @@ int main(int argc, char *argv[])
if (nbufferZone == 0.)
nbufferZone = bufferZone;

petrasovaa marked this conversation as resolved.
Show resolved Hide resolved
/* adjust buffer to multiples of resolution */
ebufferZone = (int)(ebufferZone / stepx) * stepx;
wbufferZone = (int)(wbufferZone / stepx) * stepx;
sbufferZone = (int)(sbufferZone / stepy) * stepy;
nbufferZone = (int)(nbufferZone / stepy) * stepy;

echoix marked this conversation as resolved.
Show resolved Hide resolved
new_cellhd.rows += (int)((nbufferZone + sbufferZone) / stepy);
new_cellhd.cols += (int)((ebufferZone + wbufferZone) / stepx);

Expand Down
59 changes: 59 additions & 0 deletions raster/r.horizon/testsuite/test_r_horizon.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,65 @@ def test_raster_mode_multiple_direction_offset(self):
second=stdout,
)

def test_raster_mode_bufferzone(self):
"""Test buffer 100 m and 109 m with resolution 10 gives the same result"""
self.runModule(
"g.region",
raster="elevation",
n="n-5000",
s="s+5000",
e="e-5000",
w="w+5000",
)

module = SimpleModule(
"r.horizon",
elevation="elevation",
output=self.horizon_output,
direction=50,
bufferzone=100,
)
self.assertModule(module)
ref = {
"mean": 0.0344791,
}
output = "test_horizon_output_from_elevation_050"
self.assertRasterFitsUnivar(
raster=output,
reference=ref,
precision=1e-6,
)
module = SimpleModule(
"r.horizon",
elevation="elevation",
output=self.horizon_output,
direction=50,
bufferzone=103,
)
self.assertModule(module)
self.assertRasterFitsUnivar(
raster=output,
reference=ref,
precision=1e-6,
)
module = SimpleModule(
"r.horizon",
elevation="elevation",
output=self.horizon_output,
direction=50,
bufferzone=95,
)
self.assertModule(module)
ref = {
"mean": 0.0344624,
}
self.assertRasterFitsUnivar(
raster=output,
reference=ref,
precision=1e-6,
)
self.runModule("g.region", raster="elevation")


if __name__ == "__main__":
test()
Loading