Let’s get started with some hands-on exercises and exploring some data! This exercise focuses on importing different vector data geometries from various data sources and getting used to simple feature data tables.

In the folder ./data, you can find the data files prepped for all the exercises which rely on preexisting data sets. However, if you like to play around with your own data, feel free to do so! .

1

Load the administrative borders of Germany. Therefore, import the shapefile VG250_STA.shp from the respective folder and assign it to an object named “germany”.

Plot the newly created object.
Don’t forget to load the packages sf and set your working directory before starting this exercise.
library(sf)

germany <- sf::read_sf("./data/VG250_STA.shp") 

plot(germany)

The output in the console of `R gives you already some information on the data you just loaded. You also see that the object “germany” appeared in your environment. Though, we will explore the data set a little bit closer.

2

Explore the data and answer the following questions:

  • What is the geometry type?
  • What is the id of the coordinate reference system?
  • Which kind of class is the object?
  • What is the name of the column containing the information on geometries?
  • Which attributes are assigned to the geometries?
sf::st_geometry(germany) # Multipolygon: Set of several Polygons. Each row is a polygon.
## Geometry set for 11 features 
## Geometry type: MULTIPOLYGON
## Dimension:     XY
## Bounding box:  xmin: 280371.1 ymin: 5235856 xmax: 921292.4 ymax: 6106244
## Projected CRS: ETRS89 / UTM zone 32N
## First 5 geometries:
## MULTIPOLYGON (((609387.6 5267931, 609423.3 5267...
## MULTIPOLYGON (((492810 6029412, 492821.2 602927...
## MULTIPOLYGON (((816809.9 5978628, 816854.5 5978...
## MULTIPOLYGON (((502125 5972301, 502668.3 597211...
## MULTIPOLYGON (((500425.1 5285873, 500485.1 5285...
class(germany) # "sf", "tbl_df", "tbl" and "data.frame"
## [1] "sf"         "tbl_df"     "tbl"        "data.frame"
attr(germany, "sf_column") # geometry
## [1] "geometry"
sf::st_crs(germany) # ETRS89, ID = EPSG:25832
## Coordinate Reference System:
##   User input: ETRS89 / UTM zone 32N 
##   wkt:
## PROJCRS["ETRS89 / UTM zone 32N",
##     BASEGEOGCRS["ETRS89",
##         ENSEMBLE["European Terrestrial Reference System 1989 ensemble",
##             MEMBER["European Terrestrial Reference Frame 1989"],
##             MEMBER["European Terrestrial Reference Frame 1990"],
##             MEMBER["European Terrestrial Reference Frame 1991"],
##             MEMBER["European Terrestrial Reference Frame 1992"],
##             MEMBER["European Terrestrial Reference Frame 1993"],
##             MEMBER["European Terrestrial Reference Frame 1994"],
##             MEMBER["European Terrestrial Reference Frame 1996"],
##             MEMBER["European Terrestrial Reference Frame 1997"],
##             MEMBER["European Terrestrial Reference Frame 2000"],
##             MEMBER["European Terrestrial Reference Frame 2005"],
##             MEMBER["European Terrestrial Reference Frame 2014"],
##             ELLIPSOID["GRS 1980",6378137,298.257222101,
##                 LENGTHUNIT["metre",1]],
##             ENSEMBLEACCURACY[0.1]],
##         PRIMEM["Greenwich",0,
##             ANGLEUNIT["degree",0.0174532925199433]],
##         ID["EPSG",4258]],
##     CONVERSION["UTM zone 32N",
##         METHOD["Transverse Mercator",
##             ID["EPSG",9807]],
##         PARAMETER["Latitude of natural origin",0,
##             ANGLEUNIT["degree",0.0174532925199433],
##             ID["EPSG",8801]],
##         PARAMETER["Longitude of natural origin",9,
##             ANGLEUNIT["degree",0.0174532925199433],
##             ID["EPSG",8802]],
##         PARAMETER["Scale factor at natural origin",0.9996,
##             SCALEUNIT["unity",1],
##             ID["EPSG",8805]],
##         PARAMETER["False easting",500000,
##             LENGTHUNIT["metre",1],
##             ID["EPSG",8806]],
##         PARAMETER["False northing",0,
##             LENGTHUNIT["metre",1],
##             ID["EPSG",8807]]],
##     CS[Cartesian,2],
##         AXIS["(E)",east,
##             ORDER[1],
##             LENGTHUNIT["metre",1]],
##         AXIS["(N)",north,
##             ORDER[2],
##             LENGTHUNIT["metre",1]],
##     USAGE[
##         SCOPE["Engineering survey, topographic mapping."],
##         AREA["Europe between 6°E and 12°E: Austria; Belgium; Denmark - onshore and offshore; Germany - onshore and offshore; Norway including - onshore and offshore; Spain - offshore."],
##         BBOX[38.76,6,84.33,12.01]],
##     ID["EPSG",25832]]
names(germany) # Name, Area Type, Area Size, Population Size ,...
##  [1] "ADE"      "GF"       "BSG"      "ARS"      "AGS"      "SDV_ARS"  "GEN"     
##  [8] "BEZ"      "IBZ"      "BEM"      "NBD"      "SN_L"     "SN_R"     "SN_K"    
## [15] "SN_V1"    "SN_V2"    "SN_G"     "FK_S3"    "NUTS"     "ARS_0"    "AGS_0"   
## [22] "WSK"      "DEBKG_ID" "geometry"

3

Do you have an idea why there are 11 observations instead of only 1, even though we expected a shapefile with the polygon of Germany? Create a new object that contains only one observation filtered by the variable GF == 4.
# It seems like the shapefile contains not only Germany's land area but also coastal areas and lakes.
# filter 
germany_new <-
  germany %>% 
  dplyr::filter(GF == 4)

plot(germany_new)