1

I have three layers that cover the whole continent of Africa. Right now, they are in the geographic coordinate system WGS84 EPSG:4326. Layer "stations" shows the center of cells (of size 1/12 x 1/12 degrees), layer "grid" shows the respective cells, and layer "households" shows locations of households. Here is what I want to do:

I want to keep only those stations for which at least one household falls in its cell. I.e., I want to delete those green points for which no red point is in their cell.

How can I do this?

enter image description here

NJF
  • 11
  • 2
  • By now, I've managed to solve 1) by first creating a buffer around the points and then a grid with the extent of the buffer layer.

    I now want to delete all polygons that have no orange points inside, and then only keep those green points that still have a polygon around.

    – NJF Sep 09 '22 at 20:37
  • 1
    We have a One question per Question policy, so you should probably [Edit] the Question to focus on the second issue. – Vince Sep 09 '22 at 23:08

2 Answers2

0

If you have an irregular point layer (blue) an a point grid (red), you can get those out of the red points that are 1) the centroids of a regular sqauare grid which 2) contain at least one of the blue points. Use QGIS expressions with Geometry generator or Geometry by expression (see here for details) with this expression on the points layer.

Replace Grid (line 2) with the name of your grid layer and 100 (line 4) with the distance between red grid points.

overlay_nearest(
    'Grid',  
    $geometry,
    max_distance:=sqrt(2)*100/2
)[0]

Yellow points created by the expression, based on the Grid layer; black lines/squares just for visualization purpose: enter image description here

Babel
  • 71,072
  • 14
  • 78
  • 208
  • Thank you very much for your help!

    I tried to follow your suggestions, but I fail to solve the problem. I'm sorry, I'm very new to QGis.

    This is what I did:

    1. I opened "properties" of the point layer -> Symbology -> Geometry Generator -> Point / MultiPoint
    2. I typed:

    overlay_nearest( 'Grid', $geometry, max_distance:=sqrt(2)*1/12/2 )[0]

    where Grid is the grid layer and 1/12 the distance between the grid points (in degrees). What happens is that the point layer just disappears.

    I don't know how to add a screenshot, so I'm not sure if you can follow.

    – NJF Sep 11 '22 at 08:34
  • You can edit your initial question to add a screenshot. Insert your expression in the layer styling, not in layer properties. Do not use geographic CRS (distance units in degrees), this does not work. Reproject your layer to a projected CRS, valid for your region of interest, e.g. local UTM zone. A screenshot could help, as well as sharing your data, at least a sample of it. – Babel Sep 11 '22 at 09:05
  • Thank you for your advice, I adapted the original question so that it's clearer what I've done so far and what is still missing. When reprojecting it, which projected CRS should I take if the data is covering the whole African continent? The problem is, I also don't know the meter distance between the points. – NJF Sep 11 '22 at 11:22
  • For a proper CRS to cover the whole african continent and returning more or less correct distances, you should ask a separate question. It depends a lot on your final task, what you want to achieve and how accurate distances should be. – Babel Sep 11 '22 at 12:16
0

The way I solved it for now is to use the tools "select by location" and "save selected features".

In a first step, I selected and kept only those grid cells that intersect with at least one household. In a second step, I then only selected and kept those stations that still lie within one of the remaining grids.

It took QGIS quite long to process it, but the result is as I wanted. It would be nice to have a Python code that does it in a quicker and more elegant way, but this approach seems to work as well.

NJF
  • 11
  • 2