Hi everyone,

I'm trying to make a function that constructs rectangular polygons based on
the bounding boxes of other polygons from a SpatialPolygonsDataFrame.  I am
having a number of errors right now, which I am unsure how to fix.  My code
is basically as follows:

temp = bbox(spdf_u[1,])
temp = matrix(temp, ncol = 2)

mat = matrix(nrow = 5, ncol = 2)
mat[1,1] = temp[1,1]
mat[1,2] = temp[2,1]
mat[2,1] = temp[1,1]
mat[2,2] = temp[2,2]
mat[3,1] = temp[1,2]
mat[3,2] = temp[2,2]
mat[4,1] = temp[1,2]
mat[4,2] = temp[2,1]
mat[5,1] = temp[1,1]
mat[5,2] = temp[2,1]
rm(temp)

temppoly = Polygon(mat)
polylist = list(temppoly)
temppolys = Polygons(polylist)

I'm first encountering an error after I have constructed the Polygon object
"temppoly".  It seems to have no problems at first, but if I try to plot
"temppoly", I get the following error:

Error in as.double(y) :
  cannot coerce type 'S4' to vector of type 'double'

I'm also encountering an error when attempting to construct the Polygons
object "temppolys":

Error in Polygons(polylist) : Single ID required

I'm very new to R, so these could be very simply problems, but I'm unable to
find any reference material about these issues.  If anyone could offer me
some insight as to why I'm having these errors, and perhaps how to get
around them, it would be greatly appreciated.  If more code is needed, let
me know and I'll provide it.

Thanks a lot,
Cam

	[[alternative HTML version deleted]]

