11

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:

  • 1
    Does the image in your question represent what you expect as a result? Where do counts of colored points come from? Could you add attribute table of the layer? Especially attributes of polygons which include Edmonton and Sherwood Park, for a better understanding of the colors and counts. – Kadir Şahbaz May 17 '18 at 21:06
  • 1. This is just masked data that does not have much to do with actual polygons, but yeah I expect that kind of result, but with dots around center of the polygon. 2. Counts come from attribute table columns, as there are three columns/types of points I was aggregating them into one column to first get right number of points per polygon and then assign the attribute/colors using expressions. edit: added excel table into question, doesn't represent the values, but represents the structure of my data. – Ruslan May 17 '18 at 23:48
5

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.

  • Thanks Matthias, that seems to be even better than other solutions. Can you suggest a way to quickly create the desired # of points based on attribute table to achieve this? – Ruslan Jun 15 '18 at 16:35
  • I'm not aware of an easy method apart from writing a little python script. The code is totally untested, so may have some typos ;) – Matthias Kuhn Jun 15 '18 at 17:17
  • Thanks again. I will likely have to do a similar visualization for many layers/extents etc. so I will try to build at least a processing model for this. – Ruslan Jun 15 '18 at 17:19
5
+50

May be a other way inspiring by the answer of Sarath SRK :

  1. Centroid of polygons
  2. Buffer employing an expression with the square and to adapt with your scale : i.e (1000*(sqrt("Frogs"+"Cats"+"Diplodocs" )/2))+1 and Segment=1, End cap style=Square
  3. New Grid point with a spacing coherent with the scale of the buffer.
  4. Delete point that don't intersect with the buffer layer (select by location)
  5. join attribut by location (Attribut of the buffer or the original polygons)

Yet, you will have something like this enter image description here

  1. Use à graphical modeler to create a new field with the commande "@row_number" enter image description here

  2. Execute the model with an iteration on the buffer layer enter image description here

  3. Merge all new layer

  4. Delete all the point with an ID_pt field bigger than the sum of your field ("Frogs"+"Cats"+"Diplodocs" )

  5. Categorise with rules (i.e.
    • "ID_pt" <= "Frogs"
    • "ID_pt" > "Frogs" and "ID_pt" <= ("Cats" + "Frogs" )
    • "ID_pt" > ("Cats" +"Frogs") and "ID_pt" <= ("Cats" + "Frogs"+ "Diplodocs" ) enter image description here
  • Thanks for this! I wouldn't have time to try this today, but it seems like a workable solution considering you got the output desired. – Ruslan Jun 5 '18 at 15:46
1

You could use geometry generators for this.

  1. Add 3 sublayers in the symbol, one for each color/attribute.
  2. Create an expression that generates a multipolygon for each sublayer.
  3. Now the hard part, generate square parts for the multipolygon based on the attribute. I guess this will require a custom python expression function.
  4. Optional, use the rendering variables for map-scale to determine the scaling of the polygons and spacing.
  • Sorry, I'm too busy right now for a complete answer, but it will be a very interesting challenge to try to cook something up from this recipe here. Maybe someone gets around to providing us with a nice solution based on this. – Matthias Kuhn Jun 4 '18 at 9:47
1

One solution could be to create a point layer with points at the centroid of each polygon. So for exemple you got at the centroid of Edmonton 25 superposed point : 5 with a frog attribute, 20 point with cat and 0 with diplodocs.

Then using the point displacement renderer with the Placement method set as grid you should be able to get the effect.

The difficulty is to create the point layer....

0

A very simple alternative might be to use the Pie chart available in the layer's properties ? Attributes and sizes can be dictated by an expression.

enter image description here

  • 2
    Well I know about alternative ways to map the data. The point of the question is to make that visualization workflow possible. The pie charts don't really work because when you look at the grid you get a very good sense on the count of individuals. Trying to estimate precise individual counts of each polygon from pie charts is nearly impossible. – Ruslan Jun 4 '18 at 15:48
0

You could generate the points on a spiral path starting from the polygon centroid. The following Stack Overflow post has python code to create equidistant points but I can't test it at the moment given my lack of free time.

  • Seems to be close enough, but as mentioned in the question I'm not proficient enough to code this/change the code suggested there. – Ruslan Jun 4 '18 at 15:51
  • Hopefully someone with enough knowledge and time would chime in. – Techie_Gus Jun 4 '18 at 15:53
0

In your case,

  1. Create regularly spaced points using given distance for entire AOI
  2. Create centroid points for all polygons(input).
  3. Create buffer for that centroid points using Fixed distance buffer with segments value '1'. It will create square buffer instead of circle(Use rotate tool in Qgis if you want to rotate buffer polygons).
  4. Create a selection of points falls inside buffer polygons using vector -> Research tools -> Select by location (points within polygons rule).
  5. Switch selection and delete points outside buffer polygons. So now you got regularly spaced points around centroid of polygons.
  6. Give Majority attribute for whole points and the rest of the points need to be classified manually.Use QuickMultiAttributeEdit tool to update attributes easily.
  • Thanks, this seems to cut down processing steps, but this doesn't solve the issue with need to manually select (buffers inside polygons would be identical in size=same number of points per polygon), delete and attribute created points for each of the polygons, which is the main issue with this and my workflow. – Ruslan Jun 4 '18 at 18:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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