Skip to main content

Hi,

 

I have to fit the maximum number of polygon with specified dimensions into another polygon.

I have to analyze two positions: vertical and horizontal and choose the most optimal placement (the largest number of polygons inside)

for example:

Do you have an idea how to do it in FME?

 

 

Some initial questions to get the discussion going:

1) Do you want to / can you accept a solution that uses Python?

2) Are the rectangles always the same size and shape (although, two ways of orienting them)?

3) Is the polygon (i.e. the bin) always the same size and shape too?


Some initial questions to get the discussion going:

1) Do you want to / can you accept a solution that uses Python?

2) Are the rectangles always the same size and shape (although, two ways of orienting them)?

3) Is the polygon (i.e. the bin) always the same size and shape too?

1. Yes, the solution must work on millions of objects

2. Yes and only two ways of orienting

3. No, the shape of the polygon can be different


1. Yes, the solution must work on millions of objects

2. Yes and only two ways of orienting

3. No, the shape of the polygon can be different

Hey @tk_st, that is a really interesting proposal of a workspace that you have. Could you share some more details like what format the data is that you currently have and what format you would like the data written out to be?


Hey @tk_st, that is a really interesting proposal of a workspace that you have. Could you share some more details like what format the data is that you currently have and what format you would like the data written out to be?

I am currently working on 2d polygons that are saved in the postgis database


 

I came up with a way to solve this problem, however, there is a problem with the algorithm's performance.

The algorithm works like this:

1. I created a grid in which each element has the same size (in vertical and horizontal orientation)

2. Then I move the grid to the object being analyzed

3. here iterative analysis occurs, I move the grid by a specified interval horizontally and vertically

4. I cross each grid position with the analyzed object and count the number of grid elements inside the analyzed object

5. from all iterations I choose the one in which the largest number of grid elements in the analyzed object fit

I used loops in the loop here, unfortunately I have to optimize this script because there is not enough memory during calculations.

Does anyone have an idea how to optimize this algorithm?

I need to analyze over a million objects

 

The main algorithm

1594237152577 

 

First loop

1594237832625 

 

Second loop

1594237977686 

fit_2.1.fmx

generate_2.1.fmx


Reply