# Calculate ratio of a vector field within a raster grid cell

I have a large dataset (shapefile) in which one variable is binary. I want to be able to find the fraction of 1 for all the points, but within a given raster grid cell, see below. Yes, as you can see the numbers are not gonna be high (lots of `0`), but still interesting to plot later on in my project.

How can I calculate the fraction of 1 within each raster grid cell? Hence, I need $\frac{V_{x&space;=&space;1}}{V_{total}}$ per grid cell.

The goal is to get it as a raster again file again.

I have not been able to figure it out on my own, side note I prefer to work in Qgis.

• @BERA, I have had this "concern" before, and I am not entirely sure why the community see this as a problem. I thought, more people could come with input and the post would not be so narrow. Thanks. – Thomas Dec 10 '20 at 9:16
• Good to know, I'll narrow it down. Thank you! – Thomas Dec 10 '20 at 9:17
• In QGIS If your raster isn't very large you could vectorize it, intersect with the points, Statistics by categories and then rasterize. But there is probably some smarter way. Vectorizing rasters are slow. – BERA Dec 10 '20 at 9:20
• Hi @BERA, so far so good. I have translated the raster into a vector as you said. Now, I have trouble calculating the fraction of `Vx = 1` per polygon (called `DN` grid cell). How would I do that per `DN`? Thanks. – Thomas Dec 11 '20 at 6:50

2. Join attribute by location (summary) with Vx field as `Field to summarize` and `count` and `sum` as `Summaries to calculate`