Spaces:
Sleeping
Sleeping
switch to bbox search
Browse files
app.py
CHANGED
@@ -14,27 +14,37 @@ if not MAPILLARY_ACCESS_TOKEN:
|
|
14 |
st.error("Mapillary access token not found. Please configure it in the Space secrets.")
|
15 |
st.stop()
|
16 |
|
17 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
"""
|
19 |
Get the nearest Mapillary image to given coordinates
|
20 |
"""
|
|
|
21 |
params = {
|
22 |
'fields': 'id,thumb_1024_url',
|
23 |
-
'limit': 1
|
|
|
24 |
}
|
25 |
-
|
26 |
-
query = f"""
|
27 |
-
{{
|
28 |
-
"point": {{"type": "Point", "coordinates": [{lon}, {lat}]}},
|
29 |
-
"radius": {radius}
|
30 |
-
}}
|
31 |
-
"""
|
32 |
-
|
33 |
header = {'Authorization' : 'OAuth {}'.format(MAPILLARY_ACCESS_TOKEN)}
|
34 |
try:
|
35 |
-
response = requests.
|
36 |
-
"https://graph.mapillary.com/images
|
37 |
-
json=query,
|
38 |
params=params,
|
39 |
headers=header
|
40 |
)
|
|
|
14 |
st.error("Mapillary access token not found. Please configure it in the Space secrets.")
|
15 |
st.stop()
|
16 |
|
17 |
+
def get_bounding_box(lat, lon):
|
18 |
+
"""
|
19 |
+
Create a bounding box around a point that extends roughly 25 meters in each direction
|
20 |
+
at Amsterdam's latitude (52.37°N):
|
21 |
+
- 0.000224 degrees latitude = 25 meters N/S
|
22 |
+
- 0.000368 degrees longitude = 25 meters E/W
|
23 |
+
"""
|
24 |
+
lat_offset = 0.000224 # 25 meters in latitude
|
25 |
+
lon_offset = 0.000368 # 25 meters in longitude
|
26 |
+
return [
|
27 |
+
lon - lon_offset, # min longitude
|
28 |
+
lat - lat_offset, # min latitude
|
29 |
+
lon + lon_offset, # max longitude
|
30 |
+
lat + lat_offset # max latitude
|
31 |
+
]
|
32 |
+
|
33 |
+
def get_nearest_image(lat, lon):
|
34 |
"""
|
35 |
Get the nearest Mapillary image to given coordinates
|
36 |
"""
|
37 |
+
bbox = get_bounding_box(lat, lon)
|
38 |
params = {
|
39 |
'fields': 'id,thumb_1024_url',
|
40 |
+
'limit': 1,
|
41 |
+
'bbox': f'{bbox[0]},{bbox[1]},{bbox[2]},{bbox[3]}'
|
42 |
}
|
43 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
header = {'Authorization' : 'OAuth {}'.format(MAPILLARY_ACCESS_TOKEN)}
|
45 |
try:
|
46 |
+
response = requests.get(
|
47 |
+
"https://graph.mapillary.com/images",
|
|
|
48 |
params=params,
|
49 |
headers=header
|
50 |
)
|