• 1 Introduction
    • 1.1 About this project
      • 1.1.1 Workflow
      • 1.1.2 Reproducibility
    • 1.2 Data access
      • 1.2.1 Landscape data
    • 1.3 Published work
  • 2 Getting Elephant Data
    • 2.1 Load libraries
    • 2.2 Get elephant data from Movebank
    • 2.3 Extract useful data from move object
    • 2.4 Make elephant points into paths
    • 2.5 Make sf data frame
  • 3 Getting Background Data
    • 3.1 Load libraries
    • 3.2 Get Africa landmass from Natural Earth
    • 3.3 Get Kruger boundary
    • 3.4 Get rivers from OSM
    • 3.5 Get Waterholes
    • 3.6 Process LANDSAT data
  • 4 Mapping Elephant Movement
    • 4.1 Load libraries
    • 4.2 Load data
      • 4.2.1 Prepare extent
      • 4.2.2 Load movement data
      • 4.2.3 Load boundary data
    • 4.3 Make Africa Inset
    • 4.4 Make Kruger Inset
    • 4.5 Make Main Figure
      • 4.5.1 Prepare textbox
      • 4.5.2 Prepare movement plot
      • 4.5.3 Add decoration
      • 4.5.4 Add insets
      • 4.5.5 Add text box
      • 4.5.6 Add some labels
      • 4.5.7 Make options
      • 4.5.8 Save figure

Source code for Mapping Elephant Movements in Kruger

Section 3 Getting Background Data

3.1 Load libraries

# load libs
library(sf)
library(rnaturalearth)
library(osmdata)

3.2 Get Africa landmass from Natural Earth

# only if local data does not exist
if (!file.exists("data/africa.gpkg")) {
  # get natural earth data
  land <- ne_countries(
    continent = "africa",
    scale = "small",
    returnclass = "sf"
  )
  # save
  st_write(land, "data/africa.gpkg", append = F)
}

3.3 Get Kruger boundary

The Kruger boundary was provided by SANParks.

3.4 Get rivers from OSM

# if data does not already exist
if (!file.exists("data/rivers_kruger.gpkg")) {
  # kruger bounding box
  kruger <- st_read("data/kruger_clip/kruger_clip.shp")
  q <- opq(bbox = st_bbox(kruger))

  # make query
  query_waterways <- add_osm_feature(q,
    key = "waterway",
    value = c("river", "stream")
  )

  # run query
  rivers_kruger <- osmdata_sf(query_waterways)

  # get only lines
  rivers_kruger <- rivers_kruger$osm_lines

  # assign crs
  st_crs(rivers_kruger) <- 4326

  st_write(
    rivers_kruger,
    "data/rivers_kruger.gpkg"
  )
}

3.5 Get Waterholes

Waterhole locations were provided by Abi Vanak and Maria Thaker, originally from SANParks.

3.6 Process LANDSAT data

# do not evaluate because raster is large and not on GH
# read data
temp <- raster("data/kruger_landsat5_temp.tif")

# reproject
temp_UTM <- projectRaster(
  from = temp,
  res = 200,
  crs = st_crs(32736)$proj4string
)

# save to file
writeRaster(temp_UTM, filename = "data/kruger_temperature_UTM.tif")