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.test 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 equation 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.

  • 1
    @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
  • 1
    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
  1. Vectorize the raster
  2. Join attribute by location (summary) with Vx field as Field to summarize and count and sum as Summaries to calculate
  3. Field calculate the fraction field:

enter image description here

  1. Rasterize with the calculated fraction field as Field to use for burn in value: enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.