1

I have two vectors, one with points and another with the extent of a zone of interest:

enter image description here

I would like to interpolate a surface within that zone of interest. This is just a small example, with larger zones the computational overheard of interpolating across the whole region might not be acceptable.

According the the manual, v.surf.idw takes the current mask into account:

If the user has a mask set, then interpolation is only done for those cells that fall within the mask.

Getting down to it, I first rasterise the zone map:

> v.to.rast input=zone output=zone_rst use='cat'
Reading areas...
 100%
Writing raster map...
 100%
v.to.rast complete.

As a pre-check, I check the rasterised map with Map Display:

enter image description here

I then apply this raster as the current mask and finally create the surface:

 > r.mask raster=zone_rst
All subsequent raster operations will be limited to the MASK area. Removing
or renaming raster map named 'MASK' will restore raster operations to
normal.
[Raster MASK present]
 > v.surf.idw input=points column='z' output=surface --verbose
16 records selected from table
16 points loaded
Interpolating raster map <surface> (136 rows, 132 columns)...
 100%
v.surf.idw complete.
[Raster MASK present]
> r.mask -r
Raster MASK removed

But the resulting surface spans across the entire region:

enter image description here

How can I force this module to use the mask?

Update: I previously filed an answer with what appeared to be a solution; however, I had just displayed the resulting surface with the mask still on, therefore only the surface section within the mask was visible.

I have now tried v.surf.idw with various different masks, both raster and vector, but they are always ignored. The surfaces produced by v.surf.idw always encompass the entire region. For instance, the following command sequence produces exactly the same result as above:

> r.mask vector=zone
Reading areas...
 100%
Writing raster map...
 100%
All subsequent raster operations will be limited to the MASK area. Removing
or renaming raster map named 'MASK' will restore raster operations to
normal.
[Raster MASK present]
> v.surf.idw input=points column='z' output=surface_msk_vec --verbose --overwrite
16 records selected from table
16 points loaded
Interpolating raster map <surface_msk_vec> (132 rows, 186 columns)...
 100%
v.surf.idw complete.
[Raster MASK present]
> r.mask -r
Raster MASK removed
5
  • Please use r.mask for it.
    – markusN
    Commented Jun 16, 2017 at 16:47
  • @markusN I am already applying r.mask before I use the module. Commented Jun 16, 2017 at 17:09
  • Something went wrong then :) Micha's answer below shows the procedure.
    – markusN
    Commented Jun 17, 2017 at 11:28
  • @Micha simply reproduced the question. Is there any way to investigate what is going wrong? Commented Jun 17, 2017 at 16:38
  • He wrote "I can not confirm this problem." ... Did you apply his procedure?
    – markusN
    Commented Jun 18, 2017 at 19:36

2 Answers 2

1

I can not confirm this problem. Here's a (contrived) example using the nc_basic mapset. I did an IDW interpolation of the attribute CORECAPACI from the schools vector points, but limited to a mask that I made from the geology polygons.

g.region -p vect=boundary_region
# Extract just one geology polygon
v.extract geology output=my_geol cat=270
# Set the mask. Note that in recent versions, 
# no need to convert to a raster first
r.mask vector=my_geol
# Now interpolation
v.surf.rst input=schools zcol=CORECAPACI elev=school_capac

Resulting IDW interpolation

The resulting interpolation is clipped to the MASK area.

In your case, check the raster "zone_rst". I would guess that the original zone polygons cover the whole region, so you got a raster covering the region with different values inside the zone of interest and outside. So first check that the zone vector contains only one polygon covering only your area of interest. Then use that to make the mask.

1

It so happens that masks do not apply with modules like v.surf.idw, that create new maps. In the GRASS ual there is an subtle explanation why (emphasis mine):

Raster input maps are automatically masked if a raster map named MASK exists. The MASK is only applied when reading maps from the disk.

A similar warning is present in the Introduction to vector processing:

Note that a raster mask ("MASK") will not be respected since it is only applied when reading an existing GRASS raster map.

Therefore the mask is only applied to the points map passed as an input to the module. When it creates the output surface map, and in its internal workings, v.surf.idw considers the entire GRASS region.

As far as I can tell, there is no way to mask module outputs in GRASS. I shall keep this answer up to date if I manage to dig up more information. Also, there is a discussion thread on this topic at the GRASS users mail list.

Update: The v.surf.rst module implements this functionality by providing a specific input parameter called mask. Since v.surf.idw does not offer the same functionality, I opened a new ticket requesting such enhancement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.