From 51cd3be2ebe390e92e8558a32a1d4518f6cc31bd Mon Sep 17 00:00:00 2001 From: Fredrik Unger Date: Wed, 19 Dec 2012 10:45:28 +0100 Subject: [PATCH] address: geocode language, objects for mapimages Added a accept-language header to the nominatim requests. Started to use Coord objects in mapimages, but still need more work. --- xinclude/address.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/xinclude/address.py b/xinclude/address.py index be9930f..30e8a07 100755 --- a/xinclude/address.py +++ b/xinclude/address.py @@ -150,12 +150,14 @@ class Address(object): self.name = None self.coord = None - def geocode(self): + + def geocode(self, language='en'): base_url = 'http://nominatim.openstreetmap.org/search?%s' params = { 'addressdetails': 1, 'limit': 1, 'format': 'xml', - 'polygon': 0 } + 'polygon': 0, + 'accept-language': language} if self.country: t = etree.parse('/usr/share/xml/iso-codes/iso_3166.xml') @@ -218,16 +220,17 @@ def mark(image, coord): bbox = (x-r, y-r, x+r, y+r) draw.ellipse(bbox, outline="red") +def box(image,box): + draw = ImageDraw.Draw(image) + draw.rectangle(box, outline="red") + def mapimages(coords, zoom=15,size=(TS,TS)): - minlat = 1000 - maxlat = 0 - minlon = 1000 - maxlon = 0 - for c in coords: - minlat = min(minlat,c[0]) - maxlat = max(maxlat,c[0]) - minlon = min(minlon,c[1]) - maxlon = max(maxlon,c[1]) + + minlat = min(coords,key=attrgetter('latitude')) + maxlat = max(coords,key=attrgetter('latitude')) + minlon = min(coords,key=attrgetter('longitude')) + maxlon = max(coords,key=attrgetter('longitude')) + # Find minimal bounding box and expand it 5% hyp = distance((maxlat,minlon),(minlat,maxlon)) hyp = hyp*0.05 @@ -236,6 +239,8 @@ def mapimages(coords, zoom=15,size=(TS,TS)): lld = Geodesic.WGS84.Direct(minlat, minlon, 225, hyp) lrd = Geodesic.WGS84.Direct(minlat, maxlon, 135, hyp) + ul = Coord(maxlat,minlon).direct(315, hyp) + ul = (uld['lat2'],uld['lon2']) ur = (urd['lat2'],urd['lon2']) ll = (lld['lat2'],lld['lon2']) -- 2.30.2