add location
This commit is contained in:
parent
90573b9924
commit
17e8e349ac
2 changed files with 29 additions and 1 deletions
|
@ -14,4 +14,4 @@ import net
|
||||||
|
|
||||||
from torrent import *
|
from torrent import *
|
||||||
|
|
||||||
|
import location
|
||||||
|
|
28
ox/location.py
Normal file
28
ox/location.py
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
|
import math
|
||||||
|
|
||||||
|
|
||||||
|
def center(lat_sw, lng_sw, lat_ne=None, lng_ne=None):
|
||||||
|
if not lat_ne and not lng_ne:
|
||||||
|
return min(lat_sw, lng_sw) + abs(lat_sw-lng_sw)/2
|
||||||
|
else:
|
||||||
|
return (center(lat_sw,lng_sw), center(lat_ne, lng_ne))
|
||||||
|
|
||||||
|
def area(lat_sw, lng_sw, lat_ne, lng_ne):
|
||||||
|
return (lat_ne - lat_sw) * (lng_ne - lng_sw)
|
||||||
|
|
||||||
|
def latlngspan2latlng(lat, lng, latSpan, lngSpan):
|
||||||
|
return dict(
|
||||||
|
lat_sw = lat - latSpan, lng_sw = lng - lngSpan,
|
||||||
|
lat_ne = lat + latSpan, lng_ne = lng + latSpan
|
||||||
|
)
|
||||||
|
|
||||||
|
def parseLocationString(location_string):
|
||||||
|
l = location_string.split('+')
|
||||||
|
if len(l) == 1:
|
||||||
|
l = location_string.split(';')
|
||||||
|
l = [i.strip() for i in l]
|
||||||
|
l = filter(lambda x: x, l)
|
||||||
|
return l
|
||||||
|
|
Loading…
Reference in a new issue