Skip to content

Instantly share code, notes, and snippets.

@d-wasserman
Last active December 1, 2017 15:14
Show Gist options
  • Save d-wasserman/3d8cafab1ffaa377355a92561cc96cc6 to your computer and use it in GitHub Desktop.
Save d-wasserman/3d8cafab1ffaa377355a92561cc96cc6 to your computer and use it in GitHub Desktop.
This is a sample python example that makes a list of geojson loads encoded in utf-8 by making requests for image locations using the Mapillary V3 API.
import requests
import json
def request_mapillary_image_locations(bbox_list, client_id, max_request_count=10000000,
root="https://a.mapillary.com/v3/"):
"""Function will make a request for images locations using the Mapillary V3 API within a bbox. It returns a
list of geojson loads for use."""
return_lists = []
arc_print("Requesting first geojson payload from Mapillary using bbox: {0}...".format(str(bbox_list)))
bbox_string = str(bbox_list[0]) + str(",") + str(bbox_list[1]) + str(",") + str(bbox_list[2]) + str(",") + str(
bbox_list[3]) + str(",")
curl = root + "/images?" + "bbox=" + bbox_string + "&client_id=" + str(client_id)
r = requests.head(url=curl)
data_request = requests.get(curl)
geojson = data_request.content.decode('utf-8')
return_lists.append(geojson)
next_link = r.links["next"]["url"]
counter = 0
while next_link and counter<=max_request_count:
r = requests.head(url=next_link)
data_request = requests.get(next_link)
geojson = data_request.content.decode('utf-8')
return_lists.append(geojson)
arc_print("Making request {0}...".format(str(counter)))
counter += 1
try:
next_link = r.links["next"]["url"]
except:
next_link = None
return return_lists
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment