knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.argin = "center",
  fig.path = "man/figures/README-",
  warning = FALSE)

jpmesh

CRAN_Status_Badge CRAN RStudio mirror downloads minimal R version Depsy DOI

Coverage status R-CMD-check

lifecycle npm


Overview

The jpmesh package is a package that makes it easy to use "regional mesh (i.e. mesh code JIS X 0410 )" used in Japan from R. Regional mesh is a code given when subdividing Japanese landscape into rectangular subregions by latitude and longitude. Depending on the accuracy of the code, different regional mesh length. By using the same mesh in statistical survey etc., it will become possible to handle the survey results of a large area in the area mesh unit.

In jpmesh, mesh codes and latitude and longitude coordinates are compatible with mesh codes from the first region mesh, which is the standard region mesh, to the quarter regional mesh of the divided region mesh (from 80 km to 100 m). Features include "conversion from latitude and longitude to regional mesh", "acquisition of latitude and longitude from regional mesh", "mapping on prefecture unit and leaflet".

Installation

From CRAN

install.packages("jpmesh")

For developers

# the development version from r-universe:
install.packages("jpmesh", repos = "https://uribo.r-universe.dev")

Usage

library(jpmesh)

Create mesh code

meshcode(5133) # 80km
meshcode(513377) # 10km
meshcode(51337783) # 1km
meshcode(513377831) # 500m
meshcode(5133778312) # 250m
meshcode(51337783123) # 125m
meshcode(5133778300, .type = "subdivision") # 100m

Convert mesh code to coordinate and vice versa

Return the latitude and longitude for specifying the mesh range from the mesh code.

mesh_to_coords(5133) # 80km
mesh_to_coords(513377) # 10km
mesh_to_coords(51337783) # 1km
mesh_to_coords(513377831) # 500m
mesh_to_coords(5133778312) # 250m
mesh_to_coords(51337783123) # 125m

Find the mesh code within the range from latitude and longitude.

coords_to_mesh(133, 34) # default as 1km meshcode
coords_to_mesh(133, 34, to_mesh_size = 80)
coords_to_mesh(133, 34, to_mesh_size = 0.125)

There is mesh_convert() as a function to change the mesh size more freely.

# Scale up
mesh_convert("52350432", 80)
# Scale down
mesh_convert("52350432", 0.500)

Detect fine and neighborhood mesh codes

# Returns a finer mesh of the area of the mesh codes
# Such as, 80km to 10km mesh codes.
coords_to_mesh(133, 34, 80) %>% 
  fine_separate()

# the value of the adjacent mesh codes
coords_to_mesh(133, 34, 80) %>% 
  neighbor_mesh()
coords_to_mesh(133, 34, 0.5) %>% 
  neighbor_mesh()

Utilies

Drawing a simplified Japanese map based on the mesh code.

library(sf)
plot(st_geometry(jpnrect))
library(ggplot2)
ggplot() +
  geom_sf(data = jpnrect)

Dataset of mesh code for prefectures.

set.seed(71)
administration_mesh(code = 33, to_mesh_size = 80) %>% 
  head() %>% 
  knitr::kable()

Example)

# For leaflet and mapview
library(leaflet)
leaflet() %>% 
  addTiles() %>% 
  addProviderTiles("OpenStreetMap.BlackAndWhite") %>% 
  addPolygons(data = administration_mesh(code = 33101, to_mesh_size = 1))

ggplot() + 
  geom_sf(data = administration_mesh(code = 33, to_mesh_size = 1))
ggsave(
  ggplot() + 
  geom_sf(data = administration_mesh(code = 33, to_mesh_size = 1)),
  filename = "man/figures/README-mesh_pref33_map-1.png",
  width = 8,
  height = 6,
  units = "in")

Similar projects

Code of Conduct

Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.



uribo/jpmesh documentation built on Feb. 21, 2023, 3:20 p.m.