In the green area of the raster I have to fit as many square polygons as possible, of three different sizes:
- 3x3 cell size
- 2x2 cell size
- 1x1 cell size
With the fact that the approach should be greedy, so first fitting the biggest polygons, then the middle sized, and then if there is any space left, the smallest size. It does not have to be an exact approach but at least an approximation.
Considering this is just a test area for the algorithm, which should eventually perform this search on bigger real case rasters, where basically we have objects of three different sizes and are trying to place them in the allowed zones of the raster.
Having said that, I am aware it's not at all an easy task. I am using Qgis with R scripting to try to formulate this search.
EDIT: By moving a 3x3 window square and suming up the cell values, it can be determined where are the possible locations for the squares:
So, wherever there is a 9 means the square can fit, but the squares cannot overlap so now the question is how to find the best combination of 9 cells that do not overlap