I have a task that sounds simple, but I just can't get through the last step. I need to find suitable areas where wind farms that have a size of 500x150 meters, could be placed. The restrictions are slope - best areas are form 0-2 degrees and 2-3 degrees are worth considered - and a 3 km buffer from the selected location. Data used here was SRTM as this is preliminary study. My workflow was to buffer the locations, clip the DEM, create slope, reclass into 3 categories and convert to shapefile.

My categories of reclass are as follows:

  1. First category - 1 = 0-2 degrees - green;
  2. Second category - 2 = 2-3 degrees - orange;
  3. Third category - 3 = all other data - red.

The issue that I am facing is that I would like know many 500x150 meters polygons can I fit in the green area, without overlapping the orange and red areas and without overlapping the polygon itself. The end result should be a shp with the possible positions for the aforementioned 500x150 meters polygon.

I should also specify that the 500x150 meters polygon can have any position/orientation and that I have access to ArcGIS Desktop 10.6/ArcGIS Pro 2.2/Global Mapper 19 and QGIS and my coding skill relate to very simple tasks that I replicate from other users.

I had a look at Checking if polygon fits inside another polygon using ArcGIS Desktop? where a similar things is described, but with circles and using ETGeowizard, also an older version of Arcmap.

Also, Packing Polygons within polygon using ArcGIS Desktop? is almost what I need, but the answers are just to above my level.

EDIT: the purple area is an existing possible location drawn by hand. I am trying to figure out the maximum number of 500x150m polygons that can be mosaic-ed into the green area. They don't necessarily have to touch each other.


  • 2
    Two points to clarify: 1. The purple area is an existing wind farm so do not overlap it or the unsuitable areas in orange and red. Is that interpretation correct? 2. Are you trying to figure out the maximum number of 500x150m polygons that can be mosaic-ed into the green area or are you trying to figure out all the different possible locations for a single 500x150m within the green area? – Hayden Elza Sep 22 '18 at 0:20
  • @FelixIP If I use your suggestion I will get only one polygon per area, at least this is how I understand it, because my green area is just one large polygon and you are using centroids to determine where the polygon should be placed. – alecsx Sep 22 '18 at 6:46
  • Yes, it's a case unfortunately. This is no simple task at all. I'd test few remotest points inside polygons, if you need to find certain number of them. Hopefully. – FelixIP Sep 22 '18 at 7:00
  • As a further constraint, the centre point of one of your rectangles cant have a red/yellow pixel within 75m (half the width) of it, so if you make a 75m raster buffer on the red/yellow you'll get a smaller set of possible centre location pixels. That might be useful for an algorithm which starts by selecting possible centre locations. – Spacedman Sep 22 '18 at 7:43

It is very complicated task known as bin packing problem.

The script below produces one of countless sub-optimal solutions. Algorithm:

  • places fish net over rotated POLYGON to find out rotation angle in range (0,175,5) that result in maximum count of complete rectangles
  • breaks if no such rectangles found, otherwise
  • un-rotate every good rectangle and append it to a big list
  • erase original polygon by big list. POLYGON = erase result, repeat

It works with one single-part polygon, holes Ok. Results can be slightly improved, by optimizing fish net origin location, similar to this. It would result in one more cell (near 85), but I don't think it is enough value for efforts.

enter image description here

import arcpy
from arcpy import env
from math import radians,sin,cos
env.overwriteOutput = True

# rotate polygon
def ShapeMake(pGon,angle):
    for part in pGon.boundary():
        for p in part:
    return pgonRotated
# create fishnet and count complete polygons
def fnetMake():
    oc='%s %s' %(ext.XMin,ext.YMin)
    ya='%s %s' %(ext.XMin,ext.YMax)
    cc='%s %s' %(ext.XMax,ext.YMax)
    arcpy.CreateFishnet_management(fnet, oc,ya, W, L,"","",
                                   "","NO_LABELS", rotated,"POLYGON")
    rects=arcpy.Clip_analysis(fnet, rotated, g)
    for chop in rects:
        if chop.area<A:continue
    return FNET


while True:
    for toCut in theList:
        ## FIND rotation to maximise complete rectangles
        for i in range(36):
            if N<=nMax:continue
        if nMax==0:continue
        arcpy.AddMessage("%s cell(s) found so far" %nMax)
        for item in keepers:
    if nBefore==len(bigList):break
    arcpy.Erase_analysis(PGON, bigList, erased)
    theList=arcpy.MultipartToSinglepart_management(erased, g)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.