2

New R user. I'm trying to create an observation window for a point pattern in R using a shapefile imported from ArcGIS. I've imported the shapefile and it is recognized by R as a feature class type:polygon. I need the xmin, xmax, ymin, ymax of the extent and that is all in order to specify these in creating the owin object. I can't seem to extract these values from the polygon. I know this is very basic but I can't put 2 and 2 together here.

  • 1
    object@bbox if its an sp* object – obrl_soil Nov 8 '16 at 0:38
5

You can create a rectangle with the boundary box of your polygon. I use rgdal package to make a reproducible example, but you could use only raster package with shapefile() function instead of readOGR():

library(rgdal)
library(raster)

dsn <- system.file("vectors", package = "rgdal")[1]
ogrListLayers(dsn)
polygon <- readOGR(dsn=dsn, layer="scot_BNG")

Creates an extent object using bbox and convert it to polygon:

e <- extent(polygon@bbox)

e <- as(e,"SpatialPolygons")

See the results:

plot(polygon)
plot(e, add= T)

Rplot

  • see my "answer" above-- your solution worked-- thanks ! – JRM77 Nov 8 '16 at 19:14
  • You do not need to call the bbox slot, the extent function does this for you. It is as simple as: e <- as(raster::extent(polygon), "SpatialPolygons") – Jeffrey Evans Nov 8 '16 at 20:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.