From 66d411c97ba82bfe3b072b57d2b7f8a6554723d6 Mon Sep 17 00:00:00 2001 From: Jinwei Zhao Date: Tue, 31 Jan 2017 08:35:05 +0800 Subject: format --- ingrex/utils.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'ingrex/utils.py') 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 @@ "Map Utils" from math import pi, sin, cos, tan, asin, radians, sqrt, log + def calc_tile(lng, lat, zoomlevel): - tilecounts = [1,1,1,40,40,80,80,320,1E3,2E3,2E3,4E3,8E3,16E3,16E3,32E3] + tilecounts = [1, 1, 1, 40, 40, 80, 80, 320, 1E3, 2E3, 2E3, 4E3, 8E3, 16E3, 16E3, 32E3] rlat = radians(lat) tilecount = tilecounts[zoomlevel] xtile = int((lng + 180.0) / 360.0 * tilecount) ytile = int((1.0 - log(tan(rlat) + (1 / cos(rlat))) / pi) / 2.0 * tilecount) return xtile, ytile + def calc_dist(lat1, lng1, lat2, lng2): lat1, lng1, lat2, lng2 = map(radians, [lat1, lng1, lat2, lng2]) dlat = lat1 - lat2 @@ -18,12 +20,13 @@ def calc_dist(lat1, lng1, lat2, lng2): m = 6367.0 * c * 1000 return m + def point_in_poly(x, y, poly): n = len(poly) inside = False - p1x,p1y = poly[0] + p1x, p1y = poly[0] for i in range(n+1): - p2x,p2y = poly[i % n] + p2x, p2y = poly[i % n] if y > min(p1y, p2y): if y <= max(p1y, p2y): if x <= max(p1x, p2x): @@ -31,9 +34,10 @@ def point_in_poly(x, y, poly): xints = (y - p1y) * (p2x - p1x) / (p2y - p1y) + p1x if p1x == p2x or x <= xints: inside = not inside - p1x,p1y = p2x,p2y + p1x, p1y = p2x, p2y return inside + def transform(wgLat, wgLon): """ transform(latitude,longitude) , WGS84 @@ -44,7 +48,7 @@ def transform(wgLat, wgLon): if (outOfChina(wgLat, wgLon)): mgLat = wgLat mgLon = wgLon - return mgLat,mgLon + return mgLat, mgLon dLat = transformLat(wgLon - 105.0, wgLat - 35.0) dLon = transformLon(wgLon - 105.0, wgLat - 35.0) radLat = wgLat / 180.0 * pi @@ -55,7 +59,8 @@ def transform(wgLat, wgLon): dLon = (dLon * 180.0) / (a / sqrtMagic * cos(radLat) * pi) mgLat = wgLat + dLat mgLon = wgLon + dLon - return mgLat,mgLon + return mgLat, mgLon + def outOfChina(lat, lon): if (lon < 72.004 or lon > 137.8347): @@ -64,6 +69,7 @@ def outOfChina(lat, lon): return True return False + def transformLat(x, y): ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * sqrt(abs(x)) 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): ret += (160.0 * sin(y / 12.0 * pi) + 320 * sin(y * pi / 30.0)) * 2.0 / 3.0 return ret + def transformLon(x, y): ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * sqrt(abs(x)) ret += (20.0 * sin(6.0 * x * pi) + 20.0 * sin(2.0 * x * pi)) * 2.0 / 3.0 -- cgit v1.2.3