Repository navigation
Expand file tree
/
Copy pathelevation.py
More file actions
63 lines (49 loc) · 1.79 KB
/
Copy pathelevation.py
File metadata and controls
63 lines (49 loc) · 1.79 KB
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
import httputils
import json
import random
import MySQLdb
import math
import sys
POINTS_PER_REQUEST = 10
class Area:
def __init__(self, name, minLat, maxLat, minLng, maxLng):
self.name = name
self.minLat = minLat
self.maxLat = maxLat
self.minLng = minLng
self.maxLng = maxLng
idf = Area("idf", 48.1200811, 49.241504, 1.44617, 3.5590069)
area = idf
def getRandomPoint(minLat, maxLat, minLng, maxLng):
rangeLat = maxLat - minLat
rangeLng = maxLng - minLng
lat = minLat + random.random() * rangeLat
lng = minLng + random.random() * rangeLng
if (random.random() < math.cos(lat * math.pi / 180)):
return (lat, lng)
else:
return getRandomPoint(minLat, maxLat, minLng, maxLng)
def launch():
points = []
for i in range(POINTS_PER_REQUEST):
(random_lat, random_lng) = getRandomPoint(area.minLat, area.maxLat, area.minLng, area.maxLng)
points.append(str(random_lat) + ',' + str(random_lng))
url='http://maps.googleapis.com/maps/api/elevation/json?sensor=false&locations=' + "|".join(points)
jsonRes = json.loads(httputils.get(url))
db = MySQLdb.connect("localhost", "elevation", "elevation", "elevation" )
cursor = db.cursor()
try:
for result in jsonRes['results']:
lat = str(result['location']['lat'])
lng = str(result['location']['lng'])
resolution = str(result['resolution'])
elevation = str(result['elevation'])
sql = "insert into el_point(area, date, lat, lng, res, elv) values ('" + area.name + "', now(), " + lat + ", " + lng + ", " + resolution + ", " + elevation + ");";
cursor.execute(sql)
db.commit()
except:
db.rollback()
raise
db.close()
for i in range(0, 6):
launch()