https://nbviewer.jupyter.org/gist/mrkn/055662fdbbde3d070133c1a5fe51f15d
sudo gem install specific_install
sudo gem specific_install https://github.com/sciruby-jp/rubydown
sudo apt install python3-dev python3-pip
sudo gem install spreadsheet enumerable-statistics pycall
sudo python3 -m pip install -U folium
下記markdownをmrkn.mdとして保存
# 都道府県庁所在地の可視化
## 座標データのダウンロード
~~~ruby
system("curl -fsSL -O https://www.benricho.org/chimei/latlng_data.xls")
~~~
## 前処理
~~~ruby
require 'spreadsheet'
book = Spreadsheet.open('latlng_data.xls')
sheet = book.worksheet("Sheet1")
data = []
5.upto(sheet.rows.length - 1) {|i|
break unless sheet.rows[i][5]
name = sheet.rows[i][1, 2].join(' ')
lat, lon = sheet.rows[i][5, 2]
data << [name, lat, lon]
}
~~~
## 地図の初期中心点を求める
全都道府県庁所在地の重心とする。
~~~ruby
require 'enumerable/statistics'
center = [
data.map {|r| r[1] }.mean,
data.map {|r| r[2] }.mean
]
~~~
## 地図上にマーカーを表示
~~~ruby
require 'pycall'
folium = PyCall.import_module('folium')
map = folium.Map.new(location: center, zoom_start: 5)
data.each do |r|
folium.CircleMarker.new(
location: r[1, 2],
radius: 10,
fill: true,
popup: r[0]
).add_to(map)
end
map
~~~
下記erbをtemplate.erbとして保存
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href='https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/2.10.0/github-markdown.min.css' rel='stylesheet' type='text/css' />
<style>
article.markdown-body {
box-sizing: border-box;
min-width: 200px;
max-width: 980px;
margin: 0 auto;
padding: 45px;
}
span.line-numbers {
display: none;
}
</style>
</head>
<body>
<article class='markdown-body'>
<%= doc.to_html %>
</article>
</body>
</html>
rubydown -i mrkn.md -e template.erb -o mrkn.html