Count points in raster cells: Difference between revisions

From GRASS-Wiki
Jump to navigation Jump to search
(Add area counting example)
mNo edit summary
 
Line 19: Line 19:


[[Category:FAQ]]
[[Category:FAQ]]
[[Category: Vector]]

Latest revision as of 18:06, 31 December 2013

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 r.in.xyz 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.

Example:

v.out.ascii input=myvec format=point | r.in.xyz 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 GISnet.lv

Example:

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'" | \
r.in.xyz input=- output=VaB_count method=n