I need to perform something similar to the ArcGIS tool for neighbourhood analysis (Toolbox>Spatial Analyst Tools>Neighorhood>Focal Statistics).

But for nearest neighbor in QGIS I need a point layer but I have just a raster TIFF. This is what I did so far:

I created a raster out of village polygons with value 1 for village and value 0 for novillage (via r.null). Now I want to know which and how many rastercells with novillage value (0) have one or several rastercells with village value (1) in a radius of 1500 m. If I need to convert the TIFF to a point layer, there are two questions: How to do it? How to keep the boundaries of my 25x25m grid if I tranform the grid to a point layer?

Please keep in mind I am quite new to QGIS.

I have QGIS Hanover 3.16 on a Linux Mint installed.

  • 1
    Is it absolutely mandatory to use raster files? Couldn't you just create a vector buffer of 1500 meters around the village?
    – gvanhavre
    Commented Jun 6, 2021 at 10:15
  • Thanks for fast reply! In further steps though I need to identify the size of nonvillage grid which dont have the village in the near distance of 1500 m for then appying a selection with other features to find out the best habitat for an animal. Maybe I could do this with a buffer as well and deselect somehow the grid within the buffer zone. But somehow I made a mistake anyways: because now in r.neighbor i can select my raster layer. I dont know why beforehand it only showed point layers. Therefor I think this should work now and I check if buffers might be the easier version. Thanks again!
    – Flynx
    Commented Jun 6, 2021 at 10:37

1 Answer 1


Using a point layer, you can not keep the boundaries at the same time within the same layer. But you can create two layers out of your raster: a point layer and a polygon layer.

For this to do, there are two convenient processing tools available:

  • Raster pixels to points
  • Raster pixels to polygons

enter image description here

For your goal, in this answer I suggest to use the polygons. Because you can use this handy expression which counts the number of neighboring (touching) polygons having a 1 as value:


Change "VALUE" to the fieldname containing your values, by default the output of raster pixels to polygons calls it that way. Similary, you could also take the non-touching into account and instead use a distance limit as follows:


Note that limit:=-1 should return all results as stated in the documentation of this expression, but I encountered that this is not the case in v3.18.2, so also try changing -1 to e.g. 9999 or something like that if you encounter the same behavior in 3.16.

  • Great, thanks for that suggestion and explanation! Much appreciated:) Also, I dont know if I somehow need to close this question since its answered?
    – Flynx
    Commented Jun 8, 2021 at 10:31

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.