Getting ready

There are a number of ways for us to approach this problem. In the interest of simplicity, we will first construct our grid and then rotate it in place. Also, we could in principle use a ST_Buffer function in combination with ST_Extent to construct the squares in our resultant geometry, but, as ST_Extent uses floating-point approximations of the geometry for the sake of efficiency, this could result in some mismatches at the edges of our subplots.

The approach we will use for the construction of the subplots is to construct the grid with a series of ST_MakeLine and use ST_Node to flatten or node the results. This ensures that we have all of our lines properly intersecting each other. ST_Polygonize will then construct our multi-polygon geometry for us. We will leverage this function through our wrapper function from the Improving ST_Polygonize recipe.

Our plots are 10 units on a side, in a 5 x 2 array. As such, we can imagine a function to which we pass our plot origin, and the function returns a multi-polygon of all the subplot geometries. One additional element to consider is that the orientation of the layout of our plots is rotated to a bearing. We expect the function to actually use two inputs, so origin and rotation will be the variables that we will pass to our function.