Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#1838 closed enhancement (fixed)

r.mask: allow use of vector map as input

Reported by: mlennert Owned by: grass-dev@…
Priority: normal Milestone: 7.0.0
Component: Raster Version: svn-trunk
Keywords: mask, vector, r.mask Cc: vesnikos
CPU: Unspecified Platform: Unspecified

Description

A wish coming regularly from my students: it would be nice if r.mask accepted a vector map as input.

Moritz

Change History (11)

comment:1 Changed 7 years ago by neteler

Keywords: r.mask added

Sounds very reasonable. Maybe they can develop the method? It will include (perhaps) SQL select option and column selection, then the rasterization...

comment:2 in reply to:  1 ; Changed 7 years ago by mmetz

Replying to neteler:

Sounds very reasonable. Maybe they can develop the method? It will include (perhaps) SQL select option and column selection, then the rasterization...

r.mask got new vector, layer, cats, and where options in r54302. The input option has been renamed to raster.

If you want to create a MASK from a raster map, you now need to set the raster option. If you want to create a MASK from a vector map, you now need to set the vector option. Only vector areas will be considered for creating a MASK from a vector.

When a MASK is created from a raster, the extents and resolution of the raster map are used because r.reclass is used (that's the unchanged default behaviour as in GRASS 6), but when a MASK is created from a vector, the current region settings are used.

Markus M

comment:3 Changed 7 years ago by martinl

Resolution: fixed
Status: newclosed

comment:4 Changed 7 years ago by vesnikos

Cc: vesnikos added

really nice, I just use it today!

One wish tho for next release. r.mask should be able to accept multiple vectors. For example what if I want to create a mask using the costline AND lakes shapefile?

comment:5 in reply to:  2 Changed 7 years ago by Nikos Alexandris

Replying to mmetz:

Replying to neteler:

Sounds very reasonable. Maybe they can develop the method? It will include (perhaps) SQL select option and column selection, then the rasterization...

r.mask got new vector, layer, cats, and where options in r54302. The input option has been renamed to raster.

..

When a MASK is created from a raster, the extents and resolution of the raster map are used because r.reclass is used (that's the unchanged default behaviour as in GRASS 6), but when a MASK is created from a vector, the current region settings are used.

Thanks!

Nevertheless, currently, if the region extent doesn't match, the produced raster MASK is empty. Manually, I need to extract the vector features of my interest (v.extract), set the region (g.region vect=) and then use r.mask along with the vector= option.

Would it be easy to make the region adjustment, when using a vector, automatic? Even if the user supplies an where="SQL clause"? If this action is not difficult to code, are there reasons for a user he would not want to match (at least) the region extent to the queried vector map?

I need to integrate in a script this exact operation (hardcoded example here, the idea is to support scripting of course):

r.mask vect=wrs2_descending where="PATH=161 and ROW=076"

It would be nicer to get this done automatically.

comment:6 Changed 7 years ago by pvanbosgeo

One reason a user would not want to match the region extent to the queried vector map could be that he/she is only interested in an area that partly overlaps with the vector map, with polygons falling only partly within the region. This still works with our suggestion, but only if the region is set back to the initial one after the mask is created I guess.

comment:7 in reply to:  6 Changed 7 years ago by Nikos Alexandris

Replying to pvanbosgeo:

One reason a user would not want to match the region extent to the queried vector map could be that he/she is only interested in an area that partly overlaps with the vector map, with polygons falling only partly within the region. This still works with our suggestion, but only if the region is set back to the initial one after the mask is created I guess.

If a user is interested in an area that partly overlaps with the vector map, he doesn't really want to

r.mask vector=SomeVector

He rather needs to manually find the area of interest that will become a MASK. This sounds as an exception, rather than a general rule. What do you think?

Thanks

comment:8 Changed 7 years ago by hamish

To be honest, I find it hard to justify not running v.to.rast + r.mask as a two step process. You either respect the current region setting, or the v.to.rast operation is partially undefined. Having the module change the region (and if so, internally, via WIND_OVERRIDE & the grass.use_temp_region() python function) for any reason seems like a slight misfeature to me.

Consider the case that the vector is much larger than the raster (national coastline, I'm offen making coastal "land.mask" rasters from that), you wouldn't want to rasterize the entire country at the current raster resolution. Of course it's possible to only shrink the region with a little scripting work, and it could be a nice efficiency trick to do that, but be careful that the logic for it might fail for lat/lon near the dateline)

do one thing well, Hamish

comment:9 Changed 7 years ago by Nikos Alexandris

O-K, I see. So, not even a flag "-v" that will work *only* when a "vector=" and will obtain the bounding box coordinates of the queried vector map/feature(s)?

comment:10 in reply to:  9 Changed 7 years ago by mlennert

Replying to nikosa:

O-K, I see. So, not even a flag "-v" that will work *only* when a "vector=" and will obtain the bounding box coordinates of the queried vector map/feature(s)?

-1

As the others, I do not think that setting region and mask should be mixed in one single module. They are two different things.

Moritz

comment:11 Changed 7 years ago by Nikos Alexandris

O-K, thank you all for your feedback.

Note: See TracTickets for help on using tickets.