Skip to contents

This function imports geographic data from files. It handles shapefiles specifically, as they consist of multiple files. The function checks for the presence of shapefiles and reads them accordingly.

Usage

read_geo_file(x)

Arguments

x

A character vector of file path(s) to the geographic data file(s).

Value

A sf object representing the imported geographic data.

Details

This function is designed to read geographic data files, it's a wrapper around the sf::read_sf() function. It checks if the input files are shapefiles and handles them accordingly. If the input files are not shapefiles, it reads them directly using sf::read_sf().

Examples

tun_files <-
    system.file(
      package = "riskintrodata",
      "samples",
      "tunisia",
      "epi_units", "tunisia_adm2_raw.gpkg"
    )
read_geo_file(tun_files)
#> Simple feature collection with 268 features and 13 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: 7.530076 ymin: 30.23681 xmax: 11.59826 ymax: 37.55986
#> Geodetic CRS:  WGS 84
#> # A tibble: 268 × 14
#>    GID_2  GID_0 COUNTRY GID_1 NAME_1 NL_NAME_1 NAME_2 VARNAME_2 NL_NAME_2 TYPE_2
#>    <chr>  <chr> <chr>   <chr> <chr>  <chr>     <chr>  <chr>     <chr>     <chr> 
#>  1 TUN.1… TUN   Tunisia TUN.… Ariana NA        Arian… Ariana M… NA        Deleg…
#>  2 TUN.1… TUN   Tunisia TUN.… Ariana NA        Ettad… NA        NA        Deleg…
#>  3 TUN.1… TUN   Tunisia TUN.… Ariana NA        Kalaa… NA        NA        Deleg…
#>  4 TUN.1… TUN   Tunisia TUN.… Ariana NA        Mnihla NA        NA        Deleg…
#>  5 TUN.1… TUN   Tunisia TUN.… Ariana NA        Raoued NA        NA        Deleg…
#>  6 TUN.1… TUN   Tunisia TUN.… Ariana NA        Sebkh… NA        NA        Water…
#>  7 TUN.1… TUN   Tunisia TUN.… Ariana NA        Sidi … NA        NA        Deleg…
#>  8 TUN.1… TUN   Tunisia TUN.… Ariana NA        Soukra NA        NA        Deleg…
#>  9 TUN.2… TUN   Tunisia TUN.… Béja   NA        Amdoun NA        NA        Deleg…
#> 10 TUN.2… TUN   Tunisia TUN.… Béja   NA        Béja … NA        NA        Deleg…
#> # ℹ 258 more rows
#> # ℹ 4 more variables: ENGTYPE_2 <chr>, CC_2 <chr>, HASC_2 <chr>,
#> #   geom <MULTIPOLYGON [°]>

nga_files <- system.file(
  package = "riskintrodata",
  "samples",
  "nigeria",
  "epi_units",
  "NGA-ADM1.geojson"
)
read_geo_file(nga_files)
#> Simple feature collection with 37 features and 5 fields
#> Geometry type: POLYGON
#> Dimension:     XY
#> Bounding box:  xmin: 2.692613 ymin: 4.270204 xmax: 14.67797 ymax: 13.88571
#> Geodetic CRS:  WGS 84
#> # A tibble: 37 × 6
#>    shapeName     shapeISO shapeID shapeGroup shapeType                  geometry
#>    <chr>         <chr>    <chr>   <chr>      <chr>                 <POLYGON [°]>
#>  1 Cross River   NG-CR    276711… NGA        ADM1      ((8.274303 4.854739, 8.3…
#>  2 Abuja Federa… NG-FC    276711… NGA        ADM1      ((6.980815 8.443728, 7.0…
#>  3 Ogun          NG-OG    276711… NGA        ADM1      ((4.483238 6.326054, 4.4…
#>  4 Oyo           NG-OY    276711… NGA        ADM1      ((4.088356 7.133446, 4.0…
#>  5 Sokoto        NG-SO    276711… NGA        ADM1      ((4.126405 13.24967, 4.1…
#>  6 Zamfara       NG-ZA    276711… NGA        ADM1      ((4.941011 11.73083, 4.9…
#>  7 Lagos         NG-LA    276711… NGA        ADM1      ((2.704644 6.459847, 2.6…
#>  8 Akwa Ibom     NG-AK    276711… NGA        ADM1      ((7.88037 5.366796, 7.87…
#>  9 Bayelsa       NG-BY    276711… NGA        ADM1      ((5.448385 5.133691, 5.4…
#> 10 Ondo          NG-ON    276711… NGA        ADM1      ((4.483238 6.326054, 4.5…
#> # ℹ 27 more rows