TransWikia.com

Clustering spatial data based on categorical attribute

Geographic Information Systems Asked on August 4, 2021

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?

2 Answers

  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

Correct answer by Babel on August 4, 2021

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.

Answered by wingnut on August 4, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP