Skip to content

Commit

Permalink
r.mblend: update for GRASS 8 (#910)
Browse files Browse the repository at this point in the history
* takes into account new behaviour in v.what.rast (inner buffer applied to region boundary)
* updates documentation with reference to new GitHub addons repository
* version number bumped to 1.2.0
  • Loading branch information
ldesousa committed Jul 17, 2023
1 parent f4002b7 commit 42c4ea6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/raster/r.mblend/VERSION.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# VERSION

1.1.1
1.2.0
27 changes: 20 additions & 7 deletions src/raster/r.mblend/r.mblend.html
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
<h2>DESCRIPTION</h2>

This module implements Mblend, a DEM merging method proposed by Leit&atilde;o <i>et al.</i> (2016). It deals with cases where a study area is only partially covered by a high resolution DEM, with a coarser DEM available for the remainder (as in the case shown below). <i>r.mblend</i> merges the two DEMs, producing a smooth transition from the high resolution DEM to the low resolution DEM.<br><br>
This module implements Mblend, a DEM merging method proposed by Leit&atilde;o
<i>et al.</i> (2016). It deals with cases where a study area is only partially
covered by a high resolution DEM, with a coarser DEM available for the
remainder (as in the case shown below). <i>r.mblend</i> merges the two DEMs,
producing a smooth transition from the high resolution DEM to the low
resolution DEM.<br><br>

<center>
<img width=40% align=center src=both_inputs.png><br><br>
</center>

The module works by identifying the edge between the two rasters (near edge, shown in read below) and the edge composed by the cells in the low resolution DEM farther away from the high resolution raster (far edge, shown in blue below). To each point along the near edge is assigned the difference between the two DEMs. To each point in the far edge is assigned the value 0. The Inverse Distance Weighted (IDW) method is then used to interpolate a new raster with the points along the two edges. This differences raster thus trends from the full difference at the near edge towards zero at the far edge. <br><br>
The module works by identifying the edge between the two rasters (near edge,
shown in read below) and the edge composed by the cells in the low resolution
DEM farther away from the high resolution raster (far edge, shown in blue
below). To each point along the near edge is assigned the difference between
the two DEMs. To each point in the far edge is assigned the value 0. The
Inverse Distance Weighted (IDW) method is then used to interpolate a new raster
with the points along the two edges. This interpolated differences raster thus
trends from the full difference at the near edge towards zero at the far edge.
<br><br>

<center>
<img width=40% align=center src=edges.png><br><br>
</center>

The differences raster is finally added to the low resolution DEM given as input. In the resulting DEM, cells along the near edge take the values in the high resolution raster. The farther away from the near edge (and closer to to the far edge) the closer is their value is to the low resolution raster, producing a smooth transition, without artefacts.<br><br>
The differences raster is finally added to the low resolution DEM given as
input. In the resulting DEM, cells along the near edge take the values in the
high resolution raster. The farther away from the near edge (and closer to to
the far edge) the closer is their value is to the low resolution raster,
producing a smooth transition, without artefacts.<br><br>

<center>
<img width=40% src=blended.png>
Expand Down Expand Up @@ -41,10 +58,6 @@ <h2>REFERENCES</h2>
J.P. Leit&atilde;o, D. Prodanovic, C. Maksimovic, <a href=http://www.sciencedirect.com/science/article/pii/S0098300416300012>Improving merge methods for grid-based digital elevation models</a>, <i>Computers & Geosciences</i>, Volume 88, March 2016, Pages 115-131, ISSN 0098-3004, DOI: <a href=http://doi.org/10.1016/j.cageo.2016.01.001>10.1016/j.cageo.2016.01.001</a>.


<h2>SEE ALSO</h2>

To report bugs, propose new features or discuss the funcioning of this add-on, visit the project repository at <a href=https://github.com/ldesousa/r.mblend>GitHub</a>.

<h2>AUTHORS</h2>

Lu&#237;s Moreira de Sousa<br>
Expand Down
23 changes: 17 additions & 6 deletions src/raster/r.mblend/r.mblend.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,18 @@
# %end
# %option LOW
# % key: low
# % description: Low resolution input raster.
# % label: Low resolution input raster.
# %end
# %option OUTPUT
# % key: output
# % description: Name of output raster.
# % label: Name of output raster.
# %end
# %option FAR_EDGE
# % key: far_edge
# % key_desc: value
# % type: double
# % description: Percentage of distance to high resolution raster used to determine far edge. Number between 0 and 100.
# % label: Percentage of distance to high resolution raster used to determine far edge. Number between 0 and 100.
# % description: When the blending occurs along a single edge a number closer to 100 tends to produce more even results. With more blending edges (e.g. high resolution DEM sits on the middle of the low resolution DEM) a lower number may produce a more regular blend.
# % answer: 95
# % multiple: no
# % required: no
Expand All @@ -46,14 +47,15 @@
# % key: inter_points
# % key_desc: value
# % type: integer
# % description: Number of points to use in interpolation. A higher number produces a smoother result but requires a lengthier computation.
# % label: Number of points to use in interpolation.
# % description: A higher number produces a smoother result but requires a lengthier computation.
# % answer: 50
# % multiple: no
# % required: no
# %end
# %flag
# % key: a
# % description: Assign the average difference between the two rasters to the far edge (instead of zero).
# % label: Assign the average difference between the two rasters to the far edge (instead of zero).
# %end

import os
Expand Down Expand Up @@ -214,6 +216,7 @@ def main():
# Get points in low resolution farther away from high resolution raster
dist_high = getTemporaryIdentifier()
weights = getTemporaryIdentifier()
interpol_area_inner_buff = getTemporaryIdentifier()
interpol_area_points = getTemporaryIdentifier()
pre_interpol_area_points = getTemporaryIdentifier()
weight_points = getTemporaryIdentifier()
Expand All @@ -232,9 +235,17 @@ def main():
gscript.message(
_("[r.mblend] Extract points from interpolation area " + "boundary")
)
inner_buff = -cell_side / 2
gscript.run_command(
"v.to.points",
"v.buffer",
input=interpol_area,
output=interpol_area_inner_buff,
type="area",
distance=inner_buff,
)
gscript.run_command(
"v.to.points",
input=interpol_area_inner_buff,
output=pre_interpol_area_points,
type="boundary",
dmax=d_max,
Expand Down

0 comments on commit 42c4ea6

Please sign in to comment.