Skip to content

Instantly share code, notes, and snippets.

@wiseman
Created April 7, 2026 23:46
Show Gist options
  • Select an option

  • Save wiseman/c9766665e0c6967bf421d302ff2f6b74 to your computer and use it in GitHub Desktop.

Select an option

Save wiseman/c9766665e0c6967bf421d302ff2f6b74 to your computer and use it in GitHub Desktop.
Downloads LAPD drone flight data
# /// script
# requires-python = ">=3.11"
# dependencies = [
# "requests",
# ]
# ///
"""Download LAPD drone flight data from ArcGIS feature service."""
import json
import requests
SERVICE_URL = (
"https://services7.arcgis.com/mnhQTdIYDA7UoY2l/arcgis/rest/services/"
"5e6750a5-1bc9-4fb6-a6cf-8693f4d603ff-production/FeatureServer/0/query"
)
BATCH_SIZE = 2000
OUTPUT_FILE = "lapd_drone_flights.geojson"
def fetch_batch(offset: int) -> dict:
params = {
"where": "1=1",
"outFields": "*",
"outSR": "4326",
"f": "geojson",
"resultOffset": offset,
"resultRecordCount": BATCH_SIZE,
}
resp = requests.get(SERVICE_URL, params=params, timeout=120)
resp.raise_for_status()
return resp.json()
def main():
all_features = []
offset = 0
while True:
print(f"Fetching records {offset}{offset + BATCH_SIZE - 1}...")
data = fetch_batch(offset)
features = data.get("features", [])
all_features.extend(features)
print(f" Got {len(features)} features (total: {len(all_features)})")
if len(features) < BATCH_SIZE:
break
offset += BATCH_SIZE
geojson = {
"type": "FeatureCollection",
"features": all_features,
}
with open(OUTPUT_FILE, "w") as f:
json.dump(geojson, f)
print(f"\nWrote {len(all_features)} features to {OUTPUT_FILE}")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment