Opened 12 years ago

Closed 12 years ago

Last modified 11 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 by neteler, 12 years ago

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...

in reply to:  1 ; comment:2 by mmetz, 12 years ago

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 by martinl, 12 years ago

Resolution: fixed
Status: newclosed

comment:4 by vesnikos, 12 years ago

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?

in reply to:  2 comment:5 by Nikos Alexandris, 11 years ago

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 by pvanbosgeo, 11 years ago

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.

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

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 by hamish, 11 years ago

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 by Nikos Alexandris, 11 years ago

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)?

in reply to:  9 comment:10 by mlennert, 11 years ago

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 by Nikos Alexandris, 11 years ago

O-K, thank you all for your feedback.

Note: See TracTickets for help on using tickets.