I have a mongoDB and store coordinates in a collection. If I do:
print doc["coordinates"]
it returns:
{u'type': u'Point', u'coordinates': [-81.4531344, 28.5287337]}
But if I just want the individual longitudes and latitudes, I’m trying to extract it by:
print doc["coordinates" : [0][1]]
I get nothing printed.
Thanks
I am not familiar with mongoDB, but if that returned structure is a Python dictionary as it appears, you can access the coordinates like this:
docappears to be a dictionary of dictionaries, and when you access the elementcoordinates, you get another dictionary back, and inside this dictionary is another keycoordinatesthat contains the actual list of coordinates (similarly, if you wanted thetype, you could sayprint doc['coordinates']['point']).Assuming they are in
lat, longformat, you could do something like this to pull them into their own variables (this may not suit your case, so feel free to disregard 🙂 ):