4

For a project I'm doing, I want to cluster parcels together based on their specific land use category. As an example, a small part of the data looks like this.

Spatial Data with different categories of land use highlighted in different colors

example

There are many more categories than what you see in this picture. I want to know if their is some kind of smart method to "cluster" these parcels based on the land use attribute. You can see from this picture that there is some spatial dependency and I want to create a new column which contains the number of the cluster a parcel belongs to.

I could probably one-hot-encode the category, but that would create a lot of columns and could therefore be suboptimal. Also I'm thinking of writing some simple code based on the 'DBSCAN algorithm' that checks for similar neighbors.

Do you have any suggestions for existing methods using QGIS to evaluate this problem?

0

2 Answers 2

5
  1. You can dissolve you layer based on category: Menu Vector / Geoprocessing Tools / Dissolve, select the attribute that contains the category in the optional Dissolve field(s) option.

  2. On the created layer, run Menu Vector / Geometry Tools / Multipart to singleparts. You get a new layer with one feature for each cluster.

  3. On this layer, create an attribute for a unique id of each cluster feature with field calculator and the expression $id.

  4. Now use Menu Processing / Toolbox / Join attributes by location, select your original polygon layer as Base Layer and the layer created in step 3 as Join Layer and check the box next to within. You will get a new layer, containing you original polygons but with an additional attribute field for the cluster-id.

Screenshot: the polygons are labeled with an attribute category. As you see, there are three different clusters of "category-2 polygons": on the top, on the right side and on the left side in the middle. The colors are created as a categorized style, based on the cluster id field created as described above: enter image description here

1
  • 1
    You were right! I didn't notice until I zoomed in a lot. Applied the buffer and followed your method and now I have exactly what I need. Thanks a lot for the great help! Apr 30, 2021 at 20:08
2

I would explore the various clustering plugins available for QGIS. "Attribute based clustering" Plugin may be what you need, but there are several more available.

2
  • this plugin is nice but I tried it and it doesn't take nominal data (can't select the field in dropdown). Any idea if there is something similar but nominal? Apr 30, 2021 at 20:01
  • Add a Numerical field that categorises each nominal.
    – wingnut
    May 1, 2021 at 14:19

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.