Thursday, 14 December 2017

Selecting set number of points within polygon grid cells using QGIS?


I have a polygon grid with 1 square kilometer area cells, and over it a set of points, like so:


points over grid


What i need to do is select and extract only a single random point per grid cell.


I could do that manually and it wouldn't take too much time as the area i have to cover is not that big, but is there is another way to do this?



Answer




You can easily achieve this using function from processing toolbox:




  1. Take grid cell and join its id (or other unique) attribute to related points - Use Join attributes by location and join unique attribute (i.e. "id_grid") from grid layer to point layer. This create new point layer with new attribute - "id_grid" of corresponding grid.




  2. Select only one point per gird - Use Random selection within subsets. As input choose your new layer from step one, for ID Field select "id_grid" and set number required points to be selected (in your case 1)




  3. Extracting to new point layer - Right click on layer, select Save As..., set output parametres (format, CRS...) and check Save only selected features





No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...