I have a point layer that shows the distribution of a species. Is it possible in QGIS to convert this point layer to a raster grid in which the value of each cell corresponds with the amount of points within that cell? Until now, I only managed to attach attribute values to the grid cells. I have already added a column in my attribute table that has the value '1' for each point, hoping that there is a way to use a sum of attributes for each grid cell. Can anyone please help me? Thanks!
This is a kludge but it does work - haven't found a way to go directly from points to raster yet (but am hoping someone gives a solution here!).
Starting with a point grid (random points in the Serengeti from the
Vector|Research tools|Random points tool):
Create a polygonal grid of the same extent and cell size as the raster you'd like to have (this from
Vector|Research tools|Vector grid):
Vector|Analysis tools|Points in polygon, using the polygon grid and the point layer:
This gives you a new grid (here colour coded by the number of points in each polygon cell):
Raster|Conversion|Rasterize to convert this to a raster, using the PNTCNT attribute for the raster values and the same cell size as chosend for the grid:
... giving a raster with values as per the points in each cell:
Easiest and most straight-forward way:
- Assume you have a column with a unique point identifier (the species name)
- Split your Point layer by this Attribute (QGIS -> Data Management -> Split)
- Rasterize each individual point layer for instance with the GDAL Rasterize Tool, or the SAGA or GRASS tools available in the Processing Toolbox. Make sure that you use the same cell-size and resulting extent.
- Simply sum up all generated Rasterlayers. For instance with the SAGA function "Grids sum" or within GRASS "r.sum". Both functions are available in the Processing Toolbox as well.
In order to do this automatically I would suggest you ether write yourself a script, a processing-model or click x times on batch-processing in the QGIS Processing Toolbox.
If you are capable of using R then just start directly from here and adapt the code to your needs (looping through splitted points).
Or you wait for a little longer. In my freetime I am currently in the process of writing a new plugin for QGIS (dealing with macroecological calculations) and It might have a function similar to what you need.
I found this lack of support in QGIS to be very annoying because it is one important geoprocessing step that I always need. Rasterizing via the fishnet, as suggested above, is very slow if you have a lot of data-points (say 100.000) because it performs a vector based operation that consumes your CPU. Furthermore, the fishnet is massive in size compared to a sleek raster layer.
GDAL has functionality to do this operation in a minimum amount of processing time but it is not implemented in QGIS (unfortunately). For the sake of the environment and your nerves, you can use the gdal function, however, on the command line or in other software environments. I prefer to use R that has serveral GDAL related packages. You can see here how to do it in R.