I have a question where there must be a straightforward solution, but I just don’t get it.
I use the mapillary API to get images of different cities via their coordinates. For this I first of all make an API call to get the image ID’s that I want. It uses Python and looks like this:
import mapillary as mly
mly.interface.set_access_token('here_is_my_private_token')
gj = mly.interface.get_image_close_to(longitude=11.49385, latitude=48.05053, radius=50)
print(gj)
This works without trouble and creates a geojson object. The print statement for these example coordinates gives me this:
{‘type’: ‘FeatureCollection’, ‘features’: [{‘type’: Feature, ‘geometry’: {‘type’: Point, ‘coordinates’: [11.49345874786377, 48.050743224759515]}, ‘properties’: {‘captured_at’: 1560688528671, ‘compass_angle’: 219.55442810059, ‘creator_id’: 105621578345075, ‘id’: 156304466376583, ‘is_pano’: False, ‘sequence_id’: ‘q88pqp6h720xf4tf3x0mut’}}, {‘type’: Feature, ‘geometry’: {‘type’: Point, ‘coordinates’: [11.49367868900299, 48.05092969456331]}, ‘properties’: {‘captured_at’: 1560688523518, ‘compass_angle’: 218.94528198242, ‘creator_id’: 105621578345075, ‘id’: 4152401114851048, ‘is_pano’: False, ‘sequence_id’: ‘q88pqp6h720xf4tf3x0mut’}}, {‘type’: Feature, ‘geometry’: {‘type’: Point, ‘coordinates’: [11.493721604347229, 48.0509691400122]}, ‘properties’: {‘captured_at’: 1560688522466, ‘compass_angle’: 216.1079864502, ‘creator_id’: 105621578345075, ‘id’: 957272818356791, ‘is_pano’: False, ‘sequence_id’: ‘q88pqp6h720xf4tf3x0mut’}}, {‘type’: Feature, ‘geometry’: {‘type’: Point, ‘coordinates’: [11.493549942970276, 48.05081852995386]}, ‘properties’: {‘captured_at’: 1560688526608, ‘compass_angle’: 216.87623596191, ‘creator_id’: 105621578345075, ‘id’: 195685349071104, ‘is_pano’: False, ‘sequence_id’: ‘q88pqp6h720xf4tf3x0mut’}}, {‘type’: Feature, ‘geometry’: {‘type’: Point, ‘coordinates’: [11.493507027626038, 48.0507790843896]}, ‘properties’: {‘captured_at’: 1560688527607, ‘compass_angle’: 217.21737670898, ‘creator_id’: 105621578345075, ‘id’: 494493828463470, ‘is_pano’: False, ‘sequence_id’: ‘q88pqp6h720xf4tf3x0mut’}}, {‘type’: Feature, ‘geometry’: {‘type’: Point, ‘coordinates’: [11.493635773658752, 48.05089383503807]}, ‘properties’: {‘captured_at’: 1560688524562, ‘compass_angle’: 217.47109985352, ‘creator_id’: 105621578345075, ‘id’: 5440816592658176, ‘is_pano’: False, ‘sequence_id’: ‘q88pqp6h720xf4tf3x0mut’}}, {‘type’: Feature, ‘geometry’: {‘type’: Point, ‘coordinates’: [11.493603587150574, 48.05086514739992]}, ‘properties’: {‘captured_at’: 1560688525562, ‘compass_angle’: 216.0885925293, ‘creator_id’: 105621578345075, ‘id’: 916290425872451, ‘is_pano’: False, ‘sequence_id’: ‘q88pqp6h720xf4tf3x0mut’}}]}
Now all I want is to get a list that contains all the values of the key ‘id’. The rest of the data is not needed.
I thought I simply use nested dictionary logic to get these values. Also, other Stackoverflow posts show this as the correct way. I therefore tried things like:
id = gj['features'][0]['properties']['id']
features = gj['features']
And similar stuff. However, this throws ‘TypeError: ‘GeoJSON’ object is not subscriptable’
Or I tried standard dictionary attributes like:
keys = gj.keys()
values = gj.values()
This throws ‘AttributeError: ‘GeoJSON’ object has no attribute ‘keys’, ‘values’… .
I’m well aware of what these errors mean, but I can’t solve them since I have no experience with working with geojson objects. Apparently, a geojson object looks like a dictionary but works differently. Or am I missing something? How do I get my needed list?
Thanks for your help, it is much appreciated.
Powknow is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.