Skip to content

Commit 502d045

Browse files
committed
version 0.0.8
1 parent 2a2ceef commit 502d045

5 files changed

Lines changed: 253 additions & 3 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: geojp
22
Type: Package
33
Title: Download Spatial Data Sets of Japan
4-
Version: 0.0.7
4+
Version: 0.0.8
55
Authors@R: person("Yoshihiko", "Baba", role = c("aut", "cre"), email = "babayoshihiko@mac.com", comment = c(ORCID = "0000-0001-7034-9724"))
66
Description: Easy access to various spatial data sets of Japan as 'sf' objects in R. The package includes a wide range of geospatial data available at various geographic scales and for various years with harmonized attributes, projection and fixed topology.
77
License: MIT + file LICENSE

NAMESPACE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,24 @@ export(read_census_odcity)
99
export(read_census_tract)
1010
export(read_landnuminfo)
1111
export(read_landnuminfo_admin)
12+
export(read_landnuminfo_designated_rural)
13+
export(read_landnuminfo_development_mountain_village)
1214
export(read_landnuminfo_flood)
1315
export(read_landnuminfo_hazard)
16+
export(read_landnuminfo_heavy_snowfall)
1417
export(read_landnuminfo_hospital)
1518
export(read_landnuminfo_landuse)
1619
export(read_landnuminfo_locnorm)
1720
export(read_landnuminfo_mesh3)
1821
export(read_landnuminfo_meshsub)
1922
export(read_landnuminfo_officiallandprice)
23+
export(read_landnuminfo_particular_soil)
24+
export(read_landnuminfo_peninsulas_development_implementation)
2025
export(read_landnuminfo_preflandprice)
26+
export(read_landnuminfo_remote_island_development_implementation)
2127
export(read_landnuminfo_river)
2228
export(read_landnuminfo_school)
29+
export(read_landnuminfo_underpopulated)
2330
export(read_landnuminfo_urbanarea)
2431
export(read_landnuminfo_welfare)
2532
export(read_mhlw_ltci)

R/landnuminfo.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@ read_landnuminfo_by_csv <- function(maptype, code_pref, code_muni = NULL,
106106
year4digit <- check_year(year)
107107
strTempDir <- check_data_dir(data_dir)
108108
code_pref <- check_code_pref_as_char(code_pref)
109-
code_muni <- check_code_muni_as_char(code_pref, code_muni)
109+
if (!is.null(code_muni)){
110+
code_muni <- check_code_muni_as_char(code_pref, code_muni)
111+
} else {
112+
code_muni <- ""
113+
}
110114

111115
if (nchar(code_pref) != 2) stop(paste("Invalid argument: code_pref:", code_pref))
112116
if (code_pref == "47" && year4digit < 1973) stop("No data available for Okinaya before year 1973.")
@@ -150,7 +154,7 @@ get_sfLNI <- function(maptype, strLNIFile1, strLNIFile2, strLNIFile3, strLNIUrl,
150154
message(paste("Downloaded the file and saved in", strTempDir))
151155
}
152156
unzip_ja(strLNIZip, exdir = strTempDir)
153-
message(paste("Unipped the file in", strTempDir))
157+
message(paste("Unzipped the file in", strTempDir))
154158
# Checks if the shp file exists
155159
strLNIFile <- get_sfLNI_file(strLNIFile1, strLNIFile2, strLNIFile3, strTempDir, multifiles)
156160
}

