[R-sig-Geo] plot extent and/or convert extent to SpatialPolygons
Manuel Schneider
manuel.schneider at agroscope.admin.ch
Mon Sep 21 10:29:15 CEST 2015
Agustin Lobo <alobolistas <at> gmail.com> writes:
>
> Is it possible to plot an extent object (i.e. on top of a raster like
> it would be done for a polygon with add=TRUE)
> Or can I just convert the extent object to SpatialPolygons?
>
> Thanks
> Agus
>
Try
bbox2square <- function(bb)
{
coord.mat <- data.frame(x=rep(bb[1,],each=2),y=c(bb[2,],bb[2,2:1]))
coord.mat <- rbind(coord.mat, coord.mat[1,])
sq <- SpatialPolygons(list(Polygons(list(Polygon(coord.mat)), ID = 1)))
return(as(sq, "SpatialPolygonsDataFrame"))
}
where bb <- bbox(obj)
More information about the R-sig-Geo
mailing list