[GRASS-user] v.rast.stats with mode?

Moritz Lennert mlennert at club.worldonline.be
Mon Apr 11 02:41:53 PDT 2016


On 31/03/16 10:32, patrick s. wrote:
> Following Anna's suggestion I had to find out that r.mode has to option
> to handle NULL values, i.e. exclude it from calculation? I need to
> aggregate rasters to polygons, with rasters covering only a small part
> of the polygon. As I realized now r.mode returns NULL in such case.


I cannot reproduce this issue with grass7. Try the following in the NC 
demo dataset:

g.region vector=census_wake2000 at PERMANENT res=500 -a
v.random -a output=points npoints=5 restrict=census_wake2000 at PERMANENT 
column_type=integer --o
v.kcv map=points at user1 npartitions=3
v.to.rast input=census_wake2000 at PERMANENT output=census use=attr 
attribute_column=ID --o
v.to.rast input=points at user1 output=points use=attr 
attribute_column=part --o
r.mode base=census at user1 cover=points at user1 output=census_points_rmode --o

The results seem correct: even though there are just 5 points in each 
census area, and most pixels are thus NULL in the points map, the mode 
corresponds to 1, 2 or 3.

 > Setting NULL with r.null null=9999 it will return 9999 for all of these.

If you have more NULL cells than others, and you replace the NULL value 
by an integer value, you will obviously get that value as mode...

Moritz


More information about the grass-user mailing list