Friday 21 September 2018

r - Packing squares polygons in a raster grid



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.


Raster image from R



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:


raster matrix


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




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...