An open API service indexing awesome lists of open source software.

https://github.com/paithiov909/jisx0402

Datasets Related to 'JIS X 0402:2020'
https://github.com/paithiov909/jisx0402

r r-package

Last synced: 2 months ago
JSON representation

Datasets Related to 'JIS X 0402:2020'

Awesome Lists containing this project

README

          

---
output: github_document
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
pkgload::load_all()
```

# jisx0402

> Datasets Related to 'JIS X 0402:2020'

[![jisx0402 status badge](https://paithiov909.r-universe.dev/badges/jisx0402)](https://paithiov909.r-universe.dev/jisx0402)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)

## Overview

「全国地方公共団体コード」と国内の行政区域の地図データセットを扱うRパッケージです。

## Installation

``` r
remotes::install_github("paithiov909/jisx0402")
```

## Examples

### municipality

`municipality`は、日本にある行政区域名とその市区町村コードの一覧です。

総務省では、都道府県コード(JIS X 0401)と市区町村コード(JIS X 0402)とを組み合わせた数字を[全国地方公共団体コード](https://www.soumu.go.jp/denshijiti/code.html)として定めています(このほかに「一部事務組合等コード」も全国地方公共団体コードに含まれますが、そちらはこのパッケージでは探せません)。

```{r municipality1}
jisx0402::municipality
```

全国地方公共団体コードは、5~6桁からなる数字の組です。6桁目はチェックデジットで、実際のコードとしては`pref_code`と`city_code`を連結した5桁になります。

```{r municipality2}
jisx0402::municipality |>
dplyr::filter(
pref_code == "05",
is.na(lubridate::as_date(end_date)) # 現存する自治体
) |>
dplyr::mutate(
muni_code = paste0(pref_code, city_code),
muni_code_with_cd = paste0(muni_code, jisx0402::check_digit(muni_code))
) |>
dplyr::select(muni_code, muni_code_with_cd, name)
```

なお、この一覧中には含まれていませんが、行政区域としての都道府県そのものは`city_code`を`000`として同様の方法で表示します。

### jpprefs

`jpprefs`は都道府県コードの一覧です。英語表記などがほしい場合には`zipangu::jpnprefs`を利用してください。

```{r jpprefs}
jisx0402::jpprefs
```

### jpaddresses

`jpaddresses`は、Geoloniaが公開している[住所データ](https://github.com/geolonia/japanese-addresses)を元に加工したデータセットです。

```{r jpaddresses}
jisx0402::jpaddresses
```

### jptopography

`jptopography()`は、日本の行政区域の地図データを`sf`オブジェクトとして返す関数です。`muni_code`は国土交通省が[行政区域コード](https://nlftp.mlit.go.jp/ksj/gml/codelist/AdminiBoundary_CD.xlsx)として公開しているもので、全国地方公共団体コードと同じ番号になります。

この関数で返されるデータは、スマートニュースが公開している[市区町村・選挙区 地形データ](https://github.com/smartnews-smri/japan-topography)を元に、FlatGeobuf (`.fgb`) ファイルに加工したものです。

元データが「国土数値情報 行政区域データ」として公開されているもの([第3.0版](https://nlftp.mlit.go.jp/ksj/gml/datalist/KsjTmplt-N03-v3_0.html))を簡素化したデータであるため、この関数で返されるデータを利用する際には、国土交通省の指示するクレジット記載が必要になります。詳しくは[国土数値情報ダウンロードサイト](https://nlftp.mlit.go.jp)の利用規約を参照してください。

```{r tmap}
northern_tohoku <-
with(
jisx0402::jpprefs,
subset(pref_code, name %in% c("青森県", "秋田県", "岩手県"))
)

jisx0402::jptopography("designated") |>
dplyr::mutate(pref_code = stringr::str_sub(muni_code, 1, 2)) |>
dplyr::filter(
pref_code %in% northern_tohoku
) |>
tmap::tm_shape() +
tmap::tm_polygons() +
tmap::tm_shape(subset(jptopography("prefecture"), pref_code %in% northern_tohoku)) +
tmap::tm_borders(col = "red", lty = 2) +
tmap::tm_credits(
paste("地図データ:「国土数値情報 行政区域データ」(国土交通省)",
"https://nlftp.mlit.go.jp/ksj/gml/datalist/KsjTmplt-N03-v3_0.html",
"を加工して作成",
sep = "\n")
)
```