R/landnuminfo_lessfavoured.R

Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
#' Download Underpopulated Areas of Japan
2+
#'
3+
#' @description
4+
#' Function to download spatial data of Underpopulated Areas of Japan. The returned value is an sf object.
5+
#'
6+
#' @param code_pref The 2-digit code of prefecture.
7+
#' @param code_muni Optional. The 3-digit code of municipality.
8+
#' @param year Year of the data. Defaults to 2017.
9+
#' @param data_dir The directory to store downloaded zip and extracted files. If not specified, the data will be stored in a temp directory and will be deleted after you quit the session.
10+
#'
11+
#' @return An `"sf" "data.frame"` object with extra attr "col" and "palette" for tmap.
12+
#'
13+
#' @export
14+
read_landnuminfo_underpopulated <- function(code_pref, code_muni = NULL, year = 2017, data_dir = NULL){
15+
year4digit <- check_year(year)
16+
17+
if (!(code_pref %in% c(1:13,15:47))) stop(paste("The data is not available for prefecture", code_pref))
18+
if (code_pref == 27 & year4digit < 2016) {
19+
stop(paste("The data is not available for prefecture", code_pref, "for year", year4digit))
20+
}
21+
if (code_pref == 47 & year4digit < 1973){
22+
stop(paste("The data is not available for prefecture", code_pref, "for year", year4digit))
23+
}
24+
25+
sfLNI <- NULL
26+
sfLNI <- read_landnuminfo_by_csv("A17", code_pref, NULL, year4digit, data_dir)
27+
28+
if (!is.null(code_muni)){
29+
sfLNI <- subset(sfLNI, A17_002 == paste(check_code_pref_as_char(code_pref),check_code_muni_as_char(code_pref,code_muni),sep=""))
30+
}
31+
32+
if (!is.null(sfLNI)) {
33+
attr(sfLNI, "mapname") <- "\u904e\u758e\u5730\u57df"
34+
return(sfLNI)
35+
}
36+
}
37+
38+
#' Download Peninsulas Development Implementation Areas of Japan
39+
#'
40+
#' @description
41+
#' Function to download spatial data of Peninsulas Development Implementation Areas of Japan. The returned value is an sf object.
42+
#'
43+
#' @param code_pref The 2-digit code of prefecture.
44+
#' @param code_muni Optional. The 3-digit code of municipality.
45+
#' @param year Year of the data. Defaults to 2016.
46+
#' @param data_dir The directory to store downloaded zip and extracted files. If not specified, the data will be stored in a temp directory and will be deleted after you quit the session.
47+
#'
48+
#' @return An `"sf" "data.frame"` object with extra attr "col" and "palette" for tmap.
49+
#'
50+
#' @export
51+
read_landnuminfo_peninsulas_development_implementation <- function(code_pref, code_muni = NULL, year = 2016, data_dir = NULL){
52+
year4digit <- check_year(year)
53+
54+
if (!(code_pref %in% c(1,2,5,12,16,17,22,24,26,29,30,32,34,35,38,39,41:46))) stop(paste("The data is not available for prefecture", code_pref))
55+
if (code_pref == 5 & year4digit == 1986) stop(paste("The data is not available for prefecture", code_pref, "for year 1986"))
56+
if (code_pref == 39 & year4digit == 1986) stop(paste("The data is not available for prefecture", code_pref, "for year 1986"))
57+
if (code_pref == 41 & year4digit == 1986) stop(paste("The data is not available for prefecture", code_pref, "for year 1986"))
58+
59+
sfLNI <- NULL
60+
sfLNI <- read_landnuminfo_by_csv("A18", code_pref, NULL, year4digit, data_dir)
61+
62+
if (!is.null(code_muni)){
63+
sfLNI <- subset(sfLNI, A18_002 == paste(check_code_pref_as_char(code_pref),check_code_muni_as_char(code_pref,code_muni),sep=""))
64+
}
65+
66+
if (!is.null(sfLNI)) {
67+
attr(sfLNI, "mapname") <- "\u534a\u5cf6\u632f\u8208\u5bfe\u7b56\u5b9f\u65bd\u5730\u57df"
68+
return(sfLNI)
69+
}
70+
}
71+
72+
#' Download Remote Island Development Implementation Areas of Japan
73+
#'
74+
#' @description
75+
#' Function to download spatial data of Remote Island Development Implementation Areas of Japan. The returned value is an sf object.
76+
#'
77+
#' @param code_pref The 2-digit code of prefecture.
78+
#' @param code_muni Optional. The 3-digit code of municipality.
79+
#' @param year Year of the data. Defaults to 2017.
80+
#' @param data_dir The directory to store downloaded zip and extracted files. If not specified, the data will be stored in a temp directory and will be deleted after you quit the session.
81+
#'
82+
#' @return An `"sf" "data.frame"` object with extra attr "col" and "palette" for tmap.
83+
#'
84+
#' @export
85+
read_landnuminfo_remote_island_development_implementation <- function(code_pref, code_muni = NULL, year = 2017, data_dir = NULL){
86+
year4digit <- check_year(year)
87+
88+
if (!(code_pref %in% c(1,4,6,13,15,17,22:24,28,30,32:46))) stop(paste("The data is not available for prefecture", code_pref))
89+
if (code_pref == 22 & year4digit < 1965) stop(paste("The data is not available for prefecture", code_pref, "for year", year4digit))
90+
if (code_pref == 23 & year4digit < 1960) stop(paste("The data is not available for prefecture", code_pref, "for year", year4digit))
91+
if (code_pref == 30 & year4digit > 2000) stop(paste("The data is not available for prefecture", code_pref, "for year", year4digit))
92+
if (code_pref == 33 & year4digit < 1960) stop(paste("The data is not available for prefecture", code_pref, "for year", year4digit))
93+
if (code_pref == 34 & year4digit < 1960) stop(paste("The data is not available for prefecture", code_pref, "for year", year4digit))
94+
if (code_pref == 36 & year4digit < 1960) stop(paste("The data is not available for prefecture", code_pref, "for year", year4digit))
95+
if (code_pref == 37 & year4digit < 1960) stop(paste("The data is not available for prefecture", code_pref, "for year", year4digit))
96+
if (code_pref == 44 & year4digit < 1960) stop(paste("The data is not available for prefecture", code_pref, "for year", year4digit))
97+
if (code_pref == 45 & year4digit < 1960) stop(paste("The data is not available for prefecture", code_pref, "for year", year4digit))
98+
99+
sfLNI <- NULL
100+
sfLNI <- read_landnuminfo_by_csv("A19", code_pref, NULL, year4digit, data_dir)
101+
102+
if (!is.null(code_muni)){
103+
sfLNI <- subset(sfLNI, A19_002 == paste(check_code_pref_as_char(code_pref),check_code_muni_as_char(code_pref,code_muni),sep=""))
104+
}
105+
106+
if (!is.null(sfLNI)) {
107+
attr(sfLNI, "mapname") <- "\u96e2\u5cf6\u632f\u8208\u5bfe\u7b56\u5b9f\u65bd\u5730\u57df"
108+
return(sfLNI)
109+
}
110+
}
111+
112+
#' Download Heavy Snowfall of Japan
113+
#'
114+
#' @description
115+
#' Function to download spatial data of Heavy Snowfall Areas of Japan. The returned value is an sf object.
116+
#'
117+
#' @param code_pref The 2-digit code of prefecture.
118+
#' @param code_muni Optional. The 3-digit code of municipality.
119+
#' @param year Year of the data. Defaults to 2016.
120+
#' @param data_dir The directory to store downloaded zip and extracted files. If not specified, the data will be stored in a temp directory and will be deleted after you quit the session.
121+
#'
122+
#' @return An `"sf" "data.frame"` object with extra attr "col" and "palette" for tmap.
123+
#'
124+
#' @export
125+
read_landnuminfo_heavy_snowfall <- function(code_pref, code_muni = NULL, year = 2016, data_dir = NULL){
126+
year4digit <- check_year(year)
127+
128+
if (!(code_pref %in% c(1:7,9:10,15:22,25,26,28,31:34))) stop(paste("The data is not available for prefecture", code_pref))
129+
if (code_pref == 22 & year4digit < 1960) stop(paste("The data is not available for prefecture", code_pref, "for year", year4digit))
130+
131+
sfLNI <- NULL
132+
sfLNI <- read_landnuminfo_by_csv("A22", code_pref, NULL, year4digit, data_dir)
133+
134+
if (!is.null(code_muni)){
135+
sfLNI <- subset(sfLNI, A22_002 == paste(check_code_pref_as_char(code_pref),check_code_muni_as_char(code_pref,code_muni),sep=""))
136+
}
137+
138+
if (!is.null(sfLNI)) {
139+
attr(sfLNI, "mapname") <- "\u8c6a\u96ea\u5730\u5e2f"
140+
return(sfLNI)
141+
}
142+
}
143+
144+
#' Download Particular Soil Zones of Japan
145+
#'
146+
#' @description
147+
#' Function to download spatial data of Particular Soil Zones of Japan. The returned value is an sf object.
148+
#'
149+
#' @param code_pref The 2-digit code of prefecture.
150+
#' @param code_muni Optional. The 3-digit code of municipality.
151+
#' @param year Year of the data. Defaults to 2016.
152+
#' @param data_dir The directory to store downloaded zip and extracted files. If not specified, the data will be stored in a temp directory and will be deleted after you quit the session.
153+
#'
154+
#' @return An `"sf" "data.frame"` object with extra attr "col" and "palette" for tmap.
155+
#'
156+
#' @export
157+
read_landnuminfo_particular_soil <- function(code_pref, code_muni = NULL, year = 2016, data_dir = NULL){
158+
year4digit <- check_year(year)
159+
160+
if (!(code_pref %in% c(22,28,31:35,38:40,43:46))) stop(paste("The data is not available for prefecture", code_pref))
161+
162+
sfLNI <- NULL
163+
sfLNI <- read_landnuminfo_by_csv("A23", code_pref, NULL, year4digit, data_dir)
164+
165+
if (!is.null(code_muni)){
166+
sfLNI <- subset(sfLNI, A23_002 == paste(check_code_pref_as_char(code_pref),check_code_muni_as_char(code_pref,code_muni),sep=""))
167+
}
168+
169+
if (!is.null(sfLNI)) {
170+
attr(sfLNI, "mapname") <- "\u7279\u6b8a\u571f\u58cc\u5730\u5e2f"
171+
return(sfLNI)
172+
}
173+
}
174+
175+
#' Download Development Mountain Villages of Japan
176+
#'
177+
#' @description
178+
#' Function to download spatial data of Development Mountain Villages of Japan. The returned value is an sf object.
179+
#'
180+
#' @param code_pref The 2-digit code of prefecture.
181+
#' @param code_muni Optional. The 3-digit code of municipality.
182+
#' @param year Year of the data. Defaults to 2016.
183+
#' @param data_dir The directory to store downloaded zip and extracted files. If not specified, the data will be stored in a temp directory and will be deleted after you quit the session.
184+
#'
185+
#' @return An `"sf" "data.frame"` object with extra attr "col" and "palette" for tmap.
186+
#'
187+
#' @export
188+
read_landnuminfo_development_mountain_village <- function(code_pref, code_muni = NULL, year = 2016, data_dir = NULL){
189+
year4digit <- check_year(year)
190+
191+
if (!(code_pref %in% c(1:26,28:41,43:46))) stop(paste("The data is not available for prefecture", code_pref))
192+
if (code_pref == 13 & year4digit < 1970) stop(paste("The data is not available for prefecture", code_pref, "for year", year4digit))
193+
if (year == 1966) {
194+
if (!(code_pref %in% c(1:11,15:26,28:36,38:40,43:45))) stop(paste("The data is not available for prefecture", code_pref, "for year 1966"))
195+
}
196+
197+
sfLNI <- NULL
198+
sfLNI <- read_landnuminfo_by_csv("A24", code_pref, NULL, year4digit, data_dir)
199+
200+
if (!is.null(code_muni)){
201+
sfLNI <- subset(sfLNI, A24_002 == paste(check_code_pref_as_char(code_pref),check_code_muni_as_char(code_pref,code_muni),sep=""))
202+
}
203+
204+
if (!is.null(sfLNI)) {
205+
attr(sfLNI, "mapname") <- "\u632f\u8208\u5c71\u6751"
206+
return(sfLNI)
207+
}
208+
}
209+
210+
#' Download Designated Rural Areas of Japan
211+
#'
212+
#' @description
213+
#' Function to download spatial data of Designated Rural Areas of Japan. The returned value is an sf object.
214+
#'
215+
#' @param code_pref The 2-digit code of prefecture.
216+
#' @param code_muni Optional. The 3-digit code of municipality.
217+
#' @param year Year of the data. Defaults to 2016.
218+
#' @param data_dir The directory to store downloaded zip and extracted files. If not specified, the data will be stored in a temp directory and will be deleted after you quit the session.
219+
#'
220+
#' @return An `"sf" "data.frame"` object with extra attr "col" and "palette" for tmap.
221+
#'
222+
#' @export
223+
read_landnuminfo_designated_rural <- function(code_pref, code_muni = NULL, year = 2016, data_dir = NULL){
224+
year4digit <- check_year(year)
225+
226+
sfLNI <- NULL
227+
sfLNI <- read_landnuminfo_by_csv("A25", code_pref, NULL, year4digit, data_dir)
228+
229+
if (!is.null(code_muni)){
230+
sfLNI <- subset(sfLNI, A25_002 == paste(check_code_pref_as_char(code_pref),check_code_muni_as_char(code_pref,code_muni),sep=""))
231+
}
232+
233+
if (!is.null(sfLNI)) {
234+
attr(sfLNI, "mapname") <- "\u7279\u5b9a\u8fb2\u5c71\u6751\u5730\u57df"
235+
return(sfLNI)
236+
}
237+
}
238+
239+

R/sysdata.rda

1.16 KB
Binary file not shown.

0 commit comments

Comments
 (0)