For my work in ArcGIS 10.2 for Desktop I need to divide line layers into clusters/groups. Currently I am doing this manually, but I like to automate this. The line layers can consist of 50 up to 2500 segments (smaller lines). What I need to achieve is that the line layer is divided in a n of clusters (where n can be set by the user) which meet the following requirements. In order of importance:
- The first requirement is that a cluster should always consist of 8 or more segments.
- The second is that the segments should be near each other.
- The third is that the clusters should have a equal n of segments.
So to explain this order of importance a little bit more I have to examples with pictures:
First example of a line layer to be divided in 24 clusters with a average of 20 segments per cluster. The red arrow is a part of the line layer which consists of 4 segments. So this should form 1 cluster with several segments of the part with the green arrow, so that it is at least 8 segments, but preferable 20 segments.
Second example. In case the whole line layer is 60 segments to be divided in 3 layers, the ideal situation would be 3 clusters with each 20 segments which are connected to each other. But if there is a isolated part of the line layer which consists of 10 segments (1) this should be 1 cluster and the other part which consist of 50 segments should be divided in 2 clusters (2 & 3) of 25 segments (see picture)
I tried to achieve this task by looking at some arcgis tools but didn't found a solution yet. For example the grouping analysis tool, but up to now I was not able to customize it enough to meet my requirements. I also found this post which is kind of what I am looking for but not completely: divide polygons in equal number of groups. But as far as I understand this does not meet my requirements completely, especially the order of importance. Thereby the solution of FelixIP is hard for me to understand and therefor I am not able to judge if I can use this.
So, at this point it seems to me that my problem is a difficult mathematical problem to solve, especially with the standard tools in Arc. But maybe anyone does have some good ideas/methods (maybe with a customized python script) to get this task done or at least can get me on the right track?