The following code shows an example of how to infer the floor information from the altitude of a location update, and convert the (lat, lon) coordinates to pixel (x, y) to ease display on an image map.
1 | import matplotlib.pyplot as plt |
7 | AUTH_TOKEN = "YOURTOKEN" |
11 | LOCATION = {'lon': -80.16644294783441, 'lat': 25.777023335006763, 'alt': 75.0} |
15 | building_id = requests.get(buildings_url, headers={'Authorization': AUTH_TOKEN}).json()['data'][0]['id'] |
17 | floors_data = requests.get(floors_url, headers={'Authorization': AUTH_TOKEN}).json()['data'] |
20 | location_update_floor_data = [a for a in floors_data if a['attributes']['relative_altitude'] == LOCATION['alt']][0] |
21 | location_update_floor= location_update_floor_data['attributes']['level_number'] |
22 | map_image = 'maps/floor ' + str(location_update_floor) + '.png' |
23 | location_update_floor_georeferencing_data = location_update_floor_data['attributes']['georeference_info'] |
28 | def wgs84_to_pixels(longitude, latitude): |
29 | LonX = location_update_floor_georeferencing_data['lon_x'] |
30 | LatX = location_update_floor_georeferencing_data['lat_x'] |
31 | OffsetX = location_update_floor_georeferencing_data['offset_x'] |
32 | LonY = location_update_floor_georeferencing_data['lon_y'] |
33 | LatY = location_update_floor_georeferencing_data['lat_y'] |
34 | OffsetY = location_update_floor_georeferencing_data['offset_y'] |
36 | x = longitude * LonX + latitude * LatX + OffsetX |
37 | y = longitude * LonY + latitude * LatY + OffsetY |
42 | image = Image.open(map_image) |
44 | x, y = wgs84_to_pixels(LOCATION['lon'], LOCATION['lat']) |