helper function used to retrieve the extent of a spatial object or file, and the associated proj4string

get_extent(in_object, proj4string = NULL, abort = FALSE)

# S3 method for default
get_extent(in_object, proj4string = NULL,
  abort = FALSE)

# S3 method for sprawlext
get_extent(in_object, proj4string = NULL,
  abort = FALSE)

# S3 method for Extent
get_extent(in_object, proj4string, abort = FALSE)

# S3 method for matrix
get_extent(in_object, proj4string, abort = FALSE)

# S3 method for character
get_extent(in_object, proj4string = NULL,
  abort = FALSE)

# S3 method for Raster
get_extent(in_object, proj4string = NULL,
  abort = FALSE)

# S3 method for sf
get_extent(in_object, proj4string = NULL, abort = FALSE)

# S3 method for sfc
get_extent(in_object, proj4string = NULL, abort = FALSE)

# S3 method for Spatial
get_extent(in_object, proj4string = NULL,
  abort = FALSE)

# S3 method for Spatial
get_extent(in_object, proj4string = NULL,
  abort = FALSE)

Arguments

in_object

character corresponding to the name of a R object, or a filename (full path)

proj4string

(optional) character proj4string representing the projection of the input extent. It is needed only if in_object does not include a projection (like extent or bbox).

abort

logical if TRUE, the function aborts in case valid a extent can not be retrieved, otherwise, it issues a Warning and returns NA, Default: FALSE

Value

object of class sprawlext

Details

return an object of class sprawlext with two slots:

  • $extent: numeric (4) extent of the object (xmin, ymin, xmax, ymax)

  • $proj4string: character proj4string of the object (if an extent can not be retrieved from in_object)

Examples

library(raster) in_rast <- system.file("extdata/MODIS_test", "EVIts_test.tif", package = "sprawl.data") get_extent(in_rast)
#> An object of class "sprawlext" #> Slot "extent": #> xmin ymin xmax ymax #> 12897004 1685995 12973683 1789545 #> #> Slot "proj4string": #> [1] "+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs" #>
in_rast <- raster::raster(in_rast) get_extent(in_rast)
#> An object of class "sprawlext" #> Slot "extent": #> xmin ymin xmax ymax #> 12897004 1685995 12973683 1789545 #> #> Slot "proj4string": #> [1] "+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs" #>
in_vect <- system.file("extdata/shapes","lc_polys.shp", package = "sprawl.data") get_extent(in_vect)
#> An object of class "sprawlext" #> Slot "extent": #> xmin ymin xmax ymax #> 120.17779 15.15353 121.33942 16.09343 #> #> Slot "proj4string": #> [1] "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0" #>
in_vect <- read_vect(in_vect) get_extent(in_vect)
#> An object of class "sprawlext" #> Slot "extent": #> xmin ymin xmax ymax #> 120.17779 15.15353 121.33942 16.09343 #> #> Slot "proj4string": #> [1] "+proj=longlat +datum=WGS84 +no_defs" #>