aboutsummaryrefslogtreecommitdiff
path: root/ingrex
diff options
context:
space:
mode:
authorJinwei Zhao <[email protected]>2017-01-31 08:35:05 +0800
committerJinwei Zhao <[email protected]>2017-01-31 08:35:05 +0800
commit66d411c97ba82bfe3b072b57d2b7f8a6554723d6 (patch)
treebaa314fc017e84e2aa5d39ca9ee0922e79957e07 /ingrex
parent8a1af78b809716a471d1c0d12cfcf89d2e19070f (diff)
downloadCOMM2TG-66d411c97ba82bfe3b072b57d2b7f8a6554723d6.tar.gz
format
Diffstat (limited to 'ingrex')
-rwxr-xr-xingrex/intel.py6
-rwxr-xr-xingrex/praser.py1
-rwxr-xr-xingrex/utils.py19
3 files changed, 18 insertions, 8 deletions
diff --git a/ingrex/intel.py b/ingrex/intel.py
index f13b2a2..506c6bc 100755
--- a/ingrex/intel.py
+++ b/ingrex/intel.py
@@ -2,7 +2,7 @@
2import requests 2import requests
3import re 3import re
4import json 4import json
5import os 5
6 6
7class Intel(object): 7class Intel(object):
8 "main class with all Intel functions" 8 "main class with all Intel functions"
@@ -43,7 +43,7 @@ class Intel(object):
43 count = 0 43 count = 0
44 while count < 3: 44 while count < 3:
45 try: 45 try:
46 request = self.session.post(url, data=json.dumps(payload), headers=self.headers) 46 request = self.session.post(url, data=json.dumps(payload), headers=self.headers, timeout=600)
47 return request.json()['result'] 47 return request.json()['result']
48 except requests.ConnectionError: 48 except requests.ConnectionError:
49 raise IntelError 49 raise IntelError
@@ -132,10 +132,12 @@ class Intel(object):
132 } 132 }
133 return self.fetch(url, payload) 133 return self.fetch(url, payload)
134 134
135
135class IntelError(BaseException): 136class IntelError(BaseException):
136 """Intel Error""" 137 """Intel Error"""
137 pass 138 pass
138 139
140
139class CookieError(IntelError): 141class CookieError(IntelError):
140 """Intel Error""" 142 """Intel Error"""
141 pass 143 pass
diff --git a/ingrex/praser.py b/ingrex/praser.py
index 732ab1b..a05ec1e 100755
--- a/ingrex/praser.py
+++ b/ingrex/praser.py
@@ -9,6 +9,7 @@ if osname == "Linux":
9 os.environ['TZ'] = 'Asia/Shanghai' 9 os.environ['TZ'] = 'Asia/Shanghai'
10 time.tzset() 10 time.tzset()
11 11
12
12class Message(object): 13class Message(object):
13 "Message object" 14 "Message object"
14 def __init__(self, raw_msg): 15 def __init__(self, raw_msg):
diff --git a/ingrex/utils.py b/ingrex/utils.py
index 8090f15..17d69e6 100755
--- a/ingrex/utils.py
+++ b/ingrex/utils.py
@@ -1,14 +1,16 @@
1"Map Utils" 1"Map Utils"
2from math import pi, sin, cos, tan, asin, radians, sqrt, log 2from math import pi, sin, cos, tan, asin, radians, sqrt, log
3 3
4
4def calc_tile(lng, lat, zoomlevel): 5def calc_tile(lng, lat, zoomlevel):
5 tilecounts = [1,1,1,40,40,80,80,320,1E3,2E3,2E3,4E3,8E3,16E3,16E3,32E3] 6 tilecounts = [1, 1, 1, 40, 40, 80, 80, 320, 1E3, 2E3, 2E3, 4E3, 8E3, 16E3, 16E3, 32E3]
6 rlat = radians(lat) 7 rlat = radians(lat)
7 tilecount = tilecounts[zoomlevel] 8 tilecount = tilecounts[zoomlevel]
8 xtile = int((lng + 180.0) / 360.0 * tilecount) 9 xtile = int((lng + 180.0) / 360.0 * tilecount)
9 ytile = int((1.0 - log(tan(rlat) + (1 / cos(rlat))) / pi) / 2.0 * tilecount) 10 ytile = int((1.0 - log(tan(rlat) + (1 / cos(rlat))) / pi) / 2.0 * tilecount)
10 return xtile, ytile 11 return xtile, ytile
11 12
13
12def calc_dist(lat1, lng1, lat2, lng2): 14def calc_dist(lat1, lng1, lat2, lng2):
13 lat1, lng1, lat2, lng2 = map(radians, [lat1, lng1, lat2, lng2]) 15 lat1, lng1, lat2, lng2 = map(radians, [lat1, lng1, lat2, lng2])
14 dlat = lat1 - lat2 16 dlat = lat1 - lat2
@@ -18,12 +20,13 @@ def calc_dist(lat1, lng1, lat2, lng2):
18 m = 6367.0 * c * 1000 20 m = 6367.0 * c * 1000
19 return m 21 return m
20 22
23
21def point_in_poly(x, y, poly): 24def point_in_poly(x, y, poly):
22 n = len(poly) 25 n = len(poly)
23 inside = False 26 inside = False
24 p1x,p1y = poly[0] 27 p1x, p1y = poly[0]
25 for i in range(n+1): 28 for i in range(n+1):
26 p2x,p2y = poly[i % n] 29 p2x, p2y = poly[i % n]
27 if y > min(p1y, p2y): 30 if y > min(p1y, p2y):
28 if y <= max(p1y, p2y): 31 if y <= max(p1y, p2y):
29 if x <= max(p1x, p2x): 32 if x <= max(p1x, p2x):
@@ -31,9 +34,10 @@ def point_in_poly(x, y, poly):
31 xints = (y - p1y) * (p2x - p1x) / (p2y - p1y) + p1x 34 xints = (y - p1y) * (p2x - p1x) / (p2y - p1y) + p1x
32 if p1x == p2x or x <= xints: 35 if p1x == p2x or x <= xints:
33 inside = not inside 36 inside = not inside
34 p1x,p1y = p2x,p2y 37 p1x, p1y = p2x, p2y
35 return inside 38 return inside
36 39
40
37def transform(wgLat, wgLon): 41def transform(wgLat, wgLon):
38 """ 42 """
39 transform(latitude,longitude) , WGS84 43 transform(latitude,longitude) , WGS84
@@ -44,7 +48,7 @@ def transform(wgLat, wgLon):
44 if (outOfChina(wgLat, wgLon)): 48 if (outOfChina(wgLat, wgLon)):
45 mgLat = wgLat 49 mgLat = wgLat
46 mgLon = wgLon 50 mgLon = wgLon
47 return mgLat,mgLon 51 return mgLat, mgLon
48 dLat = transformLat(wgLon - 105.0, wgLat - 35.0) 52 dLat = transformLat(wgLon - 105.0, wgLat - 35.0)
49 dLon = transformLon(wgLon - 105.0, wgLat - 35.0) 53 dLon = transformLon(wgLon - 105.0, wgLat - 35.0)
50 radLat = wgLat / 180.0 * pi 54 radLat = wgLat / 180.0 * pi
@@ -55,7 +59,8 @@ def transform(wgLat, wgLon):
55 dLon = (dLon * 180.0) / (a / sqrtMagic * cos(radLat) * pi) 59 dLon = (dLon * 180.0) / (a / sqrtMagic * cos(radLat) * pi)
56 mgLat = wgLat + dLat 60 mgLat = wgLat + dLat
57 mgLon = wgLon + dLon 61 mgLon = wgLon + dLon
58 return mgLat,mgLon 62 return mgLat, mgLon
63
59 64
60def outOfChina(lat, lon): 65def outOfChina(lat, lon):
61 if (lon < 72.004 or lon > 137.8347): 66 if (lon < 72.004 or lon > 137.8347):
@@ -64,6 +69,7 @@ def outOfChina(lat, lon):
64 return True 69 return True
65 return False 70 return False
66 71
72
67def transformLat(x, y): 73def transformLat(x, y):
68 ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * sqrt(abs(x)) 74 ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * sqrt(abs(x))
69 ret += (20.0 * sin(6.0 * x * pi) + 20.0 * sin(2.0 * x * pi)) * 2.0 / 3.0 75 ret += (20.0 * sin(6.0 * x * pi) + 20.0 * sin(2.0 * x * pi)) * 2.0 / 3.0
@@ -71,6 +77,7 @@ def transformLat(x, y):
71 ret += (160.0 * sin(y / 12.0 * pi) + 320 * sin(y * pi / 30.0)) * 2.0 / 3.0 77 ret += (160.0 * sin(y / 12.0 * pi) + 320 * sin(y * pi / 30.0)) * 2.0 / 3.0
72 return ret 78 return ret
73 79
80
74def transformLon(x, y): 81def transformLon(x, y):
75 ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * sqrt(abs(x)) 82 ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * sqrt(abs(x))
76 ret += (20.0 * sin(6.0 * x * pi) + 20.0 * sin(2.0 * x * pi)) * 2.0 / 3.0 83 ret += (20.0 * sin(6.0 * x * pi) + 20.0 * sin(2.0 * x * pi)) * 2.0 / 3.0
Powered by cgit v1.2.3 (git 2.41.0)