Geographic Information Systems Asked on August 24, 2021
I have polygon layer which looks like this (here is small cutout):
What I need is to connect all polygons with line in somehow "logical" order – it means to go from first to last polygon (eventually point as I can create centroids) and create line connecting two nearest polygons BUT with one condition – there can’t be closed polygon (it means I can’t draw lines between three points so they create triangle) and there can be several branches – to make it clear below is the image how it should looks like.
What I get so far:
Is there any automatic way to solve this using QGIS?
Maybe adding order field to layer with values based on location or something like that. I would ideally create an automatic model in the end as I deal with lots of these layers.
There's a Minimum Spanning Tree plugin for QGIS:
If you don't see it in the plugins system make sure you have the settings to show experimental plugins.
Start it from the Plugins menu and the "Minimum Spanning Tree" entry. Using the "Automatic" tab:
I set a simple polygon layer as the "Vector Layer" and got out a line shapefile.
It seems to use the centroids of the polygons for the distance ("weight") algorithm rather than the distance of nearest approach between polygons. The lines connect centroids.
The attribute table of the lines doesn't show what polygons each line comes from so you may have to do some more overlaying and intersection to get that. First use "Extract Vertices" to get two points for each line connection, and then use "Intersection" of those points over the polygons to get another point layer with the attributes of the polygon at each point. I get this:
that tells me that the line with id=0
connects the polygon with i
equal to 9 to the one with i
equal to 12. The next line, with id=1
, connect polygon 9 to polygon 6, and so on for the complete tree.
Note it only seems to work on Shapefiles rather than loaded layers. Its also "experimental" and I managed to break it once or twice. I don't understand the difference between the "Vector" and the "Automatic" tab sections, for example, but the "Automatic" one seemed to work for my simple case. Hmm the "Vector" tab says the input "must be linestring" so I'm not sure what that is doing. For polygons, "Automatic" does the job.
The MST plugin doesn't seem to expose itself as a Processing algorithm so you won't be able to build all this into a single Processing step. Perhaps worth suggesting as an enhancement on their github code page.
There's an article here: https://www.sciencedirect.com/science/article/pii/S2352711020301771
Correct answer by Spacedman on August 24, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP