-
Notifications
You must be signed in to change notification settings - Fork 0
/
topomap_client.py
71 lines (62 loc) · 2.79 KB
/
topomap_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from __future__ import print_function
import base64
import requests
import os
import geojson
import argparse
import sys
IP="localhost"
ROUTING_SERVER_URL = 'http://{}:21500/'.format(IP)
STREETVIEW_SERVER_URL = 'http://{}:21501/'.format(IP)
POI_SERVER_URL = 'http://{}:21502/'.format(IP)
def query_to_server(url, req):
if req['type']=='tile':
req_str = url + '{}/{}/{}'.format(req['type'], req['tile_num_x'], req['tile_num_y'])
elif req['type']=='wgs':
req_str = url + '{}/{}/{}/{}'.format(req['type'], req['latitude'], req['longitude'], req['radius'])
elif req['type'] in ['node', 'routing_node']:
req_str = url + '{}/{}/{}'.format(req['type'], req['node_id'], req['radius'])
else:
print('{} is not a valid request type'.format(req['type']))
return None
response = requests.get(req_str)
response.raise_for_status()
elapsed_time = response.elapsed.total_seconds()
outputs = response.json()
return outputs
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Topological Map Client")
parser.add_argument("server_type", type=str, help="request type (routing, streetview, or poi)")
parser.add_argument("req_type", type=str, help="request type (tile, wgs, or node)")
args = parser.parse_args()
if args.server_type=="routing":
SERVER_URL = ROUTING_SERVER_URL
elif args.server_type=="streetview":
SERVER_URL = STREETVIEW_SERVER_URL
elif args.server_type=="poi":
SERVER_URL = POI_SERVER_URL
else:
print("Not suppported server type")
sys.exit()
if args.req_type=="tile":
req = {'type': 'tile', 'tile_num_x': 55845, 'tile_num_y': 25390}
elif args.req_type=="wgs":
#req = {'type': 'wgs', 'latitude': 37.513366, 'longitude': 127.056132, 'radius': 500.0}
req = {'type': 'wgs', 'latitude': 37.515132, 'longitude': 126.770124, 'radius': 500.0}
#req = {'type': 'wgs', 'latitude': 30, 'longitude': 120} # Invalid request (out of range)
elif args.req_type=="node":
if args.server_type=="routing":
req = {'type': 'node', 'node_id': 558452539001190, 'radius': 500.0} # For routing layers
elif args.server_type=="streetview":
req = {'type': 'node', 'node_id': 19737201510, 'radius': 200.0} # For streetview layers
elif args.server_type=="poi":
req = {'type': 'node', 'node_id': 37644126, 'radius': 200.0} # For Poi layers
elif args.req_type=="rnode":
req = {'type': 'routing_node', 'node_id': 558452539001190, 'radius': 500.0}
else:
print("Not suppported request type")
sys.exit()
res = query_to_server(SERVER_URL, req)
if res != None:
with open("results/{}_{}.geojson".format(args.server_type, args.req_type),'w') as f:
geojson.dump(res, f)