Skip to main content

I've got a grid of polygons, each square is equal in size but has an attribute stored against it with a numeric value. I want to group grid squares together based on a sum of that attribute, but that sum needs to be as close to an upper limit as possible. So for example in the picture below all 'like' coloured grid squares are collected into groups where their attribute sum does not exceed 60,000. As close to 60,000 as possible would also be acceptable. I can't have disparate geographic groups, it has to be one block of squares, albeit that block doesn't have to be completely uniform.

gridWhen I started looking into this I thought, this must have a "name", an existing algorithm and "I bet there's already a custom transformer"... Well, I haven't found anything yet. Can anyone help put me out of my misery? This feels like a loop might be required, but the issue is the proximity, the grid squares might need to be pre-sorted geographically first? Any help gratefully received. Thanks, Dave

If the appearance of the tiles isn't so important, you could try a SpatialSorter, and sum along sequential tiles with some adjacent feature conditional logic in an AttributeCreator (if feature-1.sum + feature.number < 60000, then add it, else start a new group and sum. That'll create groups, but they might not be cleanly blobby like in your diagram.

Earlier versions of the transformer allowed adjusting the precision of the sort https://hub.safe.com/publishers/safe-lab/transformers/spatialsorter - not sure what's up with the final transformer. .

 

 

 


Hi Chris, thanks. You've corroborated my thinking actually as I'd started with using an old version of the custom SpatialSorter, specifically because it allowed for an optional groupsize. This is important because I'm trying to loop through the transformer and on each loop increase the group size (number of squares in the group) till I hit my sum of 60k or thereabouts. Had some trouble initially with blocking transformers inside custom transformers which has now been been made possible, but I'm still struggling with the StatisticsCalculator playing ball! Thanks for the tip anyway. Dave


Reply