Skip to main content
Solved

Equal parts


nath
Contributor
Forum|alt.badge.img+6
  • Contributor

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

Best answer by geomancer

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.

View original
Did this help you find an answer to your question?

8 replies

nielsgerrits
VIP
Forum|alt.badge.img+54

How I solved this:

  • Grid the area using a Tiler.
  • Calculate the area for each tile using an AreaCalculator.
  • Using an AttributeCreator with Adjacent Features and sum the area of the current feature with the area of the previous feature until I got the area I needed, then started over again.

The disadvantage of this method is that the resulting polyons are long in one direction, but it works.


nath
Contributor
Forum|alt.badge.img+6
  • Author
  • Contributor
  • May 8, 2024

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. 

 

 

 

nielsgerrits
VIP
Forum|alt.badge.img+54

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?


nath
Contributor
Forum|alt.badge.img+6
  • Author
  • Contributor
  • May 8, 2024

Manual? This was a sample, i have 1500 records :-)


geomancer
Evangelist
Forum|alt.badge.img+48
  • Evangelist
  • May 8, 2024

Nice simple hack from @nielsgerrits !

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)

 


nielsgerrits
VIP
Forum|alt.badge.img+54
nath wrote:

Manual? This was a sample, i have 1500 records :-)

Hell no :)

Attached sample workspace.


geomancer
Evangelist
Forum|alt.badge.img+48
  • Evangelist
  • Best Answer
  • May 8, 2024

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.


nath
Contributor
Forum|alt.badge.img+6
  • Author
  • Contributor
  • May 13, 2024

Thanks, that works perfectly! I had never come up with that solution myself


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings