Created
August 15, 2022 10:21
-
-
Save Rubix982/ac0dec47956484006b900f8027d2d720 to your computer and use it in GitHub Desktop.
Store the image ids
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# import the geojson model from mapillary | |
from mapillary.models.geojson import GeoJSON | |
image_id_list: list = [] | |
# Iterating over the rows of the df | |
for index, row in enumerate(safegraph_df.iterrows()): | |
# An empty dictionary that will hold our data as we go along | |
coordinates_to_image_id_dict: dict = {} | |
# Only retrieve the first 20 records from | |
# the safegraph dataset | |
if index == 20: | |
break | |
# Converting each row into a dictionary, then extracting the Lat, Long | |
latitude, longitude = dict(row[1])['Lat'], dict(row[1])['Long'] | |
# Save the longitude and the latitude in the dict defined above | |
coordinates_to_image_id_dict['lat'] = latitude | |
coordinates_to_image_id_dict['lng'] = longitude | |
# Get a `FeatureCollection` given the coordinates defined above, and | |
# converting to a dictionary | |
data: dict = mly.get_image_looking_at(at={'lng': longitude, 'lat': latitude}).to_dict() | |
# Define an empty list which will store our image_ids | |
coordinates_to_image_id_dict['image_ids'] = [] | |
# Iterate over the features retrieved | |
for index, feature in enumerate(data['features']): | |
# Only select 16 image_ids (0-15) | |
# If you'd like to select more, change the number '16' | |
# If you'd like to select ALL retrieved image_ids, comment out the | |
# next two lines | |
if index == 16: | |
break | |
# Append to the list the image_id from the feature | |
coordinates_to_image_id_dict['image_ids'].append(feature['properties']['id']) | |
# Finally, append this dictionary to the final result | |
# That is, the image_id_list variable | |
image_id_list.append(coordinates_to_image_id_dict) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment