create_vector_shape.Rd
create_vector_shape generates a EML entity of type spatialVector. The function allows the user to build a shapefile and accompanying metadata from a spatial object read into or created within the R environment. The resulting shapefile is written to a directory that is then zipped for inclusion in a data package.
create_vector_shape(
vector_name,
description,
geoDescription = NULL,
coord_sys,
layer_opts = NULL,
overwrite = FALSE,
projectNaming = TRUE,
missing_value_code = NULL
)
(character) The unquoted name of the spatial object in the R environment.
(character) Description of the vector resource.
(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.
(character) The quoted EML-compliant name of the coordinate reference system.
(character) Additional options for generating a shapefile that are passed to the sf::st_write function
(logical) A logical indicating whether to overwrite an existing directory bearing the same name as the shapefile.
(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.
(character) Quoted character(s) of a flag, in addition to NA or NaN, used to indicate missing values within the data.
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.
Unlike the package_vector_shape function in the capemlGIS package, create_vector_shape writes a new shapefile to file. This allows the user to produce a shapefile and corresponding metadata by either loading a spatial object into the R environment or creating a spatial object with the R environment. The shapefile that is written to file is packaged within a new directory that is zipped for inclusion in a data package. Because a new spatial object is created, the data can be modified as needed. 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 - create_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.
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.
The shapefile generated from create_vector_shape will have the same coordinate reference system (CRS) as the input spatial object.
if (FALSE) {
# load spatial vector object; because create_vector_shape will generate a
# new shapefile, we have complete flexibility over the shapefile name and
# manipulating the data - here we are starting with an existing shapefile
# named CORETT but will generate a shapefile with the name
# ejido_titles_points_of_decree
ejido_titles_points_of_decree <- sf::read_sf(
dsn = "data/Regularizacion/ejidal",
layer = "CORETT"
) %>%
dplyr::select(
-OBJECTID_1,
-FolderNumb,
-Surface
) %>%
dplyr::mutate(
Id = as.character(Id),
across(where(is.character), ~ gsub(pattern = "\\r\\n", replacement = "", x = .)),
across(where(is.character), ~ gsub(pattern = "--", replacement = NA_character_, x = .)),
Year = as.character(Year)
)
# write attributes (and factors if relevant)
try(write_attributes(ejido_titles_points_of_decree, overwrite = FALSE))
# generate a description for the data entity
ejido_titles_points_of_decree_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"
ejido_titles_points_of_decree_SV <- create_vector_shape(
vector_name = ejido_titles_points_of_decree,
description = ejido_titles_points_of_decree_desc,
coord_sys = "WGS_1984_UTM_Zone_55N",
layer_opts = "SHPT=POLYGON",
overwrite = TRUE,
projectNaming = TRUE,
)
# The resulting spatialVector entity can be added to a EML dataset.
# Note also in this example that we are passing additional layer options,
# which ultimately feed to sf::st_write, necessary here to generate a
# multi-polygon shapefile.
}