Geographical data in Twitter JSON

Menganalisis Data Media Sosial dengan Python

Alex Hanna

Computational Social Scientist

Locations in Twitter text

Tweet with location text

Menganalisis Data Media Sosial dengan Python

User-defined location

User-defined location

print(tweet['user']['location'])
Bay Area
Menganalisis Data Media Sosial dengan Python

place JSON

Bounding box illustration

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',
 ...}
Menganalisis Data Media Sosial dengan Python

Calculating the centroid

Bounding box illustration

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
Menganalisis Data Media Sosial dengan Python

coordinates JSON

Single coordinate place

print(tweet['coordinates'])
{'type': 'Point', 
'coordinates': [-72.2833, 
                 21.7833]}
Menganalisis Data Media Sosial dengan Python

Let's practice!

Menganalisis Data Media Sosial dengan Python

Preparing Video For Download...