From 17e8e349ac891dda3bdf7ad3f5842f15251fff9e Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Tue, 23 Nov 2010 10:50:40 +0100 Subject: [PATCH] add location --- ox/__init__.py | 2 +- ox/location.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 ox/location.py diff --git a/ox/__init__.py b/ox/__init__.py index 4004411..21f4319 100644 --- a/ox/__init__.py +++ b/ox/__init__.py @@ -14,4 +14,4 @@ import net from torrent import * - +import location diff --git a/ox/location.py b/ox/location.py new file mode 100644 index 0000000..3efc479 --- /dev/null +++ b/ox/location.py @@ -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 +