Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
# package 読み込み
library(rgl)
library(maptools)
library(spsurvey)
# カレントディレクトリをshapeファイルがあるフォルダにあらかじめ移しておくこと
shape.world <- read.shape(filename='ne_10m_admin_1_states_provinces_scale_rank.shp')
jpn.num <- which(shape.world$sr_sov_a3=='JPN')
# shapeファイルに保存されている都道府県の表記, 兵庫だけちょっと変なので注意
PreNames <-
c("Aichi","Ehime","Ibaraki","Okayama","Okinawa","Iwate","Gifu","Miyazaki",
"Miyagi","Kyoto","Kumamoto","Gunma","Hiroshima", "Kagawa","Kochi","Saga",
"Saitama","Mie","Yamagata","Yamaguchi","Yamanashi","Shiga","Kagoshima","Akita",
"Niigata","Kanagawa","Aomori","Shizuoka","Ishikawa","Chiba","Osaka","Oita",
"Nagasaki","Nagano","Tottori","Shimane","Tokyo","Tokushima","Tochigi", "Nara",
"Toyama","Fukui","Fukuoka","Fukushima","Hyōgo","Hokkaido","Wakayama")
tmp.data <- shape.world@polygons
map.data <- list()
n <- length(PreNames)
for(i in 1:n){
PreName1 <- PreNames[i]
PreNum <- which(shape.world$name == PreName1)
n2 <- length(PreNum)
tmpList <- list()
for(j in 1:n2){
num1 <- PreNum[j]
tmp1 <- tmp.data[[num1]]
tmp2 <- tmp1@Polygons
tmp3 <- tmp2[[1]]
tmp4 <- tmp3@coords
tmpList[[j]] <- tmp4
}
map.data[[i]] <- tmpList
names(map.data)[i] <- PreName1
}
# 兵庫の名前は普通に打っても出ないので簡単に指定できるよう変えておく
names(map.data)[45] <- 'Hyogo'
# こっちは全部を描画する用
map.All <- list()
n <- length(jpn.num)
for(i in 1:n){
num <- jpn.num[i]
tmp1 <- tmp.data[[num]]
tmp2 <- tmp1@Polygons
tmp3 <- tmp2[[1]]
tmp4 <- tmp3@coords
map.All[[i]] <- tmp4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment