GIS: Geodata Functions

GISR Documentation

Geodata Functions

Description

These are functions to work with geographical data. To determine coordinates based on a location (or vice versa), use geocode() / reverse_geocode().

Usage

get_map(maptype = "postcodes4")

add_map(data, maptype = NULL, by = NULL, crop_certe = TRUE)

is.sf(sf_data)

as.sf(data)

crop_certe(sf_data)

filter_geolocation(sf_data, ...)

filter_sf(sf_data, xmin = NULL, xmax = NULL, ymin = NULL, ymax = NULL)

convert_to_degrees_CRS4326(sf_data)

convert_to_metre_CRS28992(sf_data)

degrees_to_sf(longitudes, latitudes, crs = 28992)

latitude(sf_data)

longitude(sf_data)

Arguments

maptype

type of geometric data, must be one of: "gemeenten", "ggdregios", "nuts3", "postcodes2", "postcodes3", "postcodes4", "postcodes6", "provincies". For add_map(), this is determined automatically if left blank.

data

data set to join left to the geodata

by

column to join by

crop_certe

logical to keep only the Certe region

sf_data

a data set of class 'sf'

...

filters to set

xmin, xmax, ymin, ymax

coordination filters for sf_data, given in degrees following EPSG:4326 ('WGS 84')

longitudes

vector of longitudes

latitudes

vector of latitudes

crs

the coordinate reference system (CRS) to use as output

Details

All of these functions will check if the sf package is installed, and will load its namespace (but not attach the package).

crop_certe() cuts any geometry to the Certe region (more of less): the Northern three provinces of the Netherlands and municipalities of Noordoostpolder, Urk, and Steenwijkerland. This will be based on postcodes.

filter_geolocation() filters an sf object on qualitative values such as 'gemeente' and 'provincie'. The input data sf_data will be joined with postcodes and filtering can thus be done on any of these columns: postcode, inwoners, inwoners_man, inwoners_vrouw, plaats, gemeente, provincie, nuts3, ggdregio.

filter_sf() filters an sf object on coordinates, and is internally used by crop_certe().

convert_to_degrees_CRS4326() will transform SF data to WGS 84 – WGS84 - World Geodetic System 1984, used in GPS, CRS 4326.

convert_to_metre_CRS28992() will transform SF data to Amersfoort / RD New – Netherlands - Holland - Dutch, CRS 28992.

latitude() specifies the north-south position ('y axis') and longitude() specifies the east-west position ('x axis'). They return the numeric coordinate of the centre of a simple feature.

Value

An sf model. The column with geodata is always called "geometry".

Examples

# Retrieving and joining maps ------------------------------------------

get_map() # defaults to the geo_postcodes4 data set

# adding a map applies a RIGHT JOIN to get all relevant geometric data
data.frame(postcode = 7753, number_of_cases = 3) |> 
  add_map()


# Cropping to Certe region ---------------------------------------------

# Note: provinces do not include Flevoland
geo_provincies |> crop_certe()

# but other geometries do, such as geo_gemeenten
if (require("certeplot2")) {
  geo_gemeenten |> crop_certe() |>    # cropped municipalities
    plot2(title = "Certe Region") |>
    add_sf(
      geo_provincies |> crop_certe(), # cropped provinces
      colour_fill = NA,
      colour = "black",
      linewidth = 0.5)
}


# Filtering geometries -------------------------------------------------

geo_gemeenten |>
  crop_certe() |>
  # notice that the `provincie` column is not even in `geo_gemeenten`
  filter_geolocation(provincie == "Flevoland")
  
geo_gemeenten |>
  crop_certe() |>
  filter_geolocation(inwoners_vrouw >= 50000)

if (require("certeplot2")) {
  geo_postcodes4 |> 
    filter_geolocation(gemeente == "Tytsjerksteradiel") |> 
    plot2(category = inwoners,
          datalabels = postcode)

}

# filter on a latitude of 52.5 degrees and higher
geo_provincies |> filter_sf(ymin = 52.5)


# Transforming Coordinate Reference System (CRS) -----------------------

geo_provincies |> convert_to_degrees_CRS4326()

geo_provincies |> convert_to_metre_CRS28992()


# Other functions ------------------------------------------------------

degrees_to_sf(4.5, 54)

if (require("certeplot2")) {
  geo_provincies |>
      crop_certe() |> 
      plot2(category = NULL, colour_fill = NA) |> 
      add_sf(degrees_to_sf(6.5, 53),
             datalabels = "Some Point!")
}

latitude(geo_provincies)
longitude(geo_provincies)

certe-medical-epidemiology/certegis documentation built on Dec. 10, 2024, 6:27 a.m.