HI guys, I’m using python and I’m trying to, given an image id, download the corresponding photo, but I get this error:
KeyError: ‘thumb_2048_url’
{‘error’: {‘message’: ‘Tried accessing nonexisting field (thumb_2048_url) on node type (ChunkObject)’, ‘type’: ‘MLYApiException’, ‘code’: 100, ‘fbtrace_id’: ‘A2gwrQlLdZjcvK60-q86dlv’} }
as if it wasn’t possible.
this is the code to get the file geojson given the coordinates:
import requests
import codes
import math
import json
import os
from vt2geojson.tools import vt_bytes_to_geojson
def deg2num(lat_deg, lon_deg, zoom):
lat_rad = math.radians(lat_deg)
n = 2.0 ** zoom
xtile = int((lon_deg + 180.0) / 360.0 * n)
ytile = int((1.0 - math.asinh(math.tan(lat_rad)) / math.pi) / 2.0 * n)
return (xtile, ytile)
outputFolder = r"C:\example"
z = 14
ll_lat = 40.82386
ll_lon = 14.19281
ur_lat = 40.85177
ur_lon = 14.26812
llx,lly = deg2num (ll_lat, ll_lon, z)
urx,ury = deg2num (ur_lat, ur_lon, z)
type=“mly_map_feature_traffic_sign”
output = {“type”:“FeatureCollection”,“features”:}
for x in range(min(llx,urx),max(llx,urx),1):
for y in range(min(lly,ury),max(lly,ury),1):
print(type,x,y)
url = f"https://tiles.mapillary.com/maps/vtp/{type}/2/{z}/{x}/{y}?access_token={codes.API_KEY}"
r = requests.get(url)
assert r.status_code == 200, r.content
vt_content = r.content
features = vt_bytes_to_geojson(vt_content, x, y, z)
for f in features[“features”]:
output[‘features’].append(f)
with open(outputFolder + os.path.sep + type + “" + str(z) + "” + str(llx) + “" + str(urx) + "” + str(lly) + “_” + str(ury) + “.geojson”, “w”) as fx:
json.dump(output, fx)
this is the code to get the photo:
import geojson
import requests
import codes
outputFolder = r"C:\example"
id_list =
with open(r"C:\example\mly_map_feature_traffic_sign_14_8837_8841_6153_6151.geojson", “r”) as file:
temp = geojson.load(file)
for feature in temp[‘features’]:
id_list.append(feature[‘properties’][‘id’])
app_access_token = codes.API_KEY
image_id = id_list[0]
header = {‘Authorization’: ‘OAuth {}’.format(app_access_token)}
url = f"https://graph.mapillary.com/{image_id}?fields=thumb_2048_url"
response = requests.get(url, headers=header)
data = response.json()
print(data)
image_url = data[‘thumb_2048_url’]
with open(‘{}/{}.jpg’.format(outputFolder, image_id), ‘wb’) as handler:
image_data = requests.get(image_url, stream=True).content
handler.write(image_data)