| Title: | Functions for the Grid Square Codes in Japan |
|---|---|
| Description: | Provides functions for grid square codes in Japan (<https://www.stat.go.jp/english/data/mesh/index.html>). Generates the grid square codes from longitude/latitude, geometries, and the grid square codes of different scales, and vice versa. |
| Authors: | Mizuki Uchida [aut, cre] |
| Maintainer: | Mizuki Uchida <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.4.0.9000 |
| Built: | 2026-05-25 07:40:59 UTC |
| Source: | https://github.com/uchidamizuki/jpgrid |
Converting bbox to grid square codes
bbox_to_grid(bbox, grid_size)bbox_to_grid(bbox, grid_size)
bbox |
A |
grid_size |
A grid size. |
A grid vector.
Conversion between grid square codes and coordinates (longitude and latitude)
coords_to_grid(X, Y, grid_size) grid_to_coords(grid, center = TRUE)coords_to_grid(X, Y, grid_size) grid_to_coords(grid, center = TRUE)
X |
A numeric vector of longitude. |
Y |
A numeric vector of latitude. |
grid_size |
A grid size. |
grid |
A |
center |
Should the center point of the grid be returned? Otherwise the
end points will be returned. |
coords_to_grid() returns a grid vector.
grid_to_coords() returns a tbl_df.
Converting sfc geometries to grid square codes
geometry_to_grid(geometry, grid_size, options = "ALL_TOUCHED=TRUE", ...)geometry_to_grid(geometry, grid_size, options = "ALL_TOUCHED=TRUE", ...)
geometry |
A |
grid_size |
A grid size. |
options |
Options vector for GDALRasterize passed on to
|
... |
Passed on to |
A list of grid vectors.
Converting data frame containing grid square codes to sf
grid_as_sf( x, as_points = FALSE, crs = sf::NA_crs_, grid_column_name = NULL, ... )grid_as_sf( x, as_points = FALSE, crs = sf::NA_crs_, grid_column_name = NULL, ... )
x |
A data frame or a |
as_points |
Return the center points of the grids or not? |
crs |
Coordinate reference system. |
grid_column_name |
A scalar character. |
... |
passed on to |
A sf object.
Converting data frame containing regional grids to stars
grid_as_stars( x, coords = NULL, crs = sf::NA_crs_, grid_column_name = NULL, ... )grid_as_stars( x, coords = NULL, crs = sf::NA_crs_, grid_column_name = NULL, ... )
x |
A data frame or a |
coords |
The column names or indices that form the cube dimensions. |
crs |
Coordinate reference system. |
grid_column_name |
A scalar character. |
... |
Passed on to |
A stars object.
Grid square codes on the boundary
grid_boundary(grid, n = 1, type = NULL)grid_boundary(grid, n = 1, type = NULL)
grid |
A |
n |
A numeric vector of degrees. By default, |
type |
A character vector of neighborhood types, |
A grid vector.
List of grid square codes by Japanese municipalities
grid_city_2020grid_city_2020
An object of class tbl_df (inherits from tbl, data.frame) with 462915 rows and 6 columns.
https://www.stat.go.jp/data/mesh/m_itiran.html
Connected components of grid square codes
grid_components(grid, n = 1, type = NULL)grid_components(grid, n = 1, type = NULL)
grid |
A |
n |
A numeric vector of degrees. By default, |
type |
A character vector of neighborhood types, |
A integer vector of group IDs.
Convert the grid size of grid objects
grid_convert(grid, grid_size)grid_convert(grid, grid_size)
grid |
A |
grid_size |
A grid size. |
A grid vector.
grid_500m <- parse_grid(c("533945263", "533935863", "533945764"), "500m") grid_convert(grid_500m, "10km")grid_500m <- parse_grid(c("533945263", "533935863", "533945764"), "500m") grid_convert(grid_500m, "10km")
If grid and grid_to are both vectors, the distance between
grid and grid_to is calculated.
If grid is a list, The path distance of each element is calculated.
grid_distance( grid, grid_to = NULL, close = FALSE, type = c("keep_na", "ignore_na", "skip_na") )grid_distance( grid, grid_to = NULL, close = FALSE, type = c("keep_na", "ignore_na", "skip_na") )
grid |
A |
grid_to |
A |
close |
Should the path of each element be closed when |
type |
How is the NA grid treated when |
A double vector.
If grid and grid_to are both vectors, the line between
grid and grid_to is drawn (using Bresenham's line algorithm).
If grid is a list, The path lines for each element in the grid will be
drawn.
grid_line(grid, grid_to = NULL, close = FALSE, skip_na = FALSE)grid_line(grid, grid_to = NULL, close = FALSE, skip_na = FALSE)
grid |
A |
grid_to |
A |
close |
Should the path of each element be closed when |
skip_na |
Should skip the |
A list of grid vectors.
Moving on grid square codes
grid_move(grid, n_X, n_Y)grid_move(grid, n_X, n_Y)
grid |
A |
n_X |
Number of moving cells in the longitude direction. |
n_Y |
Number of moving cells in the latitude direction. |
A grid vector.
grid_neighbor(grid, n = 1L, moore = TRUE, simplify = TRUE)grid_neighbor(grid, n = 1L, moore = TRUE, simplify = TRUE)
grid |
A |
n |
A numeric vector of degrees. By default, |
moore |
Moore neighborhood ( |
simplify |
Should simplify the format of the return? |
A list of grid vectors.
Neighborhood grid square codes
grid_neighborhood(grid, n = 1L, type = NULL, simplify = TRUE)grid_neighborhood(grid, n = 1L, type = NULL, simplify = TRUE)
grid |
A |
n |
A numeric vector of degrees. By default, |
type |
A character vector of neighborhood types, |
simplify |
Should simplify the format of the return? |
A list of grid vectors.
grid_subdivide() makes the grid square codes finer.
grid_subdivide(grid, grid_size)grid_subdivide(grid, grid_size)
grid |
A |
grid_size |
A grid size. |
A list of grid vector.
Test if the object is a grid
is_grid(x, grid_size = NULL)is_grid(x, grid_size = NULL)
x |
An object. |
grid_size |
A grid size. |
TRUE if the object inherits from the grid class.
Provides functions for grid square codes in Japan (https://www.stat.go.jp/english/data/mesh/index.html). Generates the grid square codes from longitude/latitude, geometries, and the grid square codes of different scales, and vice versa.
Maintainer: Mizuki Uchida [email protected]
https://www.stat.go.jp/english/data/mesh/index.html
Parse grid square codes
parse_grid(x, grid_size = NULL, strict = TRUE)parse_grid(x, grid_size = NULL, strict = TRUE)
x |
A character vector of grid square codes. |
grid_size |
A grid size. |
strict |
A scalar logical. Should the number of digits in the grid
square code match a given number of digits? By default, |
parse_grid("53394526313") parse_grid("53394526313", "80km") parse_grid("53394526313", "80km", strict = FALSE)parse_grid("53394526313") parse_grid("53394526313", "80km") parse_grid("53394526313", "80km", strict = FALSE)