QGIS Points – Creating Regularly Spaced Points Inside Polygon Based on Attribute Value Using QGIS

qgisvisualization-techniques

I have a polygon layer with an attribute value attached representing the count of individuals inside a polygon. I'm using QGIS 3.0.

I need to visualize the counts as a grid of points inside a polygon (i.e. 1 point = 100 frogs, colored by specie). The points do not necessarily need to occupy entire polygon, and preferably be drawn around a centroid with pre-defined spacing (i.e. 300 m), so that they can represent a neat grid at a specific resolution.

Current workaround I found is to use "Regular points", with counts parameter, to create grids inside extent drawn on a map, then delete the extra points created by algorithm (algorithm rounds to a grid and you might get 20 points instead of 17 in input). This produces desired result, but requires drawing the extent of area for regular points for each polygon, as well as manual attribute input and clean up of points created. Furthermore, since I'm running "Regular Points" with count specified, instead of spacing, each polygon gets differently spaced points.

In a nutshell:
Regular points (defined # of points, drawn extent) for each polygon (batch) > Delete extra points > assign attribute values to the # points

Alternative (avoids the irregular spacing, but requires even more manipulations):

Regular points (defined spacing i.e. 300m) in the extent of the entire layer >
Clip to the polygons extent > Delete extra points in each polygon until you get desired # of points > assign attribute values to points.

The main problem with my workarounds is the polygon-by-polygon processing, which makes it hard to update the data and work with larger number of polygons.

Analogous question was asked as Creating regularly spaced, defined # of points within polygon in QGIS, but specifics are different.

Screenshot of desired result:

Attribute tableL:

Best Answer

QGIS 3 comes with a new displacement method in the cluster renderer called grid. Looks like this is pretty much what you need. Just create the number of desired points at the centroid of your polygon.

enter image description here

I am not aware of a method to generate the points only with a gui tool, but a relatively simple python script should do that.

with edit(point_layer):
    for polygon_feature in polygon_layer.getFeatures():
        point_feature = QgsFeature(point_layer.fields())
        point_feature.setGeometry(polygon_feature.geometry().centroid())

        point_feature['type'] = 'Frog'
        for i in range(polygon_feature['Frogs']):
            point_layer.addFeature(point_feature)

        point_feature['type'] = 'Cat'
        for i in range(polygon_feature['Cats']):
            point_layer.addFeature(point_feature)

        point_feature['type'] = 'Diplodoc'
        for i in range(polygon_feature['Diplodocs']):
            point_layer.addFeature(point_feature)

If you want to go crazy, wrap that in a custom processing algorithm.

Related Question