Skip to content

Commit

Permalink
[fix]pref_codeの割り当て
Browse files Browse the repository at this point in the history
  • Loading branch information
uribo committed Aug 1, 2024
1 parent eaeb93f commit 66ffa34
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion data-raw/station_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ if (!file.exists(here::here("data-raw/amedas_raw.rds"))) {
readr::read_rds("data-raw/amedas_raw.rds")
}

# natural earthのポリゴン情報をもとに都道府県コードを付与
# ときどき間違いがあるので手動で修正する
ne_jpn <-
ne_states(country = "Japan", returnclass = "sf") %>% # magrittr
tibble::new_tibble(nrow = nrow(.), class = "sf") |>
Expand Down Expand Up @@ -227,13 +229,15 @@ prefecture_code <- c(`11001` = "01",
`23376` = "01",
`24101` = "01",
`31001` = "02",
`31662` = "02",
`32056` = "05",
`32286` = "05",
`32616` = "05",
`35002` = "06",
`34292` = "04",
`34361` = "04",
`35246` = "06",
`41011` = "09",
`45147` = "12",
`45346` = "12",
`54012` = "15",
Expand All @@ -254,26 +258,35 @@ prefecture_code <- c(`11001` = "01",
`44263` = "13",
`44281` = "13",
`44301` = "13",
`45061` = "12",
`45148` = "12",
`46046` = "14",
`46141` = "14",
`46211` = "14",
`50066` = "22",
`50506` = "22",
`50416` = "22",
`50561` = "22",
`50551` = "22",
`51077` = "23",
`51261` = "23",
`54041` = "15",
`54166` = "15",
`54387` = "15",
`54876` = "15",
`57051` = "18",
`62081` = "27",
`65021` = "30",
`65036` = "30",
`65106` = "30",
`65127` = "30",
`65288` = "30",
`65356` = "30",
`63517` = "28",
`63496` = "28",
`63491` = "28",
`63551` = "28",
`69006` = "31",
`66501` = "33",
`68022` = "32",
`68046` = "32",
Expand All @@ -285,6 +298,7 @@ prefecture_code <- c(`11001` = "01",
`81436` = "35",
`81486` = "35",
`72111` = "37",
`72176` = "36",
`73168` = "38",
`73256` = "38",
`73341` = "38",
Expand Down Expand Up @@ -315,6 +329,7 @@ prefecture_code <- c(`11001` = "01",
`86216` = "43",
`87412` = "45",
`87492` = "45",
`88836` = "46",
`88551` = "46",
`88612` = "46",
`88746` = "46",
Expand All @@ -327,6 +342,7 @@ prefecture_code <- c(`11001` = "01",
`88956` = "46",
`88971` = "46",
`88781` = "46",
`88986` = "46",
`91081` = "47",
`91107` = "47",
`91236` = "47",
Expand All @@ -348,7 +364,7 @@ prefecture_code <- c(`11001` = "01",
`94036` = "47",
`94121` = "47",
`94116` = "47") |>
ensurer::ensure(length(.) == 171L)
ensurer::ensure(length(.) == 185L)

pref_code_missing <-
stations |>
Expand Down Expand Up @@ -395,6 +411,17 @@ stations <-
.default = pref_code
))

stations |>
sf::st_drop_geometry() |>
distinct(area, pref_code) |>
count(area, sort = TRUE) |>
filter(n > 1) |>
pointblank::row_count_match(0L)

# stations |>
# filter(area == "鹿児島", pref_code == "47") |>
# distinct(area, pref_code)

stations |>
st_drop_geometry() |>
filter(is.na(pref_code)) %>% # magrittr
Expand Down
Binary file modified data/stations.rda
Binary file not shown.

0 comments on commit 66ffa34

Please sign in to comment.