create_vector writes a spatial data file of type KML and generates corresponding metadata of EML entity of type spatialVector

create_vector(
  vector_name,
  description,
  driver = "GeoJSON",
  geoDescription = NULL,
  overwrite = FALSE,
  projectNaming = TRUE,
  missing_value_code = NULL
)

Arguments

vector_name

(character) The quoted or unquoted name of the spatial data object in the R environment.

description

(character) Quoted description of the vector resource.

driver

(character) Quoted format of output file: KML or GeoJSON (default).

geoDescription

(character) A textual description of the geographic study area of the vector. This parameter allows the user to overwrite the geographicDesciption value provided in the project config.yaml.

overwrite

(logical) A logical indicating whether to overwrite an existing file bearing the same name as kml file as it is imported.

projectNaming

(logical) Logical indicating if the resulting file should be renamed per the style used in the capeml ecosystem with the project id + base file name + file extension. If set to false, the resulting file will bear the name the object is assigned in the R environment with the appropriate file extension.

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

EML spatialVector object is returned. Additionally, the spatial data entity is written to file as type kml or GeoJSON.

Details

create_vector creates a EML spatialVector object from a spatial data object that is read into or created within the R environment. 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 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.

All vector objects are transformed to epsg 4326 (WGS 1984)

Examples

if (FALSE) {

# load spatial vector object; because create_vector will generate a new kml or GeoJSON file, we
# have complete flexibility over the resulting file name and manipulating
# the data - here we are starting with an existing shapefile named CORETT but
# will generate a kml with the name ejido_titles_points_of_decree 

ejido_titles_points_of_decree <- sf::read_sf(
  dsn = "data/Regularizacion/ejidal",
  layer = "CORETT"
  ) %>%
select(
  -OBJECTID_1,
  -FolderNumb,
  -Surface
  ) %>%
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(
  vector_name = ejido_titles_points_of_decree,
  description = ejido_titles_points_of_decree_desc,
  driver = "kml",
  overwrite = TRUE,
  projectNaming = TRUE
  )

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

}