]> git.openstreetmap.org Git - nominatim.git/blob - mytests/forward_tiger_functional.py
c12e399812babd90d56bd2555d7ffe529cfb453a
[nominatim.git] / mytests / forward_tiger_functional.py
1 import numpy as np
2 import urllib2 as url
3 import json as json
4 import random_points_bbox
5 import time
6
7 def test(num):
8     #first get some random points in the bbox
9     aPoints = random_points_bbox.getPoints(num, -100.815, 46.789, -100.717, 46.84)
10     #get the addresses
11     sReverseUrl = "http://localhost/nominatim/reverse.php?format=json&lat=%f&lon=%f"
12     aAddresses = []
13     for point in aPoints:
14         response = url.urlopen(sReverseUrl % (point[1], point[0]))
15         aAddresses.append(json.load(response)['address'])
16     #print aAddresses
17     # now we have all the addresses of the points in a list
18     # lets forward geocode this list
19     sOldUrl = "http://localhost/nominatim_old/search.php?format=json&city=%s&street=%s&addressdetails=1"
20     sLineUrl = "http://localhost/nominatim/search.php?format=json&city=%s&street=%s&addressdetails=1"
21     diff_lat =0
22     diff_lon =0
23     points =0
24     for address in aAddresses:
25         if 'house_number' in address and 'road' in address:
26             responseOld = url.urlopen(sOldUrl % (address['city'], address['house_number']+' '+address['road']))
27             dataOld = json.load(responseOld)
28             print dataOld[0]['display_name']
29             responseLine = url.urlopen(sLineUrl % (address['city'], address['house_number']+' '+address['road']))
30             dataLine = json.load(responseLine)
31             print dataLine[0]['display_name']
32             temp_diff_lat = np.abs(float(dataOld[0]['lat'])-float(dataLine[0]['lat']))
33             temp_diff_lon = np.abs(float(dataOld[0]['lon'])-float(dataLine[0]['lon']))
34             print "diff lat: "+str(temp_diff_lat*111166)+", diff lon: "+str(temp_diff_lon*250456)
35             diff_lat += temp_diff_lat
36             diff_lon += temp_diff_lon
37             points +=1
38
39     print "Average difference in lat degrees with %d elements: %f (meters: %f)" % (points, diff_lat/points, diff_lat/points*111166)
40     print "Average difference in lon degrees with %d elements: %f (meters: %f)" % (points, diff_lon/points, diff_lon/points*250456)
41     # at 46.8 deg: 1 deg lat=111.166, 1 deg lon=250.456
42         
43 test(20)