I have a polygon hydro layer of my study area and am trying to calculate the distance to nearest water bodies from my site. Since my site are 2km*2km grids I am not sure how to calculate it? Whether to calculate from centroids of the grids or convert the layer to raster and somehow calculate mean distance of raster cells within the grid. Would be a great help if somebody could provide steps :)
If you are working with GRASS, then you can use the module v.distance. When you import the 2kmX2km grid into grass, it automatically creates centroids for each grid cell (that's how the vector design in GRASS works). So you would first add a column in the grids table to hold the distance value, then run v.distance to update that column:
(Assuming two GRASS vector maps, 'water' and 'grid')
v.db.addcolumn map=grid column="dist_to_water double" v.distance from=grid from_type=centroid to=water upload=dist column=dist_to_water
View the results:
GRASS v.distance in QGIS Processing is not working (see this pull request), so if you want to use v.distance you will have to use the GRASS plugin.
An alternative is the QGIS NNJoin Plugin, that for each feature in the input dataset finds the nearest neighbour in the join dataset. The resulting layer will contain all the features from the input dataset with all the attributes from the nearest join feature added, and also a new attribute that contains the distance to the nearest (join) feature.