-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
170 lines (125 loc) · 4.84 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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# geojp
<!-- badges: start -->
[![DOI](https://zenodo.org/badge/527063683.svg)](https://zenodo.org/doi/10.5281/zenodo.10205233)
<!-- badges: end -->
The goal of geojp is to provide an easy access to various geographical data of Japan.
## Installation
You can install the development version of geojp from [GitHub](https://github.com/) with:
```{r eval = FALSE}
install.packages("devtools")
devtools::install_github("babayoshihiko/geojp")
```
Load (attach) package **geojp**.
```{r setup}
library(geojp)
```
## Census
Load census boundary information. Specify the prefecture code (code_pref) and municipality code (code_muni). Here is an example for Osaki City (215) in Miyagi Prefecture (4).
```{r echo=T, eval=F}
sfCensus <- geojp::read_census_tract(code_pref = 4, code_muni = 215)
head(sfCensus)
```
```{r echo=F, eval=T}
sfCensus <- geojp::read_census_tract(code_pref = 4, code_muni = 215, data_dir = "~/data.noindex/Census")
head(sfCensus)
```
The census has many columns, so only the important ones have been cut out.
Ordinance-designated cities will be in units of administrative districts. The `read_census_odcity()` function returns all the wards with the name of the ordinance-designated city.
```{r echo=T, eval=F}
sfCensus2 <- geojp::read_census_odcity("京都市")
head(sfCensus2)
```
```{r echo=F, eval=T}
sfCensus2 <- geojp::read_census_odcity("京都市", data_dir = "~/data.noindex/Census")
head(sfCensus2)
```
Additional attribute information is set. Attributes are obtained using the `attr()` function. One particularly important attribute is the source. The source can be retrieved as follows
```{r}
attr(sfCensus2, "sourceName")
attr(sfCensus2, "sourceURL")
```
## National Land Information
Load the zoning information from the National Land Information. Specify the prefecture code (code_pref) and municipality code (code_muni). The 2011 and 2019 versions are available, so we will try the 2011 version this time.
For more information about the National Land Information, see [National Land Information Download Service](https://nlftp.mlit.go.jp/ksj/index.html).
The return value is an `sf` object.
```{r echo=T, eval=F}
sfYouto <- geojp::read_landnuminfo_landuse(code_pref = 26, code_muni = 100, year = 2019)
```
```{r echo=F, eval=T}
sfYouto <- geojp::read_landnuminfo_landuse(code_pref = 26, code_muni = 100, year = 2019, data_dir = "~/data.noindex/A29")
```
The `A29_004` and `A29_005` columns, which indicate the zoning class, are of type factor.
```{r}
levels(sfYouto$A29_005)
```
Additional attribute information is set. Attributes are obtained using the `attr()` function. One particularly important attribute is the source. The source can be retrieved as follows
```{r}
attr(sfYouto, "sourceName")
attr(sfYouto, "sourceURL")
```
The attribute "col" is the column name used for color separation. The attribute "palette" is the color palette for color separation. This is matched as closely as possible to the colors of the intended use area according to the Japanese Industrial Standards (JIS).
```{r}
attr(sfYouto, "palette")
```
## tmap
Use package **tmap** to display the usage area. The last font specification is required only for macOS.
```{r}
library(tmap)
# Create a map.
myTm <- tm_shape(sfYouto) +
tm_polygons(fill = attr(sfYouto, "col"),
palette = attr(sfYouto, "palette"), alpha = 0.8) +
tm_borders()
myTm <- myTm +
tm_scale_bar() +
tm_layout(tm_title = "京都市",
legend.text.fontfamily = "HiraginoSans-W3")
```
Display the plot.
```{r}
myTm
```
To save, use the `tmap_save()` function.
```{r eval = FALSE}
tmap_save(tm = myTm, filename = "map.png")
```
You can also superimpose census and zoning maps.
In addition, you can use The Geospatial Information Authority of Japan standard map in tiled format as a base map.
https://maps.gsi.go.jp/development/ichiran.html
```{r}
library(tmap)
tmap_mode("view")
# Create a map.
myTm <- tm_shape(sfCensus2) +
tm_polygons("JINKO", alpha = 0.8)
myTm <- myTm +
tm_shape(sfYouto) +
tm_polygons(fill = attr(sfYouto, "col"),
palette = attr(sfYouto, "palette"), alpha = 0.8) +
tm_borders()
myTm <- myTm +
tm_basemap(server = "https://cyberjapandata.gsi.go.jp/xyz/std/{z}/{x}/{y}.png")
myTm <- myTm +
tm_scale_bar() +
tm_layout(tm_title = "京都市",
legend.text.fontfamily = "HiraginoSans-W3")
myTm
```
## mapview
```{r eval=FALSE}
library(mapview)
mapviewOptions(fgb = FALSE) # needed when creating web pages
mapview(sfYouto[attr(sfYouto, "col")], col.regions = attr(sfYouto, "palette"), fgb = FALSE)
```