Hi,
Is there a way to divide records into equal parts based on the value of an attribute? In concrete terms, I want to divide 400 areas into 3 pieces, each of which is the same size.
Thx
Hi,
Is there a way to divide records into equal parts based on the value of an attribute? In concrete terms, I want to divide 400 areas into 3 pieces, each of which is the same size.
Thx
How I solved this:
The disadvantage of this method is that the resulting polyons are long in one direction, but it works.
Thx for the answer but I guess I wasn't clear It's about areas with lines and dots in them. For each area I have calculate the amount of lines and points into an attribute. We need to load those areas with those lines and points in an application, but it's too much to do in one go. That's why we want to divide those areas into 3 days, but I always want a combination of areas that is approximately the same size as the next combination..
It’s like this
the total count is 2639199
My goal for the result is to have 3 groups with codes who have together approximately 1/3 of the total count.
Ah lol. Depends on the data, but how about sorting descending on count and give the records group id 1,2,3,1,2,3,1,2,3 etc?
Manual? This was a sample, i have 1500 records :-)
Nice simple hack from
But why do things manually when you can let FME do the dirty work for you?
Calculate Group as @fmod(@Count(),3)
(or maybe expand to @fmod(@Count()+1,3)+1
, which gives the results shown below)
Manual? This was a sample, i have 1500 records :-)
Hell no :)
Attached sample workspace.
The approach provided above will always put considerably more 'weight’ in group 1 than in group 3.
It would be better to assign the sorted features consecutively to Group 1, Group 2, Group 3, Group 3, Group 2, Group 1, and so on.
After sorting, give each feature a number using @Count(). Then determine to which group to assign each feature, based on this number.
This can be done with a Conditional Value:
It is also possible (and much more fun ) to put these conditions in the Math Operator x?y:z (if condition x is true then use y, else use z):
@fmod(@int(@Value(Number)/3),2) == 0 ? @fmod(@Value(Number),3) : 2-@fmod(@Value(Number),3)
The attached workspace illustrates both approaches.
Thanks, that works perfectly! I had never come up with that solution myself