Count points in raster cells

From GRASS-Wiki
Jump to: navigation, search

Q: How can I count the number of points which fall into a raster cell? I want to count vector points by region resolution (quadrat count) and write the results to a raster map (in order to perform r.mapcalc on these observed frequencies).

A: Use with 'method=n' which will count points per cell (resolution chosen with g.region) and write a raster map allocating the number count to the cell.


v.out.ascii input=myvec format=point | input=- output=myras method=n type=FCELL x=1 y=2 z=3

Q: But what if I need to count vector areas and not points per raster cell?

A: Create vector grid with desired cell size; Overlay it with area layer You want to count; Adjust GRASS region to match vector grid and then use same method as described for points. Example found at


v.mkgrid map=soil_grid grid=7,9 position=coor coor=595000,4920000 box=1000,1000
v.overlay ainput=soil_grid atype=area binput=soils@PERMANENT btype=area output=soil_on_grid operator=and
g.region vect=soil_grid res=1000
v.out.ascii input=soil_on_grid format=point fs='|' dp=2 layer=1 where="b_label='VaB'" | \ input=- output=VaB_count method=n