This function creates a "RapData" object using pre-processed data.

RapData(
  pu,
  species,
  targets,
  pu.species.probabilities,
  attribute.spaces,
  boundary,
  polygons = NA,
  skipchecks = FALSE,
  .cache = new.env()
)

Arguments

pu

base::data.frame() planning unit data. Columns must be "cost" (numeric), "area" (numeric), and "status" (integer).

species

base::data.frame() with species data. Columns must be "name" (character).

targets

base::data.frame() with species data. Columns must be "species" (integer), "target" (integer), "proportion" (numeric).

pu.species.probabilities

base::data.frame() with data on the probability of species in each planning unit. Columns must be "species", (integer), "pu" (integer), and "value" (numeric).

attribute.spaces

list of AttributeSpaces() objects with the demand points and planning unit coordinates.

boundary

base::data.frame() with data on the shared boundary length of planning units. Columns must be "id1" (integer), "id2" (integer), and "boundary" (integer).

polygons

PBSmapping::PolySet() planning unit spatial data or NULL if data not available.

skipchecks

logical Skip data integrity checks? May improve speed for big data sets.

.cache

base::environment() used to cache calculations.

Value

A new RapData object.

Note

Generally, users are not encouraged to change arguments to .cache.

Examples

# \dontrun{
# load data
cs_pus <- sf::read_sf(
 system.file("extdata", "cs_pus.gpkg", package = "raptr")
)
cs_spp <- terra::rast(
  system.file("extdata", "cs_spp.tif", package = "raptr")
)
cs_space <- terra::rast(
  system.file("extdata", "cs_space.tif", package = "raptr")
)

# create data for RapData object
attribute.spaces <- list(
  AttributeSpaces(name = "geographic", list(
    AttributeSpace(
      planning.unit.points = PlanningUnitPoints(
        suppressWarnings(
          sf::st_coordinates(sf::st_centroid(cs_pus[1:10, ]))
        ),
        seq_len(10)
      ),
      demand.points = make.DemandPoints(
        randomPoints(cs_spp[[1]], n = 10, prob = TRUE)
      ),
      species = 1L
    ))
  ),
  AttributeSpaces(name = "environmental", list(
    AttributeSpace(
      planning.unit.points = PlanningUnitPoints(
        as.matrix(terra::extract(
          cs_space[[1]], as(cs_pus[1:10, ], "SpatVector"),
          fun = "mean",
          ID = FALSE
        )),
        seq_len(10)
      ),
      demand.points = make.DemandPoints(
        as.matrix(terra::as.data.frame(cs_space[[1]], na.rm = TRUE))
      ),
      species = 1L
    )
 ))
)
#> Registered S3 methods overwritten by 'adehabitatMA':
#>   method                       from
#>   print.SpatialPixelsDataFrame sp  
#>   print.SpatialPixels          sp  
pu.species.probabilities <- calcSpeciesAverageInPus(
  cs_pus[1:10,], cs_spp[[1]]
)
polygons <- convert2PolySet(cs_pus[1:10, ])
boundary <- calcBoundaryData(cs_pus[1:10, ])

# create RapData object
x <- RapData(
  pu = cs_pus[1:10, ], species = data.frame(name = "test"),
  target = data.frame(species = 1L, target = 0:2, proportion = 0.2),
  pu.species.probabilities = pu.species.probabilities,
  attribute.spaces = attribute.spaces,
  polygons = polygons,
  boundary = boundary
)

# print object
print(x)
#> RapData object.
#>   Number of planning units: 10
#>   Number of species: 1
#>   Number of attribute spaces: 2
# }