-
Notifications
You must be signed in to change notification settings - Fork 1
/
mapGen.py
93 lines (68 loc) · 2.05 KB
/
mapGen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import folium
import numpy as num
import random
import sqlite3, time
from folium.plugins import HeatMap
connection = None
cursor = None
def connect(path):
global connection, cursor
connection = sqlite3.connect(path)
cursor = connection.cursor()
return
def get_data_points():
path="./All_tweets.db"
connect(path)
query = "SELECT lat, lon FROM tweets ORDER BY date DESC LIMIT 300"
tweets = cursor.execute(query)
all_tweets = [tweet for tweet in tweets]
print(len(all_tweets))
print(all_tweets)
#print(type(all_tweets[0][0]))
connection.close()
return all_tweets
#createHeatMap(heatArray)
def createHeatMap(heat_Map_Array, start_lat=53.540996, start_lon=-113.497746, start_zoom = 4):
# generate the map
mainMap = folium.Map(
location=[start_lat, start_lon],
zoom_start=start_zoom,
no_wrap=True,
world_copy_jump=True,
)
# add all layers
"""
folium.TileLayer('Mapbox Bright').add_to(mainMap)
folium.TileLayer('Mapbox Control Room').add_to(mainMap)
folium.TileLayer('Stamen Toner').add_to(mainMap)
folium.TileLayer('openstreetmap').add_to(mainMap)
folium.TileLayer('Stamen Terrain').add_to(mainMap)
"""
# add layer controller
# folium.LayerControl().add_to(mainMap)
pingPoints = {'lat': [], 'lon': []}
#print(pingPoints)
#print(list(zip(pingPoints['lat'], pingPoints['lon'])))
#heat = HeatMap(
#heat_Map_Array,
#min_opacity=0.2,
#max_val=1.0,
#radius=15, blur=15,
#max_zoom=1,)
heat = HeatMap(
heat_Map_Array, radius=15)
mainMap.add_child(heat)
# heatMap output
mainMap.save('static/heatMap.html')
if __name__ == "__main__":
#createHeatMap()
prev = -1
curr = 0
time.sleep(3)
while curr > prev:
heatArray = get_data_points()
#createHeatMap(heatArray,53.540996,-113.497746)
createHeatMap(heatArray,39,-98)
time.sleep(2)
prev = curr
curr = len(heatArray)