I'm trying to solve the following problem:
I need to place rectangles inside a polygon (must not intersect) in an alternating east-west, north-south orientation.
Variables, user defined
- Size of the rectangle e.g. is 50m by 2m.
- The number of rectangles e.g. 20.
- A tolerance value is the minimum distance between the rectangles, e.g. 10m.
- The area in which the rectangles should be placed.
The area could be a uniform shape like polygon1
or irregular like polygon2
, or more complex shapes like multipolygons.
import shapely.wkt
polygon1 = shapely.wkt.loads('POLYGON ((0.0 0.0, 1000.0 0.0, 1000.0 1000.0, 0.0 1000.0, 0.0 0.0))')
polygon2 = shapely.wkt.loads('POLYGON ((0.0 0.0, 1000.0 0.0, 1000.0 1000.0, 500.0 2000.0, 0.0 1000.0, 0.0 0.0))')
I have looked at the following which does similar for points Fastest way to produce a grid of points that fall within a polygon or shape?
Essentially I could adapt it then replace each point with a rectangles, but then a rectangles will overlap polygon1
or polygon2
.
In the described pattern the centroid of each rectangle can be best described as being on a uniform grid. The rectangles should not overlap each other, be separated by at least the tolerance value, and orientated N-S then E-W alternating.
Any suggestions on where to begin would be greatly appreciated, I assume using geopandas and shapely.