-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
README.Rmd
175 lines (128 loc) · 5.34 KB
/
README.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
---
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 = "man/figures/README-",
warning = FALSE)
```
# jpmesh <img src="man/figures/logo.png" align="right" width="80px" />
[![CRAN\_Status\_Badge](https://www.r-pkg.org/badges/version/jpmesh)](https://cran.r-project.org/package=jpmesh)
[![CRAN RStudio mirror downloads](https://cranlogs.r-pkg.org/badges/jpmesh?color=FF5254)](https://cran.r-project.org/package=jpmesh) [![minimal R version](https://img.shields.io/badge/R%3E%3D-3.1.0-blue.svg)](https://cran.r-project.org/) [![Depsy](http://depsy.org/api/package/cran/jpmesh/badge.svg)](http://depsy.org/package/r/jpmesh) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4291910.svg)](https://doi.org/10.5281/zenodo.4291910)
[![Coverage status](https://codecov.io/gh/uribo/jpmesh/branch/main/graph/badge.svg)](https://codecov.io/github/uribo/jpmesh?branch=main) [![R-CMD-check](https://github.com/uribo/jpmesh/workflows/R-CMD-check/badge.svg)](https://github.com/uribo/jpmesh/actions?query=workflow%3AR-CMD-check)
[![lifecycle](https://img.shields.io/badge/lifecycle-maturing-blue.svg?style=for-the-badge)](https://lifecycle.r-lib.org/articles/stages.html)
[![npm](https://img.shields.io/npm/l/express.svg?style=for-the-badge)](https://github.com/uribo/jpmesh)
-----
## 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
```{r, eval = FALSE, echo = TRUE}
install.packages("jpmesh")
```
For developers
```{r, eval = FALSE, echo = TRUE}
# the development version from r-universe:
install.packages("jpmesh", repos = "https://uribo.r-universe.dev")
```
## Usage
```{r}
library(jpmesh)
```
### Create mesh code
```{r}
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.
```{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, 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.
```{r}
# Scale up
mesh_convert("52350432", 80)
# Scale down
mesh_convert("52350432", 0.500)
```
### Detect fine and neighborhood mesh codes
```{r, message=FALSE}
# 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.
```{r, jpn_simple_map_sf, fig.width = 8, fig.height = 6, eval = TRUE, message=FALSE}
library(sf)
plot(st_geometry(jpnrect))
```
```{r jpn_simple_map, fig.width = 8, fig.height = 6, echo = TRUE}
library(ggplot2)
ggplot() +
geom_sf(data = jpnrect)
```
Dataset of mesh code for prefectures.
```{r, results = 'asis'}
set.seed(71)
administration_mesh(code = 33, to_mesh_size = 80) %>%
head() %>%
knitr::kable()
```
Example)
```{r, eval = FALSE, echo = TRUE}
# For leaflet and mapview
library(leaflet)
leaflet() %>%
addTiles() %>%
addProviderTiles("OpenStreetMap.BlackAndWhite") %>%
addPolygons(data = administration_mesh(code = 33101, to_mesh_size = 1))
```
![](man/figures/README-mesh_pref_33_leaflet-1.png)
```{r mesh_pref33_map, warning = FALSE, echo = TRUE, eval = FALSE}
ggplot() +
geom_sf(data = administration_mesh(code = 33, to_mesh_size = 1))
```
```{r, eval = FALSE, include = FALSE}
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")
```
![](man/figures/README-mesh_pref33_map-1.png)
## Similar projects
- [japanmesh](https://cran.r-project.org/package=japanmesh)
## Code of Conduct
Please note that this project is released with a [Contributor Code of Conduct](.github/CODE_OF_CONDUCT.md).
By participating in this project you agree to abide by its terms.