File: data.R

package info (click to toggle)
r-cran-s2 1.1.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,540 kB
  • sloc: cpp: 124,506; ansic: 2,639; pascal: 1,495; python: 354; sh: 139; makefile: 2
file content (79 lines) | stat: -rw-r--r-- 1,980 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79

#' Low-resolution world boundaries, timezones, and cities
#'
#' Well-known binary versions of the [Natural Earth](https://www.naturalearthdata.com/)
#' low-resolution world boundaries and timezone boundaries.
#'
#' @param name The name of a country, continent, city, or `NULL`
#'   for all features.
#' @param utc_offset_min,utc_offset_max Minimum and/or maximum timezone
#'   offsets.
#'
#' @format A data.frame with columns `name` (character), and
#'   `geometry` (wk_wkb)
#' @source [Natural Earth Data](https://www.naturalearthdata.com/)
#' @examples
#' head(s2_data_countries())
#' s2_data_countries("Germany")
#' s2_data_countries("Europe")
#'
#' head(s2_data_timezones())
#' s2_data_timezones(-4)
#'
#' head(s2_data_cities())
#' s2_data_cities("Cairo")
#'
"s2_data_tbl_countries"

#' @rdname s2_data_tbl_countries
"s2_data_tbl_timezones"

#' @rdname s2_data_tbl_countries
"s2_data_tbl_cities"

#' @rdname s2_data_tbl_countries
#' @export
s2_data_countries <- function(name = NULL) {
  df <- s2::s2_data_tbl_countries
  if (is.null(name)) {
    wkb <- df$geometry
  } else {
    wkb <- df$geometry[(df$name %in% name) | (df$continent %in% name)]
  }

  as_s2_geography(wkb)
}

#' @rdname s2_data_tbl_countries
#' @export
s2_data_timezones <- function(utc_offset_min = NULL, utc_offset_max = utc_offset_min) {
  df <- s2::s2_data_tbl_timezones
  if (is.null(utc_offset_min)) {
    wkb <- df$geometry
  } else {
    matches <- (df$utc_offset >= utc_offset_min) & (df$utc_offset <= utc_offset_max)
    wkb <- df$geometry[matches]
  }

  as_s2_geography(wkb)
}

#' @rdname s2_data_tbl_countries
#' @export
s2_data_cities <- function(name = NULL) {
  df <- s2::s2_data_tbl_cities
  if (is.null(name)) {
    wkb <- df$geometry
  } else {
    wkb <- df$geometry[df$name %in% name]
  }

  as_s2_geography(wkb)
}

#' Example Geometries
#'
#' These geometries are toy examples useful for testing various coordinate
#' shuffling operations in the s2 package.
#'
"s2_data_example_wkt"