I use QGIS 2.18.26. I have a layer with 10 million location points over which I lay a 1m by 1m raster. Then I want to count the number of points in each 1m² of this raster. When I launch the count I get an error without a log file.

This has worked for 1 million location points with a 5m by 5m raster.

How can i make this work for the 10 million points within each 1m²?

  • Have you tried using subsets of your data?
    – Erik
    Nov 28, 2018 at 13:00
  • How do I do this? I need the total count within each 1m² to get an average value on another parameter.Ex: all rasters with count between 600-6000, i will calculate an average mortality rate of those points, rasters with a count between 6000-60000, same thing ... Nov 28, 2018 at 13:10
  • What OS system is used? Perhaps you may try some scripting, e.g. the code from this thread Is there any simple integration for counting points in polygon using python qgis?.
    – Taras
    Nov 28, 2018 at 13:11
  • I think you're capable of creating spatial subsets. Problem is most likely too many elements in your files. Might be solvable by using QGis 3.4 and converting your points from shape to geopackage.
    – Erik
    Nov 28, 2018 at 13:13
  • 1
    I'm not sure I get your question. The question is about polygons yet your explanation says raster. If your issues are about performance, one idea would be to create a raster from your vector grid using FID as values, then use SAGA's raster values to points and finally count how many points you have in each FID using for instance the field calculator (Aggregate)
    – Albert
    Nov 28, 2018 at 13:45

1 Answer 1


This looks like a memory or storage issue. A 1 by 1 m raster is 25 times larger than a 5 by 5 m raster, so this is a huge change. You could have not enough RAM or the number that stores unique values is too small. Here are 2 workarounds (that need to be further developed).

1) use a subset

Create a regular vector grid of about 25 tiles

Make a 1 m buffer around each polygon

select the points by location inside each buffer

Create a vert to clip your raster

Get the count and mosaic the results (take the maximum in overlapping areas)

2) get the count without using the raster, then convert it to raster

If you have something like 1000 counts per pixel, the number of occupied cells should be "relatively" small. So you could focus on the points.

get a list of the coordinates of the points

convert the coordinates in meters and **round** your coordinates (all values that fall in the samme pixels will be equal, just check if your raster is shifted if you want to fit exactly within each pixel)

Loop on each pair of coordinate and increase their count by one (something like mydictionnary[(xcoordinate,ycoordinate)] += 1 , initialized at 1 if empty)

now you have your points with values of the counts, so you can continue to work with points or convert them into a 1 by 1 raster. 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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