最終更新:2026-01-01
Rで利用しやすい行政境界データとしては、主に以下が挙げられる。
N03-20250101_GML.zipN03-20250101_prefecture.shp: 都道府県境界データN03-20250101.shp: 市区町村境界データ# 必要なパッケージの読み込み
library(sf)
# シェープファイルの読み込み
suuchi <- sf::st_read("N03-20250101_GML/N03-20250101.shp")## Reading layer `N03-20250101' from data source
## `/Users/ayumu/Documents/GitHub/research/4_GIS/MapJapan/N03-20250101_GML/N03-20250101.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 124094 features and 6 fields
## Geometry type: POLYGON
## Dimension: XY
## Bounding box: xmin: 122.9326 ymin: 20.42275 xmax: 153.9867 ymax: 45.55724
## Geodetic CRS: JGD2011
## Coordinate Reference System:
## User input: JGD2011
## wkt:
## GEOGCRS["JGD2011",
## DATUM["Japanese Geodetic Datum 2011",
## ELLIPSOID["GRS 1980",6378137,298.257222101,
## LENGTHUNIT["metre",1]]],
## PRIMEM["Greenwich",0,
## ANGLEUNIT["degree",0.0174532925199433]],
## CS[ellipsoidal,2],
## AXIS["geodetic latitude (Lat)",north,
## ORDER[1],
## ANGLEUNIT["degree",0.0174532925199433]],
## AXIS["geodetic longitude (Lon)",east,
## ORDER[2],
## ANGLEUNIT["degree",0.0174532925199433]],
## USAGE[
## SCOPE["Horizontal component of 3D system."],
## AREA["Japan - onshore and offshore."],
## BBOX[17.09,122.38,46.05,157.65]],
## ID["EPSG",6668]]
含まれる属性フィールドは以下の通りである。
都道府県名、市区町村名などは日本語表記である。
N03_001: 都道府県名
N03_002: 北海道の振興局名
N03_003: 郡名
N03_004: 市区町村名
N03_005: 政令指定都市の行政区域名
N03_007: 全国地方公共団体コード
N03-20250101.shpは、253MB程度の大きなデータである。このデータを、QGISで地図描画するのに時間がかからないが、Rで地図描画するのは非常に時間がかかる。N03-20250101_rev1.shp(2.6MB)として保存する。library(sf)
suuchi2 <- sf::st_simplify(suuchi, dTolerance = 500) # 500m の精度で簡略化
# 保存
sf::st_write(suuchi2, "Data_output/N03-20250101_rev1.shp", delete_dsn = TRUE)## Deleting source `Data_output/N03-20250101_rev1.shp' using driver `ESRI Shapefile'
## Writing layer `N03-20250101_rev1' to data source
## `Data_output/N03-20250101_rev1.shp' using driver `ESRI Shapefile'
## Writing 124094 features with 6 fields and geometry type Unknown (any).
N03-20250101_rev2.shp(1.1MB)として保存する。library(dplyr)
library(sf)
suuchi3 <- suuchi2 %>%
group_by(N03_007) %>%
summarise(
geometry = sf::st_union(geometry),
pref = first(N03_001),
gun = first(N03_003),
city = first(N03_004),
ku = first(N03_005),
code = first(N03_007)
) %>%
ungroup()
# 保存
sf::st_write(suuchi3, "Data_output/N03-20250101_rev2.shp", delete_dsn = TRUE)## Deleting source `Data_output/N03-20250101_rev2.shp' using driver `ESRI Shapefile'
## Writing layer `N03-20250101_rev2' to data source
## `Data_output/N03-20250101_rev2.shp' using driver `ESRI Shapefile'
## Writing 1905 features with 6 fields and geometry type Unknown (any).
# 地図の作成
library(ggplot2)
ggplot(data = suuchi3) + # 地図データの指定
geom_sf(fill = "lightgreen", color = "black") + # 塗り
theme_minimal() + # ミニマルテーマの適用
labs(title = "National Land Numerical Information",
subtitle = "Administrative Boundaries of Japan Cities",
caption = "Source: Ministry of Land, Infrastructure, Transport and Tourism") +
theme(axis.text = element_blank(), # 目盛りを非表示
axis.title = element_blank()) # 軸タイトルを非表示TRUE
# 必要なパッケージの読み込み
library(sf)
# シェープファイルの読み込み
suuchi_pref <- sf::st_read("N03-20250101_GML/N03-20250101_prefecture.shp")## Reading layer `N03-20250101_prefecture' from data source
## `/Users/ayumu/Documents/GitHub/research/4_GIS/MapJapan/N03-20250101_GML/N03-20250101_prefecture.shp'
## using driver `ESRI Shapefile'
## Simple feature collection with 121990 features and 6 fields
## Geometry type: POLYGON
## Dimension: XY
## Bounding box: xmin: 122.9326 ymin: 20.42275 xmax: 153.9867 ymax: 45.55724
## Geodetic CRS: JGD2011
## Coordinate Reference System:
## User input: JGD2011
## wkt:
## GEOGCRS["JGD2011",
## DATUM["Japanese Geodetic Datum 2011",
## ELLIPSOID["GRS 1980",6378137,298.257222101,
## LENGTHUNIT["metre",1]]],
## PRIMEM["Greenwich",0,
## ANGLEUNIT["degree",0.0174532925199433]],
## CS[ellipsoidal,2],
## AXIS["geodetic latitude (Lat)",north,
## ORDER[1],
## ANGLEUNIT["degree",0.0174532925199433]],
## AXIS["geodetic longitude (Lon)",east,
## ORDER[2],
## ANGLEUNIT["degree",0.0174532925199433]],
## USAGE[
## SCOPE["Horizontal component of 3D system."],
## AREA["Japan - onshore and offshore."],
## BBOX[17.09,122.38,46.05,157.65]],
## ID["EPSG",6668]]
含まれる属性フィールドは以下の通りである。
都道府県名は日本語表記である。
N03_001: 都道府県名
N03_002: NA
N03_003: NA
N03_004: NA
N03_005: NA
N03_007: 全国地方公共団体コード
N03-20250101_prefecture.shpは178MB程度の大きなデータであり、そのまま可視化するのは時間がかかる。rmapshaper::ms_simplify(keep = 0.01, keep_shapes = TRUE)を用いると、1%の頂点を保持してデータを簡略化でき、地物間に隙間ができにくいが、処理中にRが停止したので、st_simplifyを用いる。N03-20250101_prefecture_rev1.shp(1.8MB)として保存する。library(sf)
# 500m の精度で簡略化
suuchi_pref2 <- sf::st_simplify(suuchi_pref, dTolerance = 500)
# 保存
sf::st_write(suuchi_pref2, "Data_output/N03-20250101_prefecture_rev1.shp", delete_dsn = TRUE)## Deleting source `Data_output/N03-20250101_prefecture_rev1.shp' using driver `ESRI Shapefile'
## Writing layer `N03-20250101_prefecture_rev1' to data source
## `Data_output/N03-20250101_prefecture_rev1.shp' using driver `ESRI Shapefile'
## Writing 121990 features with 6 fields and geometry type Unknown (any).
N03-20250101_prefecture_rev2.shp(342KB)として保存する。library(dplyr)
library(sf)
suuchi_pref3 <- suuchi_pref2 %>%
group_by(N03_001) %>%
summarise(
geometry = sf::st_union(geometry),
pref = first(N03_001),
) %>%
ungroup()
# 保存
sf::st_write(suuchi_pref3, "Data_output/N03-20250101_prefecture_rev2.shp", delete_dsn = TRUE)## Deleting source `Data_output/N03-20250101_prefecture_rev2.shp' using driver `ESRI Shapefile'
## Writing layer `N03-20250101_prefecture_rev2' to data source
## `Data_output/N03-20250101_prefecture_rev2.shp' using driver `ESRI Shapefile'
## Writing 47 features with 2 fields and geometry type Unknown (any).