Learn R Programming

arealDB (version 0.3.9)

normGeometry: Normalise geometries

Description

Harmonise and integrate geometries in a standardised format

Usage

normGeometry(
  input = NULL,
  ...,
  thresh = 10,
  outType = "gpkg",
  pattern = NULL,
  update = FALSE,
  verbose = FALSE
)

Arguments

input

[character(1)] path of the file to normalise. If this is left empty, all files at stage two as subset by pattern are chosen.

...

[character(.)] a subset of administrative units as given by nation, continent, region, subregion or un_member = TRUE/FALSE. Valid selection criteria and their values are in the object countries.

thresh

[integerish(1)] the deviation of percentage of overlap above which to consider two territorial units "different".

outType

[character(1)] the output file-type, see st_drivers for a list. If a file-type supports layers, they are stored in the same file, otherwise the different layers are provided separately. For an R-based workflow, "rds" could be an efficient option.

pattern

[character(1)] an optional regular expression. Only dataset names which match the regular expression will be returned.

update

[logical(1)] whether or not the physical files should be updated (TRUE) or the function should merely return the geometry inventory of the handled files (FALSE, default). This is helpful to check whether the metadata specification and the provided file(s) are properly specified.

verbose

[logical(1)] be verbose about what is happening (default FALSE). Furthermore, you can use suppressMessages to make this function completely silent.

Value

This function harmonises and integrates so far unprocessed geometries at stage two into stage three of the geospatial database. It produces for each nation in the registered geometries a spatial file of the specified file-type.

Details

To normalise geometries, this function proceeds as follows:

  1. Read in input and extract initial metadata from the file name.

  2. Loop through every nation potentially included in the file that shall be processed and carry out the following steps:

    • In case the geometries are provided as a list of simple feature POLYGONS, they are dissolved into a single MULTIPOLYGON per nation.

    • In case the nation to which a geometry belongs has not yet been created at stage three, the following steps are carried out:

      1. Check whether the recent dataset is GADM, to build the initial administrative hierarchy from GADM geometries, and stop if this is not the case.

      2. Extract the full hierarchy of all territorial units that are part of the geometry.

      3. Reconstruct ahID from the intermediate spatial objects and from the metadata.

    • In case the nation to which the geometry belongs has already been created, the following steps are carried out:

      1. Check whether the new geometries have the same coordinate reference system as the already existing database and re-project the new geometries if this is not the case.

      2. Check whether all new geometries are already exactly matched spatially and stop if that is the case.

      3. Check whether the new geometries are all within the already defined parents, and save those that are not as a new geometry.

      4. Calculate spatial overlap and distinguish the geometries into those that overlap with more and those with less than thresh.

      5. For all units that did match, copy ahID from the geometries they overlap.

      6. For all units that did not match, rebuild metadata and a new ahID.

    • If update = TRUE, store the processed geometry at stage three.

  3. Move the geometry to the folder '/processed', if it is fully processed.

See Also

Other normalisers: normTable()

Examples

Run this code
# NOT RUN {
library(sf)

# build the example database
makeExampleDB(until = "regGeometry")

# normalise all geometries ...
normGeometry(nation = "estonia", update = TRUE)

# ... and check the result
st_layers(paste0(tempdir(), "/newDB/adb_geometries/stage3/Estonia.gpkg"))
output <- st_read(paste0(tempdir(), "/newDB/adb_geometries/stage3/Estonia.gpkg"))
# }

Run the code above in your browser using DataLab