package_vector_shape generates a EML entity of type spatialVector, and harvests all relevant files that constitute a single shapefile into a directory that is then zipped.

package_vector_shape(
  dsn,
  layer,
  description,
  geoDescription = NULL,
  coord_sys,
  overwrite = FALSE,
  projectNaming = TRUE,
  missing_value_code = NULL
)

Arguments

dsn

(character) The quoted name of the directory where the shapefile is located. The trailing slash of a directory should not be included.

layer

(character) The quoted name of the shapefile (without a file extension).

description

(character) Description of the vector resource.

geoDescription

(character) A textual description of the geographic coverage of the vector. If not provided, the project-level geographic desciption in the config.yaml will be used.

coord_sys

(character) The quoted EML-compliant name of the coordinate reference system.

overwrite

(logical) A logical indicating whether to overwrite an existing directory bearing the same name as the shapefile.

projectNaming

(logical) Logical indicating if the zipped directory should be renamed per the style used within the capeml ecosystem (default) with the project id + base file name + md5sum + file extension (zip in this case). The name of the shapefile + file extension (zip in this case) will be used if this is set to FALSE. Note that this applies only to the zipped directory, the files that constitute the shapefile are not renamed.

missing_value_code

(character) Quoted character(s) of a flag, in addition to NA or NaN, used to indicate missing values within the data.

Value

An object of type EML spatialVector is returned. Additionally, all files that make up a single shapefile are harvested into a new directory that is zipped for inclusion in the data package.

Details

Unlike some other capemlGIS functions for managing vector data, package_vector_shape does not create a new spatial entity but rather collects all of the files that consititue a single shapefile, aggregates those files into a single directory, then zips that directory for inclusion in the data package. Metadata are generated on both spatial aspects of the data and physical aspects of the zipped directory. Because a new spatial object is not created, metadata must be constructed on the data as they exist. That is, some data operations can be performed, such as classifying a numerical ID field as character so that it does not require a unit, but the data from which the metadata are constructed should not be edited. If present, the function reads attribute and factor metadata from supporting yaml file(s) generated from the capeml::write_attributes() and capeml::write_factors() functions - package_vector_shape will look for files in the working directory with a name of type "entity name"_attrs.yaml (or "entity name"_attrs.csv if an older project) for attribute metadata, and "entity name"_factors.yaml (or "entity name"_factors.csv if an older project) for factor metadata. Note that this functionality is predicated on the existence of a file containing metadata about the attributes, that that file is in the working directory, and that the file matches the name of the spatial data entity precisely.

Note

If project naming is TRUE then create_vector will look for a package number (packageNum (deprecated) or identifier) in config.yaml; this parameter is not passed to the function and it must exist.

Examples

if (FALSE) {

# read spatial data into R and manipulate as necessary (but minimally as a
# new data object is not created so the metadata should reflect the unaltered
# source data)
CORETT <- sf::read_sf(
  dsn = "data/",
  layer = "CORETT"
  ) %>%
mutate(
  Id = as.character(Id),
  Year = as.character(Year)
)

# write an attributes metadata template (and factors if relevant (not shown))
try(capeml::write_attributes(CORETT, overwrite = TRUE))

# generate a description for the data entity
corett_desc <- "polygons of land regularized by the National Agency, CORETT;
polygons were georeferenced from 281 paper maps, consolidated into 87 unique
regularization degrees of ejidos that became privitzed from 1987-2007;
includes the area of each polygon, the date of regularization, the name of
the ejido, the delegation, and the 'plane number' that could be used to find
the original map file in the CORETT office; it only includes expropriation
for the delegations Xochimilco, Magdalena Contreras, Iztapalapa, Tlahuac,
Gustavo Madero, Cuajimalpa, Alvaro Obregon, Tlalpan, Coyoacan, and Milpa
Alta"

# generate the spatial vector object, which can now be incorporated into our
# EML dataset metadata; here we are relying on the geographic description in
# the project config.yaml but we could overwrite that by passing an argument
# to the geoDescription parameter if appropriate.

corett_SV <- package_vector_shape(
  dsn           = "~/Desktop/shapedir/data",
  layer         = "CORETT",
  description   = corett_desc,
  geoDescription,
  coord_sys     = "WGS_1984_UTM_Zone_55N",
  overwrite     = TRUE,
  projectNaming = TRUE
  )

# The resulting spatialVector entity can be added to a EML dataset

}