function to automatically re-cast a "vector" object to a given "class" specified by the to argument.

cast_vect(object, to)

# S3 method for default
cast_vect(object, to)

# S3 method for sf
cast_vect(object, to)

# S3 method for sfc
cast_vect(object, to)

# S3 method for Spatial
cast_vect(object, to)

# S3 method for character
cast_vect(object, to)

Arguments

object

either an R object of class sf, sfc or Spatial, or a character string corresponding to a filename (with full path)

to

character indicating to which type of object the input should be re-casted. It can be "sfobject" (re-cast to sf), "spobject" (recast to Spatial) or "vectfile" (re-cast to a shapefile)

Value

returns the same object, casted to the "class" specified by to (or the exact same object in case object is already of "class" to)

Details

If object is a valid R spatial object, it is automatically converted to an object of a different class if needed (e.g., from sf to Spatial and viceversa, or from sf to a vector file through sprawl::write_shape). If it is a character string, the function checks if it corresponds to a valid vector file and reads it to a sf or Spatial object through sprawl::read_vect

Examples

#EXAMPLE1