From 96527c801dbfd53ded84355f9b052c4bb9ebbd7a Mon Sep 17 00:00:00 2001 From: "james.p.turk" Date: Thu, 19 Jun 2008 20:44:50 +0000 Subject: [PATCH] let non-negative longitudes slide and normalize district numbers git-svn-id: https://polipoly.googlecode.com/svn/trunk@15 1885ebd5-0a40-0410-88a4-770918bee656 --- polipoly.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/polipoly.py b/polipoly.py index 5935b11..3ab0eae 100644 --- a/polipoly.py +++ b/polipoly.py @@ -287,9 +287,16 @@ class AddressToDistrictService(object): def lat_long_to_district(self, lat, lng): """ Obtain the district containing a given latitude and longitude.""" - flat, flng = float(lat), float(lng) - return lat, lng, [(cb.state, cb.district) for cb in self.boundaries - if cb.contains((flng,flat))] + flat, flng = float(lat), -abs(float(lng)) + districts = [] + for cb in self.boundaries: + if cb.contains((flng,flat)): + if cb.district == '98': + cb.district = '00' + elif cb.district[0] == '0': + cb.district = cb.district[1] + districts.append((cb.state, cb.district)) + return lat, lng, districts def address_to_district(self, address): """Given an address returns the congressional district it lies within.