Hello!
I am using this endpoint 'https://tiles.mapillary.com/maps/vtp/mly_map_feature_traffic_sign/2/{}/{}/{}?access_token={}'
to fetch data that looks like this:
My question is: how would I convert those coordinates to (lat, lon), like: 45.06193, 85.50351? Is this the formula the one below?
if the image size is 800x600 pixels, and you want the point at 100,200, you take 100 x (width in degrees) / 800 + left edge longitude
, and 200 x (height in degrees) / 600 + lower edge latitude
.
Considering the extent will always be 4096, then replace
Update: (added code, maybe it becomes more clear) Is this function okay to convert from zoom_14_mapillary_type coordinates to real (lon, lat)?
Z14_TILE_DMD_WIDTH = 0.02197265625
Z14_TILE_DMD_HEIGHT = 0.018241950298914844
def get_normalized_coordinates(bbox: mercantile.LngLatBbox,
target_lat: int,
target_lon: int,
extent: int=4096): # 4096 is Mapillary's default
"""
Returns lon,lat tuple representing real position on world map of a map feature.
"""
min_lon, min_lat, _, _ = bbox
return min_lon + target_lon / extent * Z14_TILE_DMD_WIDTH,
min_lat + target_lat / extent * Z14_TILE_DMD_HEIGHT
And if you are wondering how I came with the constants that you see, I simply iterated over the list of tiles that I am interested in and checked to make sure they all have the same width/height size (this might have not been the case, keeping in mind what I mentioned above about tiles closer to one of the poles - I think this is called “distortion”, not sure). Also, for context: these tiles I iterated over are within this bbox: (-125.024414, 31.128199, -108.896484, 49.152970) (min_lon, min_lat, max_lon, max_lat; US west coast) which I believe is also why all the tiles have the same width/height sizes.
set_test = set()
for tile in relevant_tiles_set:
curr_bbox = mercantile.bounds(list_relevant_tiles_set[i])
dm_width_diff: float = curr_bbox.east - curr_bbox.west
dm_height_diff: float = curr_bbox.north - curr_bbox.south
set_test.add((dm_width_diff, dm_height_diff))
set_test
output:
{(0.02197265625, 0.018241950298914844}