10

I already asked a similar question here and I tried the different solutions but I wasn’t very successful. Thus, I was thinking of using another approach if possible and I created another question.

Summary: I have a layer of centroids/points. The layer has thousands of points. I want to group each x number of points close together in one group/polygon. The points are numbered using a function (Numbering adjacent points/centroids in sequential order) from Numbering adjacent points/centroids in sequential order - QGIS 3.18

enter image description here

My question: is there a way

  1. To highlight automatically each x sequential points (e.g., each 30 points) using a different color (so every 30 points have the same other, the next 30 points have another color etc...)
  2. Or to create automatically a line/polygon in another layer or on the same layer grouping each those x sequential points together (so each polygon has 30 points in it) My idea is then later I can manually segment or tweak the areas using the different points’ colors or using the lines/polygons created automatically.

I tried using the points render: https://docs.qgis.org/3.16/en/docs/user_manual/working_with_vector/vector_properties.html#point-cluster-renderer However, since it is dynamic the number of clusters is changing based on the zoom level and at the same time, I cannot tell the render to join 30 close points together and render them as one point and it is not easy to tell which points are included in one cluster and which points are counted in another cluster

enter image description here etc...

10

You can do the first by creating bins in a new field with the expression

ceil(id/30)

Where id is your sequential field. This returns 1 for the first 30 points, 2 for points 31-60 and so on.

Then, go into Symbology, choose Categorized, your bin field as the Value and classify.

This is what it'll look like:

enter image description here

Map result, showing 30 features per bin (note that my test data isn't ordered spatially).

enter image description here

You can do the second thing easily with this sql expression, using your bins:

select bins,st_convexhull(st_collect(geom)) as geom
from table
group by bins

Collects all the points by bin number and creates a convex hull around them. Result:

enter image description here

And here's a guide to running SQL queries within QGIS:

  1. Save your layer as a Geopackage.
  2. Go to DB Manager and connect to the Geopackage
  3. Click the 'SQL Window' button to the left of the 'Import Layer/File' button:

enter image description here

  1. Paste in the query above, replacing 'table' with the name of your layer. Run it and choose to 'Load as new layer'. The unique ID column is bin, name it whatever you want.

enter image description here

  1. Click Load. This will generate a temporary view enclosing your points with polygons, grouped by bins. You can see the query in action in the layer's info panel, in the Source field:

enter image description here

12
  • 1
    Updated to simplify. Try now :)
    – Encomium
    Jun 1 at 19:53
  • 1
    I think you went wrong somewhere. Ceil never gives a floating number. It rounds up to the next integer. You should have a bin field with the first 30 rows having the same integer value, and so on. Once you have that, you can use the Categorized symbology to just colour points by the bin value.
    – Encomium
    Jun 1 at 20:16
  • 1
    Use Categorized :) I updated my post to reflect that - the whole graduated thing was silly thinking on my part and totally unnecessary, apologies. I also updated the answer to also give a solution for the second part of the question. Refresh if you don't see that, please.
    – Encomium
    Jun 1 at 20:37
  • 1
    Didn't see the categorized. I apologize!!! Working great. I just saw the second part
    – wollyka
    Jun 1 at 20:39
  • 1
    Updated to show you how you would go from a shapefile layer to a Geopackage, where you can leverage the power of SQL much more readily within QGIS.
    – Encomium
    Jun 1 at 23:12

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.