Skip to content

Instantly share code, notes, and snippets.

@bertrandmartel
Last active June 11, 2020 10:55
Show Gist options
  • Save bertrandmartel/b295f3805f087cda6bd4eefb1869caf0 to your computer and use it in GitHub Desktop.
Save bertrandmartel/b295f3805f087cda6bd4eefb1869caf0 to your computer and use it in GitHub Desktop.
extract map data from Arcgis Rest service World_Topo_Map
import requests
params = {
"text": "",
"objectIds": "",
"time": "",
"geometry": "",
"geometryType": "esriGeometryEnvelope",
"inSR": "",
"spatialRel": "esriSpatialRelIntersects",
"relationParam": "",
"outFields": "*",
"returnGeometry": "true",
"returnTrueCurves": "false",
"maxAllowableOffset": "",
"geometryPrecision": "",
"outSR": "",
"returnIdsOnly": "false",
"returnCountOnly": "false",
"orderByFields": "",
"groupByFieldsForStatistics": "",
"outStatistics": "",
"returnZ": "false",
"returnM": "false",
"gdbVersion": "",
"returnDistinctValues": "false",
"resultOffset": "",
"resultRecordCount": "",
"queryByDistance": "",
"returnExtentsOnly": "false",
"datumTransformation": "",
"parameterValues": "",
"rangeValues": "",
"f": "pjson"
}
params["where"] = "1=1"
data = []
count = 1
finish = False
while finish == False:
print(f"[{count}] requesting...")
r = requests.get("https://services.arcgisonline.com/arcgis/rest/services/World_Topo_Map/MapServer/0/query", params = params)
entries = r.json()["features"]
if len(entries) < 100:
finish = True
else:
last_object_id = entries[-1]["attributes"]["OBJECTID"]
print(f"next object id : {last_object_id}")
params["where"] = f"OBJECTID > {last_object_id}"
data.extend(entries)
print(f"[{count}] received {len(entries)} items - total received : {len(data)}")
count +=1
print(f"TOTAL: {len(data)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment