Title: | Tools for converting QuadKey-identified datasets (Microsoft's Bing Maps Tile System) into raster images and analyzing Meta (Facebook) Mobility Data. |
---|---|
Description: | 'Quadkeyr' functions generate raster images based on QuadKey-identified data, facilitating efficient integration of Tile Maps data into R workflows. In particular, 'Quadkeyr' provides support to process and analyze Facebook mobility datasets within the R environment. |
Authors: | Florencia D'Andrea [aut, cre] , Pilar Fernandez [aut] , Maria Paula Caldas [rev] (<https://orcid.org/0000-0002-1938-6471>, Maria Paula Caldas reviewed the package (v. 0.0.0.9000) for rOpenSci, see https://github.com/ropensci/software-review/issues/619), Vincent van Hees [rev] (<https://orcid.org/0000-0003-0182-9008>, Vincent van Hees reviewed the package (v. 0.0.0.9000) for rOpenSci, see https://github.com/ropensci/software-review/issues/619), CDC's Center for Forecasting and Outbreak Analytics [fnd] (This project was made possible by cooperative agreement CDC-RFA-FT-23-0069 (grant # NU38FT000009-01-00) from the CDC's Center for Forecasting and Outbreak Analytics. Its contents are solely the responsibility of the authors and do not necessarily represent the official views of the Centers for Disease Control and Prevention.), MIDAS-NIH COVID-19 urgent grant program [fnd], Paul G. Allen School for Global Health, Washington State University [cph] |
Maintainer: | Florencia D'Andrea <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0 |
Built: | 2024-10-28 05:53:05 UTC |
Source: | https://github.com/ropensci/quadkeyr |
quadkey
column of a data.frame.This function estimates the bounding box of the quadkeys given in the quadkey column and adds rows to complete the quadkeys and the geometry needed to create a regular grid. All other columns for the introduced QuadKeys will be filled with NAs.
For a detailed explanation on how to use this
and other similar quadkeyr
functions,
read the the vignette:
https://fernandez-lab-wsu.github.io/quadkeyr/articles/quadkey_identified_data_to_raster.html
add_regular_polygon_grid(data)
add_regular_polygon_grid(data)
data |
A data.frame with a |
A list with three elements:
data
A sf
POLYGON data.frame with all the QuadKeys within
the bounding box of the ones provided in the quadkey
column
of the input dataset, and the rest of the original variables.
The columns quadkey
and geometry
are returned for all the grid,
The values of the newly added QuadKeys will be NA
for the rest of the variables.
num_rows
The number of columns of the regular grid.
num_cols
The number of rows of the regular grid.
# read the file with the data path <- paste0( system.file("extdata", package = "quadkeyr"), "/cityA_2020_04_15_0000.csv" ) data <- read.csv(path) data <- format_fb_data(data) add_regular_polygon_grid(data = data)
# read the file with the data path <- paste0( system.file("extdata", package = "quadkeyr"), "/cityA_2020_04_15_0000.csv" ) data <- read.csv(path) data <- format_fb_data(data) add_regular_polygon_grid(data = data)
n_crisis
Applying a week lag to the data will create raster images
showing the mobility a week before the date of interest.
This function works only for QuadKeys reported without NAs for
n_crisis
and percent_change
variables .
apply_weekly_lag(data)
apply_weekly_lag(data)
data |
A data.frame with the columns |
A data.frame with the extra columns n_crisis_lag_7
and
percent_change_7
.
n_crisis_lag_7
, is the same variable defined as n_crisis
in the Facebook mobility data.frame with a 7 day lag applied.
percent_change_7
is the difference between
the n_crisis
value between weeks expressed as percentage.
files <- read_fb_mobility_files( path_to_csvs = paste0(system.file("extdata", package = "quadkeyr" ), "/"), colnames = c( "lat", "lon", "quadkey", "date_time", "n_crisis", "percent_change" ), coltypes = list( lat = "d", lon = "d", quadkey = "c", date_time = "T", n_crisis = "c", percent_change = "c" ) ) apply_weekly_lag(data = files)
files <- read_fb_mobility_files( path_to_csvs = paste0(system.file("extdata", package = "quadkeyr" ), "/"), colnames = c( "lat", "lon", "quadkey", "date_time", "n_crisis", "percent_change" ), coltypes = list( lat = "d", lon = "d", quadkey = "c", date_time = "T", n_crisis = "c", percent_change = "c" ) ) apply_weekly_lag(data = files)
Generates a grid comprising all the QuadKeys within the area defined by the maximum and minimum coordinates of latitude and longitude along with a specified zoom level.
create_qk_grid(xmin, xmax, ymin, ymax, zoom)
create_qk_grid(xmin, xmax, ymin, ymax, zoom)
xmin |
Minimum value in the x axis (longitude) |
xmax |
Maximum value in the y axis (latitude) |
ymin |
Minimum value in the x axis (longitude) |
ymax |
Maximum value in the Y axis (latitude) |
zoom |
Zoom or level of detail, from 1 (lowest detail) to 23 (highest detail). |
A list returning the QuadKeys as a data.frame (data
),
the number of rows (num_rows
)
and columns (num_cols
) of the grid.
grid <- create_qk_grid( xmin = -59, xmax = -57, ymin = -35, ymax = -34, zoom = 12 )
grid <- create_qk_grid( xmin = -59, xmax = -57, ymin = -35, ymax = -34, zoom = 12 )
stars
rasterThe use of a template enables the creation of an accurate raster, even in the presence of NAs.
create_stars_raster(template, nx, ny, data, var)
create_stars_raster(template, nx, ny, data, var)
template |
A |
nx |
Integer; number of cells in x direction. |
ny |
Integer; number of cells in y direction. |
data |
A |
var |
The column name of the variable to plot. |
A stars
object.
# Basic workflow # read the file with the data path <- paste0( system.file("extdata", package = "quadkeyr"), "/cityA_2020_04_15_0000.csv" ) data <- read.csv(path) data <- format_fb_data(data) complete_polygon_grid <- add_regular_polygon_grid(data = data) stars_object <- create_stars_raster( data = complete_polygon_grid$data, template = complete_polygon_grid$data, var = "percent_change", nx = complete_polygon_grid$num_cols, ny = complete_polygon_grid$num_rows ) stars_object # Other workflow grid <- create_qk_grid( xmin = -59, xmax = -57, ymin = -35, ymax = -34, zoom = 12 ) grid_coords <- get_qk_coord(data = grid$data) polygrid <- grid_to_polygon(grid_coords) data("data_provided") data_raster <- polygrid |> dplyr::inner_join(data_provided, by = c("quadkey") ) raster <- create_stars_raster( template = data_raster, nx = grid$num_cols, ny = grid$num_rows, data = data_raster, var = "variable" )
# Basic workflow # read the file with the data path <- paste0( system.file("extdata", package = "quadkeyr"), "/cityA_2020_04_15_0000.csv" ) data <- read.csv(path) data <- format_fb_data(data) complete_polygon_grid <- add_regular_polygon_grid(data = data) stars_object <- create_stars_raster( data = complete_polygon_grid$data, template = complete_polygon_grid$data, var = "percent_change", nx = complete_polygon_grid$num_cols, ny = complete_polygon_grid$num_rows ) stars_object # Other workflow grid <- create_qk_grid( xmin = -59, xmax = -57, ymin = -35, ymax = -34, zoom = 12 ) grid_coords <- get_qk_coord(data = grid$data) polygrid <- grid_to_polygon(grid_coords) data("data_provided") data_raster <- polygrid |> dplyr::inner_join(data_provided, by = c("quadkey") ) raster <- create_stars_raster( template = data_raster, nx = grid$num_cols, ny = grid$num_rows, data = data_raster, var = "variable" )
This function removes unnecessary characters such as \\N
and ensures that the format of the date and QuadKeys is correct.
format_fb_data(data, keep_format = NULL)
format_fb_data(data, keep_format = NULL)
data |
A data.frame with a |
keep_format |
Vector of column names,
besides |
A data.frame without \N
,
quadkey
without scientific notation and
a new column day
and hour
data(result_read_fb_mobility_data) format_fb_data(data = result_read_fb_mobility_data)
data(result_read_fb_mobility_data) format_fb_data(data = result_read_fb_mobility_data)
Reads the QuadKey as a string and extracts the lat/long coordinates of the upper-left corner of the QuadKey.
get_qk_coord(data)
get_qk_coord(data)
data |
A dataframe with a quadkey column. |
A sf
POINT data.frame containing the tiles XY coordinates
(tileX
, tileY
), the QuadKeys (quadkey
), and a geometry
column.
grid <- create_qk_grid( xmin = -59, xmax = -40, ymin = -38, ymax = -20, zoom = 6 ) # quadkey column in grid$data converted to geographic coordinates grid_coords <- get_qk_coord(data = grid$data) plot(grid_coords)
grid <- create_qk_grid( xmin = -59, xmax = -40, ymin = -38, ymax = -20, zoom = 6 ) # quadkey column in grid$data converted to geographic coordinates grid_coords <- get_qk_coord(data = grid$data) plot(grid_coords)
quadkey
column of a data.frame.This function estimates the bounding box of the QuadKeys given in the
quadkey
column and adds the rows needed to complete a regular grid.
For a detailed explanation on how to use this
and other similar quadkeyr
functions,
read the the vignette:
https://fernandez-lab-wsu.github.io/quadkeyr/articles/facebook_mobility_csvs_to_raster_files.html
get_regular_polygon_grid(data)
get_regular_polygon_grid(data)
data |
A data.frame with a |
A list with three elements:
data
An sf
POLYGON data.frame with all the QuadKeys within
the bounding box of the quadkey
column of a data.frame.
Only the columns quadkey
, tileX
, tileY
and geometry
are returned.
num_rows
The number of columns of the regular grid.
num_cols
The number of rows of the regular grid.
# data file path <- paste0( system.file("extdata", package = "quadkeyr"), "/cityA_2020_04_15_0000.csv" ) data <- read.csv(path) data <- format_fb_data(data) get_regular_polygon_grid(data = data)
# data file path <- paste0( system.file("extdata", package = "quadkeyr"), "/cityA_2020_04_15_0000.csv" ) data <- read.csv(path) data <- format_fb_data(data) get_regular_polygon_grid(data = data)
The main argument of this function, the grid of
geographic coordinates (lat/long WG84) represents the upper-left
corner of the QuadKey.
To transform these coordinates into square polygons, the function
supplements the grid by adding a row and column of tiles. These points
introduce QuadKeys located at the border of the area using the internal
function complete_grid_for_polygons()
.
The function constructs the polygons using all the points of the grid.
Note that it's possible to associate each QuadKey with its square polygon.
grid_to_polygon(data)
grid_to_polygon(data)
data |
A |
A sf POLYGON data.frame with a quadkey column.
grid <- create_qk_grid( xmin = -59, xmax = -57, ymin = -35, ymax = -34, zoom = 11 ) grid_coords <- get_qk_coord(data = grid$data) polygrid <- grid_to_polygon(grid_coords) polygrid
grid <- create_qk_grid( xmin = -59, xmax = -57, ymin = -35, ymax = -34, zoom = 11 ) grid_coords <- get_qk_coord(data = grid$data) polygrid <- grid_to_polygon(grid_coords) polygrid
Determines the ground resolution (in meters per pixel) at a specified latitude and zoom level. For further information, refer to the Microsoft Bing Maps Tile System documentation.
ground_res(latitude, zoom)
ground_res(latitude, zoom)
latitude |
Latitude (in degrees) at which to measure the ground resolution. |
zoom |
Zoom or level of detail, from 1 (lowest detail) to 23 (highest detail). |
the ground resolution (meters / pixel)
https://learn.microsoft.com/en-us/bingmaps/articles/bing-maps-tile-system
ground_res( latitude = 0, zoom = 6 )
ground_res( latitude = 0, zoom = 6 )
Converts a point from latitude/longitude WGS-84 coordinates (in degrees) into pixel XY coordinates at a specified zoom level. For further information, refer to the Microsoft Bing Maps Tile System documentation.
latlong_to_pixelXY(lat, lon, zoom)
latlong_to_pixelXY(lat, lon, zoom)
lat |
Latitude of the point, in degrees. |
lon |
Longitude of the point, in degrees. |
zoom |
Zoom or level of detail, from 1 (lowest detail) to 23 (highest detail). |
Converting latitude/longitude coordinates into a QuadKey and then back to latitude/longitude won't yield identical values, unless the initial latitude/longitude coordinates correspond to the upper-left Quadkey's pixel and tile XY coordinates at the same zoom level.
Understanding this distinction is crucial for the accurate use of these functions in coordinate conversions.
For a detailed explanation on how to use this
and other similar quadkeyr
functions,
read the the vignette:
https://fernandez-lab-wsu.github.io/quadkeyr/articles/quadkey_to_sf_conversion.html
A list returning pixel X and pixel Y coordinates.
https://learn.microsoft.com/en-us/bingmaps/articles/bing-maps-tile-system
latlong_to_pixelXY( lat = -35, lon = -50, zoom = 6 )
latlong_to_pixelXY( lat = -35, lon = -50, zoom = 6 )
Converts a point from latitude/longitude WGS-84 coordinates (in degrees) into a Quadkey at a specified zoom level. For further information, refer to the Microsoft Bing Maps Tile System documentation.
latlong_to_quadkey(lat, lon, zoom)
latlong_to_quadkey(lat, lon, zoom)
lat |
Latitude of the point, in degrees. |
lon |
Longitude of the point, in degrees. |
zoom |
Zoom or level of detail, from 1 (lowest detail) to 23 (highest detail). |
Converting latitude/longitude coordinates into a QuadKey and then back to latitude/longitude won't yield identical values, unless the initial latitude/longitude coordinates correspond to the upper-left Quadkey's pixel and tile XY coordinates at the same zoom level.
Understanding this distinction is crucial for the accurate use of these functions in coordinate conversions.
For a detailed explanation on how to use this
and other similar quadkeyr
functions,
read the the vignette:
https://fernandez-lab-wsu.github.io/quadkeyr/articles/quadkey_to_sf_conversion.html
A dataframe with latitude (lat), longitude (lon), zoom level (zoom) and the QuadKey as a string (quadkey).
https://learn.microsoft.com/en-us/bingmaps/articles/bing-maps-tile-system
latlong_to_quadkey( lat = 35.63051, lon = 139.69116, zoom = 20 ) latlong_to_quadkey( lat = c(-4, -25.33, -25.66), lon = c(-53, -60.33, -70.66), zoom = 4 )
latlong_to_quadkey( lat = 35.63051, lon = 139.69116, zoom = 20 ) latlong_to_quadkey( lat = c(-4, -25.33, -25.66), lon = c(-53, -60.33, -70.66), zoom = 4 )
Determines the map scale at a specified latitude, zoom level, and screen resolution. For further information, refer to the Microsoft Bing Maps Tile System documentation.
mapscale(latitude, zoom, screen_dpi)
mapscale(latitude, zoom, screen_dpi)
latitude |
Latitude (in degrees) at which to measure the map scale. |
zoom |
Zoom or level of detail, from 1 (lowest detail) to 23 (highest detail). |
screen_dpi |
Resolution of the screen, in dots per inch. |
The map scale, expressed as the denominator N of the ratio 1 : N.
https://learn.microsoft.com/en-us/bingmaps/articles/bing-maps-tile-system
mapscale( latitude = 0, zoom = 6, screen_dpi = 96 )
mapscale( latitude = 0, zoom = 6, screen_dpi = 96 )
Determines the map width and height (in pixels) at a specified zoom level. For further information, refer to the Microsoft Bing Maps Tile System documentation.
mapsize(zoom)
mapsize(zoom)
zoom |
Zoom or level of detail, from 1 (lowest detail) to 23 (highest detail). |
The map width and height in pixels.
https://learn.microsoft.com/en-us/bingmaps/articles/bing-maps-tile-system
mapsize(zoom = 6)
mapsize(zoom = 6)
Facebook mobility data is reported daily at 3 different hours (0, 8, 16). This function reads the data extracted from the current files and detects if any file for a particular day or hour is missing.
missing_combinations(data)
missing_combinations(data)
data |
A data.frame with a |
A data.frame with the missing days and hours, if any.
# Sample dataset data <- data.frame( country = c("US", "MX", "MX"), day = c("2023-01-01", "2023-01-03", "2023-01-05"), hour = c(0, 8, 16) ) missing_combinations(data)
# Sample dataset data <- data.frame( country = c("US", "MX", "MX"), day = c("2023-01-01", "2023-01-03", "2023-01-05"), hour = c(0, 8, 16) ) missing_combinations(data)
Converts a pixel from pixel XY coordinates at a specified zoom level into latitude/longitude WGS-84 coordinates (in degrees). For further information, refer to the Microsoft Bing Maps Tile System documentation.
pixelXY_to_latlong(pixelX, pixelY, zoom)
pixelXY_to_latlong(pixelX, pixelY, zoom)
pixelX |
X coordinate of the point, in pixels. |
pixelY |
Y coordinates of the point, in pixels. |
zoom |
Zoom or level of detail, from 1 (lowest detail) to 23 (highest detail). |
Converting latitude/longitude coordinates into a QuadKey and then back to latitude/longitude won't yield identical values, unless the initial latitude/longitude coordinates correspond to the upper-left QuadKey's pixel and tile XY coordinates at the same zoom level.
Understanding this distinction is crucial for the accurate use of these functions in coordinate conversions.
For a detailed explanation on how to use this
and other similar quadkeyr
functions,
read the the vignette:
https://fernandez-lab-wsu.github.io/quadkeyr/articles/quadkey_to_sf_conversion.html
A list with the longitude and latitude.
https://learn.microsoft.com/en-us/bingmaps/articles/bing-maps-tile-system
pixelXY_to_latlong( pixelX = 768, pixelY = 1280, zoom = 3 )
pixelXY_to_latlong( pixelX = 768, pixelY = 1280, zoom = 3 )
Converts pixel XY coordinates into tile XY coordinates of the tile containing the specified pixel. For further information, refer to the Microsoft Bing Maps Tile System documentation.
pixelXY_to_tileXY(pixelX, pixelY)
pixelXY_to_tileXY(pixelX, pixelY)
pixelX |
Pixel X coordinate. |
pixelY |
Pixel Y coordinate. |
Converting latitude/longitude coordinates into a QuadKey and then back to latitude/longitude won't yield identical values, unless the initial latitude/longitude coordinates correspond to the upper-left Quadkey's pixel and tile XY coordinates at the same zoom level.
Understanding this distinction is crucial for the accurate use of these functions in coordinate conversions.
For a detailed explanation on how to use this
and other similar quadkeyr
functions,
read the the vignette:
https://fernandez-lab-wsu.github.io/quadkeyr/articles/quadkey_to_sf_conversion.html
A list returning the tile X and tile Y coordinates.
https://learn.microsoft.com/en-us/bingmaps/articles/bing-maps-tile-system
pixelXY_to_tileXY( pixelX = 5916, pixelY = 9894 )
pixelXY_to_tileXY( pixelX = 5916, pixelY = 9894 )
Creates one raster by each date and time reported and
saves it as a .tif
.
polygon_to_raster( data, nx, ny, template, var = "percent_change", filename, path )
polygon_to_raster( data, nx, ny, template, var = "percent_change", filename, path )
data |
A |
nx |
Integer; number of cells in x direction. |
ny |
Integer; number of cells in y direction. |
template |
A |
var |
The column name of the variable to plot. |
filename |
Select a name for the file. The date and time will be included automatically in the name. |
path |
Path where the files should be stored. |
as many .tif files as dates and times in the dataset
files <- read_fb_mobility_files( path_to_csvs = paste0(system.file("extdata", package = "quadkeyr" ), "/"), colnames = c( "lat", "lon", "quadkey", "date_time", "n_crisis", "percent_change" ), coltypes = list( lat = "d", lon = "d", quadkey = "c", date_time = "T", n_crisis = "c", percent_change = "c" ) ) # Get a regular grid and create the polygons regular_grid <- get_regular_polygon_grid(data = files) # Keep only the QuadKeys reported files_polygons <- files |> dplyr::inner_join(regular_grid$data, by = c("quadkey") ) ## Not run: # Generate the raster files polygon_to_raster( data = files_polygons, nx = regular_grid$num_cols, ny = regular_grid$num_rows, template = files_polygons, var = "percent_change", filename = "cityA", path = paste0( system.file("extdata", package = "quadkeyr" ), "/" ) ) ## End(Not run)
files <- read_fb_mobility_files( path_to_csvs = paste0(system.file("extdata", package = "quadkeyr" ), "/"), colnames = c( "lat", "lon", "quadkey", "date_time", "n_crisis", "percent_change" ), coltypes = list( lat = "d", lon = "d", quadkey = "c", date_time = "T", n_crisis = "c", percent_change = "c" ) ) # Get a regular grid and create the polygons regular_grid <- get_regular_polygon_grid(data = files) # Keep only the QuadKeys reported files_polygons <- files |> dplyr::inner_join(regular_grid$data, by = c("quadkey") ) ## Not run: # Generate the raster files polygon_to_raster( data = files_polygons, nx = regular_grid$num_cols, ny = regular_grid$num_rows, template = files_polygons, var = "percent_change", filename = "cityA", path = paste0( system.file("extdata", package = "quadkeyr" ), "/" ) ) ## End(Not run)
This function launches the Shiny app.
qkmap_app()
qkmap_app()
This function does not return any value. It launches the Shiny app.
## Not run: qkmap_app() ## End(Not run)
## Not run: qkmap_app() ## End(Not run)
quadkey
column to a sf
POLYGON data.frameConvert data.frame with quadkey
column to a sf
POLYGON data.frame
quadkey_df_to_polygon(data)
quadkey_df_to_polygon(data)
data |
A data.frame with a |
The same original data.frame with a sf
POLYGON data.frame with a
geometry
column.
# Quadkey as string quadkey_to_polygon(quadkey = "213") # QuadKeys as column in a data.frame # get data file path <- paste0( system.file("extdata", package = "quadkeyr"), "/cityA_2020_04_15_0000.csv" ) data <- read.csv(path) data <- format_fb_data(data) quadkey_df_to_polygon(data = data)
# Quadkey as string quadkey_to_polygon(quadkey = "213") # QuadKeys as column in a data.frame # get data file path <- paste0( system.file("extdata", package = "quadkeyr"), "/cityA_2020_04_15_0000.csv" ) data <- read.csv(path) data <- format_fb_data(data) quadkey_df_to_polygon(data = data)
This function converts Quadkeys to latitude/longitude WGS-84 coordinates (in degrees). For further information, refer to the Microsoft Bing Maps Tile System documentation.
quadkey_to_latlong(quadkey_data)
quadkey_to_latlong(quadkey_data)
quadkey_data |
A single QuadKey as a string or a vector with unique QuadKeys. |
Converting latitude/longitude coordinates into a QuadKey and then back to latitude/longitude won't yield identical values, unless the initial latitude/longitude coordinates correspond to the upper-left Quadkey's pixel and tile XY coordinates at the same zoom level.
Understanding this distinction is crucial for the accurate use of these functions in coordinate conversions.
For a detailed explanation on how to use this
and other similar quadkeyr
functions,
read the the vignette:
https://fernandez-lab-wsu.github.io/quadkeyr/articles/quadkey_to_sf_conversion.html
A sf POINT data.frame with a quadkey
column.
The latitude/longitude coordinates represent
the upper-left corner of the QuadKey.
https://learn.microsoft.com/en-us/bingmaps/articles/bing-maps-tile-system
quadkey_to_latlong(quadkey_data = "213") quadkey_to_latlong(quadkey_data = c("213", "212", "210"))
quadkey_to_latlong(quadkey_data = "213") quadkey_to_latlong(quadkey_data = c("213", "212", "210"))
This functions creates a sf
POLYGON data.frame from a QuadKey string.
quadkey_to_polygon(quadkey)
quadkey_to_polygon(quadkey)
quadkey |
The QuadKey as a string |
A sf
POLYGON data.frame with a quadkey
and geometry
column.
# Quadkey as string quadkey_to_polygon(quadkey = "213") # QuadKeys as column in a data.frame # get data file path <- paste0( system.file("extdata", package = "quadkeyr"), "/cityA_2020_04_15_0000.csv" ) data <- read.csv(path) data <- format_fb_data(data) quadkey_df_to_polygon(data = data)
# Quadkey as string quadkey_to_polygon(quadkey = "213") # QuadKeys as column in a data.frame # get data file path <- paste0( system.file("extdata", package = "quadkeyr"), "/cityA_2020_04_15_0000.csv" ) data <- read.csv(path) data <- format_fb_data(data) quadkey_df_to_polygon(data = data)
For further information, refer to the Microsoft Bing Maps Tile System documentation.
quadkey_to_tileXY(quadkey)
quadkey_to_tileXY(quadkey)
quadkey |
A QuadKey as a single string. |
Converting latitude/longitude coordinates into a QuadKey and then back to latitude/longitude won't yield identical values, unless the initial latitude/longitude coordinates correspond to the upper-left QuadKey's pixel and tile XY coordinates at the same zoom level.
Understanding this distinction is crucial for the accurate use of these functions in coordinate conversions.
For a detailed explanation on how to use this
and other similar quadkeyr
functions,
read the the vignette:
https://fernandez-lab-wsu.github.io/quadkeyr/articles/quadkey_to_sf_conversion.html
A list returning the tile X, tile Y coordinates and the zoom level.
https://learn.microsoft.com/en-us/bingmaps/articles/bing-maps-tile-system
quadkey_to_tileXY(quadkey = "213")
quadkey_to_tileXY(quadkey = "213")
This function reads all the .csv
files in a particular folder.
These files consistently contain identical columns,
with variations only in location, day, and time.
As a result,
we can uniformly apply specific formatting to columns across these files.
read_fb_mobility_files(path_to_csvs, colnames, coltypes, keep_format = NULL)
read_fb_mobility_files(path_to_csvs, colnames, coltypes, keep_format = NULL)
path_to_csvs |
Path to the folder where the |
colnames |
Columns to include in the results (as character).
For more information go to |
coltypes |
Column specifications (as strings). See vignette("readr", package = "readr") for more details. documentation. |
keep_format |
Vector of column names,
besides |
A data.frame with the information of all the files read.
files <- read_fb_mobility_files( path_to_csvs = paste0(system.file("extdata", package = "quadkeyr" ), "/"), colnames = c( # The columns not listed here will be omitted "lat", "lon", "quadkey", "date_time", "n_crisis", "percent_change", "day", "hour" ), coltypes = list( lat = "d", lon = "d", quadkey = "c", date_time = "T", n_crisis = "c", percent_change = "c", day = "D", hour = "i" ) ) head(files)
files <- read_fb_mobility_files( path_to_csvs = paste0(system.file("extdata", package = "quadkeyr" ), "/"), colnames = c( # The columns not listed here will be omitted "lat", "lon", "quadkey", "date_time", "n_crisis", "percent_change", "day", "hour" ), coltypes = list( lat = "d", lon = "d", quadkey = "c", date_time = "T", n_crisis = "c", percent_change = "c", day = "D", hour = "i" ) ) head(files)
sf
POINT data.frame into a regular grid.This function completes sf
POINT data.frame grid of QuadKeys
using the bounding box of the data provided.
regular_qk_grid(data)
regular_qk_grid(data)
data |
A |
A list with three elements:
data
A sf
POINT data.frame, with the rows needed to complete the grid.
num_rows
The number of columns of the regular grid.
num_cols
The number of rows of the regular grid.
quadkey_vector <- c("213", "210", "211") qtll <- quadkey_to_latlong(quadkey = quadkey_vector) regular_qk_grid(qtll)
quadkey_vector <- c("213", "210", "211") qtll <- quadkey_to_latlong(quadkey = quadkey_vector) regular_qk_grid(qtll)
Converts tile XY coordinates into pixel XY coordinates of the upper-left pixel of the specified tile. For further information, refer to the Microsoft Bing Maps Tile System documentation.
tileXY_to_pixelXY(tileX, tileY)
tileXY_to_pixelXY(tileX, tileY)
tileX |
Tile X coordinate. |
tileY |
Tile Y coordinate. |
Converting latitude/longitude coordinates into a QuadKey and then back to latitude/longitude won't yield identical values, unless the initial latitude/longitude coordinates correspond to the upper-left Quadkey's pixel and tile XY coordinates at the same zoom level.
Understanding this distinction is crucial for the accurate use of these functions in coordinate conversions.
For a detailed explanation on how to use this
and other similar quadkeyr
functions,
read the the vignette:
https://fernandez-lab-wsu.github.io/quadkeyr/articles/quadkey_to_sf_conversion.html
A list returning the pixel X and pixel Y coordinates.
https://learn.microsoft.com/en-us/bingmaps/articles/bing-maps-tile-system
tileXY_to_pixelXY( tileX = 3, tileY = 5 )
tileXY_to_pixelXY( tileX = 3, tileY = 5 )
Converts tile XY coordinates into a QuadKey at a specified zoom level. For further information, refer to the Microsoft Bing Maps Tile System documentation.
tileXY_to_quadkey(tileX, tileY, zoom)
tileXY_to_quadkey(tileX, tileY, zoom)
tileX |
Tile X coordinate. |
tileY |
Tile Y coordinate. |
zoom |
Zoom or level of detail, from 1 (lowest detail) to 23 (highest detail). |
Converting latitude/longitude coordinates into a QuadKey and then back to latitude/longitude won't yield identical values, unless the initial latitude/longitude coordinates correspond to the upper-left Quadkey's pixel and tile XY coordinates at the same zoom level.
Understanding this distinction is crucial for the accurate use of these functions in coordinate conversions.
For a detailed explanation on how to use this
and other similar quadkeyr
functions,
read the the vignette:
https://fernandez-lab-wsu.github.io/quadkeyr/articles/quadkey_to_sf_conversion.html
The QuadKey as a string.
https://learn.microsoft.com/en-us/bingmaps/articles/bing-maps-tile-system
tileXY_to_quadkey( tileX = 23, tileY = 38, zoom = 6 )
tileXY_to_quadkey( tileX = 23, tileY = 38, zoom = 6 )