Adds/Retrieves longitude/latitude values to location data within an epiflows object. Coordinates are added to object's locations slot as lon and lat columns.

add_coordinates(x, coordinates = c("lon", "lat"), loc_column = "id",
  overwrite = FALSE)

get_coordinates(x, ...)

# S3 method for epiflows
get_coordinates(x, location = NULL, ...)

Arguments

x

An epiflows object.

coordinates

Either names of the appended columns with longitudes and latitudes, respectively (default: "lon" and "lat") or a data frame with longitude and latitude columns.

loc_column

Name of the column where location names are stored (default: "country").

overwrite

If TRUE, retrieves all geocodes, even those already retrieved. If FALSE (default), overwrites only NAs.

...

unused

location

a character specifying a single location to return as a vector of coordinates. You cannot specify multiple locations with this parameter. Defaults to `NULL`, indicating all locations.

Value

An updated epiflows object.

See also

Examples

# Setting up the data data("Brazil_epiflows") data("YF_coordinates") get_coordinates(Brazil_epiflows) # no coordinates yet
#> NULL
ef <- add_coordinates(Brazil_epiflows, YF_coordinates[-1]) get_coordinates(ef)
#> id lon lat #> 1 Espirito Santo -40.308863 -19.18342 #> 2 Minas Gerais -44.555031 -18.51218 #> 3 Rio de Janeiro -43.172897 -22.90685 #> 4 Sao Paulo -46.633309 -23.55052 #> 5 Southeast Brazil -46.209155 -20.33318 #> 6 Argentina -63.616672 -38.41610 #> 7 Chile -71.542969 -35.67515 #> 8 Germany 10.451526 51.16569 #> 9 Italy 12.567380 41.87194 #> 10 Paraguay -58.443832 -23.44250 #> 11 Portugal -8.224454 39.39987 #> 12 Spain -3.749220 40.46367 #> 13 United Kingdom -3.435973 55.37805 #> 14 United States of America -95.712891 37.09024 #> 15 Uruguay -55.765835 -32.52278
get_coordinates(ef, location = "Espirito Santo") # coordinates for Espirito Santo
#> [1] -40.30886 -19.18342
# You can use google maps' geocode functionality if you have a decent # internet connection ef2 <- add_coordinates(Brazil_epiflows, loc_column = "id")
#> Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Espirito%20Santo&sensor=false
#> Warning: geocode failed with status OVER_QUERY_LIMIT, location = "Espirito Santo"
#> Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Minas%20Gerais&sensor=false
#> Warning: geocode failed with status OVER_QUERY_LIMIT, location = "Minas Gerais"
#> Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Rio%20de%20Janeiro&sensor=false
#> Warning: geocode failed with status OVER_QUERY_LIMIT, location = "Rio de Janeiro"
#> Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Sao%20Paulo&sensor=false
#> Warning: geocode failed with status OVER_QUERY_LIMIT, location = "Sao Paulo"
#> Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Southeast%20Brazil&sensor=false
#> Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Argentina&sensor=false
#> Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Chile&sensor=false
#> Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Germany&sensor=false
#> Warning: geocode failed with status OVER_QUERY_LIMIT, location = "Germany"
#> Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Italy&sensor=false
#> Warning: geocode failed with status OVER_QUERY_LIMIT, location = "Italy"
#> Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Paraguay&sensor=false
#> Warning: geocode failed with status OVER_QUERY_LIMIT, location = "Paraguay"
#> .
#> Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Portugal&sensor=false
#> .
#> Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Spain&sensor=false
#> Warning: geocode failed with status OVER_QUERY_LIMIT, location = "Spain"
#> .
#> Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=United%20Kingdom&sensor=false
#> Warning: geocode failed with status OVER_QUERY_LIMIT, location = "United Kingdom"
#> .
#> Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=United%20States%20of%20America&sensor=false
#> .
#> Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Uruguay&sensor=false
ef2
#> #> /// Epidemiological Flows // #> #> // class: epiflows, epicontacts #> // 15 locations; 100 flows; directed #> // optional variables: pop_size, duration_stay, num_cases, first_date, last_date, coordinates #> #> // locations #> #> # A tibble: 15 x 8 #> id location_popula… num_cases_time_… first_date_cases last_date_cases #> * <chr> <dbl> <dbl> <fct> <fct> #> 1 Espi… 3973697 2600 2017-01-04 2017-04-30 #> 2 Mina… 20997560 4870 2016-12-19 2017-04-20 #> 3 Rio … 16635996 170 2017-02-19 2017-05-10 #> 4 Sao … 44749699 200 2016-12-17 2017-04-20 #> 5 Sout… 86356952 7840 2016-12-17 2017-05-10 #> 6 Arge… NA NA <NA> <NA> #> 7 Chile NA NA <NA> <NA> #> 8 Germ… NA NA <NA> <NA> #> 9 Italy NA NA <NA> <NA> #> 10 Para… NA NA <NA> <NA> #> 11 Port… NA NA <NA> <NA> #> 12 Spain NA NA <NA> <NA> #> 13 Unit… NA NA <NA> <NA> #> 14 Unit… NA NA <NA> <NA> #> 15 Urug… NA NA <NA> <NA> #> # ... with 3 more variables: length_of_stay <dbl>, lon <dbl>, lat <dbl> #> #> // flows #> #> # A tibble: 100 x 3 #> from to n #> <chr> <chr> <dbl> #> 1 Espirito Santo Italy 2828. #> 2 Minas Gerais Italy 15714. #> 3 Rio de Janeiro Italy 8164. #> 4 Sao Paulo Italy 34039. #> 5 Southeast Brazil Italy 76282. #> 6 Espirito Santo Spain 3270. #> 7 Minas Gerais Spain 18176. #> 8 Rio de Janeiro Spain 9443. #> 9 Sao Paulo Spain 39371. #> 10 Southeast Brazil Spain 88231. #> # ... with 90 more rows #>