QGIS - point to raster - Summing attributes as value of raster

I'm trying to produce a raster layer. The aim is to show the summed heat consumption of every cell (100*100m).

I created an point layer with all buildings and an attribute with their heat consumption. Using the Rasterize (Polygon to Raster) funtion I can choose the attribute field heat consumption, but the output doesn't show the sum of the attribute heat consumption in every cell. The value of every cell is a random value of one building inside and not the sum of all buildings inside.The problem is I need the sum of every building inside the cell. I tested a lot of different ways to find a solution, since I'm still on beginner level, it's hard for me to find out a way to calculate this.

There's probably a simpler way but I would do the following:

1. Create a 100x100m vector grid around your points layer (to match the cellsize of your raster):

``````Vector > Research Tools > Vector Grid
``````
2. The grid should have an `id` field containing unique values. Join the grid to your point layer so that your points layer also contains the `id` field:

``````Vector > Data Management Tools > Join attributes by location
``````
3. Each point should lie inside a grid cell and contain its ID. Now use the Field Calculator for your point layer to create a new field to calculate the sum of the heat consumption for each grid cell using the following expression:

``````sum( "heat_consumption_field", group_by:="id")
``````
4. Each point with a certain id should now contain the sum of the heat consumption. Use this new field for your rasterisation.

I have the same issue and find the proposed solution to be very tedious and inefficient for large data. If you know how to work with R it is quite easy. here is a minimal reproducuble example:

``````library(raster)

# create Vector layer
data(meuse)
coordinates(meuse) <- ~x+y
proj4string(meuse) <- CRS("+init=epsg:28992")

plot(meuse)

# create a baseraster for rasterization
baseraster<-raster(ext=extent(meuse),
resolution=c(100,100),
crs=CRS(proj4string(meuse)))

# rasterize zinc measurements in meuse river, using observation averages
meuse_rasterized<-rasterize(meuse,baseraster,field="zinc",fun=mean)

plot(meuse_rasterized)
``````