(I asked this question on stackoverflow, but since there were no solutions, and it has a GIS component, I thought I'd ask here).
I have an excel file with minimum and maximum projected x and y coordinates. I used the function rect to make rectangles
The code looks something like this, (the plot boundaries are different in my real script, but you get it hopefully):
op<- par(bg= "white")
plot(c(0,1000), c(0,1000), type = "n", xlab="", ylab= "", main= "poly test")
xmin=0;ymin=0;xmax=1000;ymax=1000
poly_test<- rect(xleft= xmin, ybottom=ymin, xright= xmax, ytop= ymax, lwd=3)
So far so good. But now I want to export it to QGIS or some other GIS application, or at the least have R recognize that these are spatial objects. When I try this,
poly_test2 <- SpatialPolygons(poly_test)
it gives an error. First that error was is.list(Srl) is not true. Then I turned poly-test2 into a list, and now I get "" Cannot get a slot('area") from an object of type "null"
What should I do? I've also tried setting the xmin, ymin etc as coordinates first, but it doesn't work either.
I also want to label my polygons based on an id listed in the excel file, how to do that in R? And will that label show up after exporting, in QGIS?
EDIT2: There was a projection in the projection file,.. I forgot to set something in QGIS , I think.. Anyway, I adapted the script by including a "for loop", since I have a spreadsheet with a bunch of minimum and maximun x and y coordinates. The for loop looks something like this:
for(i in 1: length(Excel_File$column))
{
e<- extent(Excel_File$XMIN[i],Excel_File$XMAX[i], Excel_File$YMIN[i],Excel_File$YMAX[i])
}
And then the rest of the script you suggested. When I apply plot(e), I see only one polygon. How do I get to see a plot of all of the polygons I created? Is my for loop not good? Do I need to crete e first with either e<-list(), or e<- data.frame etc?