-
Notifications
You must be signed in to change notification settings - Fork 2
/
jpmesh_demo.Rmd
111 lines (84 loc) · 3.07 KB
/
jpmesh_demo.Rmd
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.argin = "center",
fig.path = "figures/README-",
warning = FALSE
)
```
# jpmesh <img src="man/figures/logo.png" align="right" width="80px" />
## Overview
The **jpmesh** 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 125 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".
## Usage
```{r}
library(magrittr)
library(jpmesh)
```
### Convert mesh code to coordinate and vice versa
Return the latitude and longitude for specifying the mesh range from the mesh code.
```{r}
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.
```{r}
coords_to_mesh(133, 34) # default as 1km meshcode
coords_to_mesh(133, 34, mesh_size = "80km")
coords_to_mesh(133, 34, mesh_size = "125m")
```
### Detect fine and neighborhood mesh codes
```{r}
# Returns a finer mesh of the area of the mesh codes
# Such as, 80km to 10km mesh codes.
coords_to_mesh(133, 34, "80km") %>%
fine_separate()
# the value of the adjacent mesh codes
coords_to_mesh(133, 34, "80km") %>%
neighbor_mesh()
coords_to_mesh(133, 34, "500m") %>%
neighbor_mesh()
```
### Utilies
Drawing a simplified Japanese map based on the mesh code.
```{r, jpn_simple_map_sf, fig.width = 8, fig.height = 6, eval = TRUE}
library(sf)
plot(jpnrect["abb_name"])
```
```{r}
remotes::instll_github("hadley/ggplot2")
```
```{r jpn_simple_map, fig.width = 8, fig.height = 6, eval = TRUE, echo = TRUE}
library(ggplot2) # 2.2.1.9000
ggplot() +
geom_sf(data = jpnrect)
```
Dataset of mesh code for prefectures.
```{r, results = 'asis'}
set.seed(71)
administration_mesh(code = 33, type = "prefecture") %>%
dplyr::sample_n(5) %>%
knitr::kable()
```
Example)
```{r, eval = TRUE, echo = TRUE}
# For leaflet
library(leaflet)
leaflet() %>%
addTiles() %>%
addProviderTiles("OpenStreetMap.BlackAndWhite") %>%
addPolygons(data = administration_mesh(code = 33101, type = "city"))
```
```{r mesh_pref33_map, warning = FALSE, eval = TRUE, echo = TRUE}
ggplot() +
geom_sf(data = administration_mesh(code = 33, type = "city"))
```