Created
October 25, 2016 14:48
-
-
Save masayukeeeee/e07d64552229c7dbbaa125891e151fd4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# jpn.shpを読み込む | |
shape.jpn <- read.shape(filename="/Library/Frameworks/R.framework/Versions/3.3/Resources/library/Nippon/shapes/jpn.shp") | |
# jpn.shpの中の座標データがあるオブジェクトを抜き出す | |
Datas <- shape.jpn@polygons | |
# 県名を抜き出す | |
Pref.names <- as.character(shape.jpn[[3]]) | |
# 各県の座標を格納するリストを作成 | |
all.list <- list() | |
# 各県について実行 | |
for(i in 1:47){ | |
# 座標行列を格納するリストを作成 | |
each.list <- list() | |
# i番目の県のデータを取り出す | |
tmp1 <- Datas[[i]] | |
# i番目の県の座標行列を取り出す | |
tmp2 <- tmp1@Polygons | |
# tmp2の要素分だけ繰り返し | |
for(j in 1:length(tmp2)){ | |
# tmp2のj番目の座標行列を取り出す | |
tmp3 <- tmp2[[j]] | |
# 座標行列をeach.listのj番目に格納 | |
each.list[[j]] <- tmp3@coords | |
} | |
# each.listをall.listのi番目に格納 | |
all.list[[i]] <- each.list | |
} | |
# all.listの要素の名前を都道府県名前に変更する | |
names(all.list) <- Pref.names |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment