loadShape {actel}R Documentation

Load shapefile and convert to a raster object.

Description

loadShape can also perform early quality checks on the shape file, to ensure it is compatible with the remaining study data. To activate these, set the names of the columns in the spatial.csv file that contain the x and y coordinates of the stations using coord.x and coord.y. By default, loadShape looks for a spatial.csv file in the current working directory, but this can be personalized using the spatial argument.

Usage

loadShape(
  path = ".",
  shape,
  size,
  spatial = "spatial.csv",
  coord.x = NULL,
  coord.y = NULL,
  buffer = NULL,
  type = c("land", "water")
)

Arguments

path

The system path to the 'shape' file. Defaults to the current directory.

shape

A shape file containing land polygons of the study area.

size

The pixel size, in metres.

spatial

Either a character string specifying the path to a spatial.csv file or a spatial data frame. This argument is not mandatory, but can be used to perform an early check of the shape file's compatibility with the study stations and release sites.

coord.x, coord.y

The names of the columns containing the x and y positions of the stations in the spatial.csv file. these coordinates MUST BE in the same coordinate system as the shape file.

buffer

Artificially expand the shape file edges. Can be a single value (applied to all edges) or four values (xmin, xmax, ymin, ymax). The unit of the buffer depends on the shape file's coordinate system.

type

The type of shapefile being loaded. One of "land" or "water".

Details

It is highly recommended to read the vignette regarding distances matrix before running this function. You can find it by running vignette('a-2_distances_matrix', 'actel') or browseVignettes('actel')

Value

A raster object.

Examples


# check if R can run the distance functions
aux <- c(
  length(suppressWarnings(packageDescription("raster"))),
  length(suppressWarnings(packageDescription("gdistance"))),
  length(suppressWarnings(packageDescription("sp"))),
  length(suppressWarnings(packageDescription("tools"))),
  length(suppressWarnings(packageDescription("rgdal"))))
missing.packages <- sapply(aux, function(x) x == 1)

if (any(missing.packages)) {
  message("Sorry, this function requires packages '",
    paste(c("raster", "gdistance", "sp", "tools", "rgdal")[missing.packages], collapse = "', '"),
    "' to operate. Please install ", ifelse(sum(missing.packages) > 1, "them", "it"),
    " before proceeding.")
} else {
  if (suppressWarnings(require("rgdal"))) {
    # Fetch actel's example shapefile location
    aux <- system.file(package = "actel")[1]

    # import the shape file
    x <- loadShape(path = aux, shape = "example_shapefile.shp", size = 20)

    # have a look at the resulting raster,
    # where the blank spaces are the land areas
    raster::plot(x)
  } else {
    message("Sorry, it appears that rgdal is not being able to load.")
  }
}
rm(aux, missing.packages)


[Package actel version 1.2.1 Index]