資料可視化
HW03 - 樓層平面圖及面量圖 Choropleth
吳泳霈
國立臺北科技大學資訊工程系
目錄
P.2
01
章節 01
目錄
P.3
JSON 檔介紹
P.4
02
章節 02
JSON 檔
定義:JavaScript Object Notation (JSON) 是資料交換格式。是一種以文字為基礎的方式來表示 JavaScript 物件文字、陣列和純量資料。
https://hackmd.io/IB66HLWrStq5GGiJaYywhw?view
P.5
一般的JSON檔
https://csvjson.com/json_beautifier
P.6
GeoJSON
基於JSON格式,用來描述地理空間資訊的數據交換格式,它定義了幾種類型的JSON對象(Object),和它們組合於一起的方法,用來表示地理相關要素、屬性和空間範圍資料的資訊。
GeoJSON 的最外層是一個單獨的對象(object),對象可表示:
P.7
GeoJSON
最外層的對象(object)包含許多子對象,而每個子對象都具有一個 type 屬性,用來表示對象的類型,type 值必須是下面其中之一:
P.8
重要規定
如果 type 設定為:
P.9
範例:第一種
P.10
線上實現 GeoJSON工具:https://geojson.io/#map=2/20.0/0.0
點:
{
"type": "Point",
"coordinates": [30, 10]
}
面:
{
"type": "Polygon",
"coordinates": [
[[30, 10], [40, 40], [20, 40], [10, 20], [30, 10]]
]
}
線:
{
"type": "LineString",
"coordinates": [
[30, 10], [10, 30], [40, 40]
]
}
範例:第二種
P.11
{
"type": "GeometryCollection", //object
"geometries": [ //變量
{
"type": "Point", //子 object
"coordinates": [120, 60]
},
{
"type": "LineString",
"coordinates": [ [100, 60], [100, 40] ]
}
]
}
範例:第三種
P.12
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"name": "Taipei 101"
},
"geometry": {
"type": "Point",
"coordinates": [121.5615184,25.0338266]
}
}
]
}
TopoJSON
為 GeoJSON 依照拓樸學編碼後的擴展形式,由鼎鼎大名的 D3.JS 視覺化套件作者 Mike Bostock 制定。
相比 GeoJSON 直接使用 Polygon、Point 之類的幾何體來表示圖形的方法,TopoJSON 中的每一個幾何體都是透過共享體(arcs)整合後組成的幾何體圖形。
P.13
TopoJSON
優勢:TopoJson 產出的檔案更小,大概縮小了80%
原因:
P.14
JavaScript讀取JSON檔案
P.15
03
章節 03
一、使用getJSON、Fetch等
假設在目錄底下新增一份 test.json 檔,且個人路徑是 yungpei/json/,因使用ajax相關技術,須留意檔案位置是否為可讀取的靜態檔案路徑。
P.16
<script>
fetch('yungpei/json/test.json')
.then(function (response) {
return response.json();
})
.then(function (result) {
console.log(result);
});
</script>
[
{
"Email": "t112598033@ntut.org.tw",
"Floor": "1F",
"Pressure": 0.0,
"Timestamp": "2023/11/03 14:20:05",
"X": 13.328418731689454,
"Y": -4.617437362670898,
"RotateY": -0.4538845419883728
},
{
"Email": "t112598033@ntut.org.tw",
"Floor": "1F",
"Pressure": 0.0,
"Timestamp": "2023/11/03 14:20:06",
"X": 13.328418731689454,
"Y": -4.617437362670898,
"RotateY": -0.3522264361381531
},
二、使用JavaScript import、export
將 Json 檔改為 Js 檔,如:test.json.js 或 test.js,使用 import 讀檔。
P.17
[
export const test = {
"Email": "t112598033@ntut.org.tw",
"Floor": "1F",
"Pressure": 0.0,
"Timestamp": "2023/11/03 14:20:05",
"X": 13.328418731689454,
"Y": -4.617437362670898,
"RotateY": -0.4538845419883728
},
{
"Email": "t112598033@ntut.org.tw",
"Floor": "1F",
"Pressure": 0.0,
"Timestamp": "2023/11/03 14:20:06",
"X": 13.328418731689454,
"Y": -4.617437362670898,
"RotateY": -0.3522264361381531
},
<script type="module">
import { test } from 'yungpei/json/test.json.js';
console.log(test);
</script>
(補充)MDN有關於讀取JSON檔的方法
P.18
<script>
var requestURL = 'yungpei/json/test.json';
var request = new XMLHttpRequest();
request.open('GET', requestURL);
request.responseType = 'json';
request.send();
request.onload = function() {
console.log(request.response);
}
</script>
Choropleth 介紹
P.19
04
章節 04
面量圖 Choropleth 介紹
"面量圖(分級著色圖)是一種統計地圖。使用假色把空間單位(如人口密度)等地理特徵,對應到不同顏色。面量圖能夠反映變數在地理區域上的變化情況。熱圖和等值線圖也有類似作用,利用變數來繪製區域,而面量圖則反之,是彙總並填充預先劃定的區域。"(出處: 維基百科)
P.20
出處: 維基百科
REFERENCES
[3] Wikipedia. 2017. Choropleth map. Retrieved from https://en.wikipedia.org/wiki/Choropleth_map.
圖1、面量圖範例。(出處: 維基百科)
面量圖 Choropleth 結構
"面量圖融合了兩套數據:將地理空間劃分為「區域」的空間數據,以及某個變數在每個區域內彙總得到的統計數據。
對於這兩種數據如何在面量圖中相互作用,有兩種概念模式:
P.21
假色
"指在一幅影像中使用與真實色彩不同的顏色描述一項物體。
例如負片的顏色就可以被叫做假色,因為負片的顏色是物體顏色的補色。但假色常被用於表示電磁波譜中不可見光的部分。
面量圖是指在地圖或影像上加上顏色形成一個目錄顯示不同的值或變量。面量圖因為多用於地圖,因此被認為是假色的極端形式。"
(出處: 維基百科)
P.22
熱圖
"Heat map,是在二維空間中以顏色的形式顯示一個現象的絕對量,是一種資料視覺化技術。顏色的變化可能是通過色調或強度,給讀者提供明顯的視覺提示,說明現象是如何在空間上聚集或變化的。
面量圖有時被誤稱為熱圖。面量圖的特點是在地理邊界內有不同的陰影或圖案,以顯示感興趣的變數的比例,而熱圖(在地圖上)的顏色變化與地理邊界並不能對應上。"(出處: 維基百科)
P.23
評分標準
05
24
評分標準
P.25
作業說明
06
26
Simple baseline (3pt)
P.27
Medium baseline (3pt)
P.28
Strong baseline (4pt)
P.29
details
.enter()
.append("path")
.attr("fill", (d) => {
const townData = data.find(
(t) =>
t.county === d.properties.COUNTYNAME &&
t["county"].replace(" ", "") === d.properties.TOWNNAME
);
//return
})
.attr("d", path);
Refernce
P.30
繳交資訊
07
31
繳交資訊 Simple baseline
https://github.com/你的帳號/vis2023f/hw03/src/simple/
P.32
繳交資訊 Medium baseline
https://github.com/你的帳號/vis2023f/hw03/src/medium/
P.33
檔案分類
P.34
Export notebook
P.35
1. 點擊 ...
2. 選擇 Export
3. Download code
1. 匯出檔案前請確認所有cell都有run過、地圖、Table皆有呈現。
Export notebook
P.36
2. 將下載下來的檔案解壓縮,刪除裡面的 files 資料夾。並修改最主要的js檔案。
(名字是亂碼的那個,例如 ec0e39b666962d0e@457),並將URL路徑改成 ../UserData.json。如下圖紅框處。
Export notebook
P.37
3. 資料夾裡面會有兩個名字是亂碼的js檔案,選擇程式碼內有自己做的notebook 內容。
Github
P.38
4. 將 UserData.json 放到 src 檔案夾底下
Github
5. 在 src 檔案夾底下建立 strong 檔案夾,並將修改過後的檔案放入。
P.39
新增前往你的Demo網頁
P.40
<!-- ------------------------------------------------>
<div class="row hw12">
<div class="col-md-12 twenty">
<h4>前往你的 Demo 網頁</h4>
</div>
</div>
<!-- ------------------------------------------------>
<div class="row hw12">
<div class="col-md-12 twenty">
<a href="https://你的帳號.github.io/vis2023f/hw03/src/simple/你的檔案">https://你的帳號.github.io/vis2023f/hw03/src/simple/</a>
<hr>
<a href="https://你的帳號.github.io/vis2023f/hw03/src/medium/你的檔案">https://你的帳號.github.io/vis2023f/hw03/src/medium/</a>
<hr>
<a href="https://你的帳號.github.io/vis2023f/hw03/src/strong/">https://你的帳號.github.io/vis2023f/hw03/src/strong/</a>
</div>
</div>
Embed cells
P.41
1. 點擊 ...
2. 選擇 Export
3. Embed cells
Embed cells
P.42
1. 選擇 Entire notebook
3. Copy URL only
2. 確認是Iframe
Iframe
在hw03/index.html中原本為影片的地方程式碼如下:
改成自己的內容:
P.43
<div class="row hw12">
<div class="col-md-12 twenty">
<video id="video1" style="width:100%;max-width:100%;" controls="">
<source src="https://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
</video>
</div>
</div>
<div class="row hw12">
<div class="col-md-12 twenty">
<h4>Strong baseline - 建立課程班上學生居住縣市人數的 Choropleth</h4>
</div>
</div>
<div class="row hw12">
<div class="col-md-12 twenty">
<iframe width="100%" height="500" frameborder="0" style="background-color: #FFFFFF"
src="你的URL"></iframe>
</div>
</div>
評分表
更改 hw03/index.html 中程式碼
P.44
<table>
<tr>
<th>總分</th>
<th>完成後打勾</th>
<th>配分</th>
<th>分項描述</th>
</tr>
<tr>
<td rowspan="0" id="myTotal"></td>
<td><input type="checkbox" class="flipswitch" id="myCheckbox1" checked></td>
<td id='m1'>1</td>
<td>Simple baseline-1 - 播放自己的參訪路徑</td>
</tr>
<tr>
<td><input type="checkbox" class="flipswitch" id="myCheckbox2" checked></td>
<td id='m2'>2</td>
<td>Simple baseline-2 - 計算自己的移動距離/卡路里</td>
</tr>
<tr>
<td><input type="checkbox" class="flipswitch" id="myCheckbox3" checked></td>
<td id='m3'>3</td>
<td>Medium baseline - 建立課程班上學生居住縣市人數的 Choropleth</td>
</tr>
<tr>
<td><input type="checkbox" class="flipswitch" id="myCheckbox4" checked></td>
<td id='m4'>4</td>
<td>Strong baseline - 美術館樓層平面圖分區(造訪頻率)</td>
</tr>
</table>
評分表
更改 hw03/index.html 中程式碼
P.45
function update(){
var score = 0;
if (d3.select("#myCheckbox1").property("checked")){
score += parseInt(d3.select('#m1').html());
}
if (d3.select("#myCheckbox2").property("checked")){
score += parseInt(d3.select('#m2').html());
}
if (d3.select("#myCheckbox3").property("checked")){
score += parseInt(d3.select('#m3').html());
}
if (d3.select("#myCheckbox4").property("checked")){
score += parseInt(d3.select('#m4').html());
}
d3.select("#myTotal").html(score);
}
Regulations
P.47
助教聯絡資訊
08
48
助教聯絡資訊
P.49