Twitter JSON 中的地理資料

使用 Python 分析社群媒體資料

Alex Hanna

Computational Social Scientist

推文文字中的地點

含地點文字的推文

使用 Python 分析社群媒體資料

使用者自訂地點

使用者自填地點

print(tweet['user']['location'])
Bay Area
使用 Python 分析社群媒體資料

place 的 JSON

外框框示意圖

print(tweet['place'])
{'attributes': {},
 'bounding_box': {'coordinates': 
  [[[-80.47611, 37.185195],
    [-80.47611, 37.273387],
    [-80.381618, 37.273387],
    [-80.381618, 37.185195]]],
  'type': 'Polygon'},
 'country': 'United States',
 'country_code': 'US',
 'full_name': 'Blacksburg, VA',
 'name': 'Blacksburg',
 'place_type': 'city',
 ...}
使用 Python 分析社群媒體資料

計算幾何中心

外框框示意圖

coordinates = [
    [-80.47611, 37.185195],
    [-80.47611, 37.273387],
    [-80.381618, 37.273387],
    [-80.381618, 37.185195]]

longs = np.unique( [x[0] for x 
    in coordinates] )
lats  = np.unique( [x[1] for x 
    in coordinates] )

central_long = np.sum(longs) / 2
central_lat  = np.sum(lats) / 2
使用 Python 分析社群媒體資料

coordinates 的 JSON

單一座標的地點

print(tweet['coordinates'])
{'type': 'Point', 
'coordinates': [-72.2833, 
                 21.7833]}
使用 Python 分析社群媒體資料

一起來練習吧!

使用 Python 分析社群媒體資料

Preparing Video For Download...