import sys import json from urllib import request # Define query parameters for OpenStreetMap Overpass API query = """ { __export_roof_area__: "paris"; ("building" "roof"); union; out; totalways; }; out geom; """ url = f"https://overpass-api.de/interpreter?data=[out:{query}]&lang=json&zipped=true" # Execute GET request and retrieve JSON data response = request.urlopen(url) data = json.loads(response.read().decode('utf-8')) way = next((x for x in data["elements"] if x["type"] == "way"), None) total_area = 0.0 if way: nodes = [node['nodes'] for node in way["geometry"] if node["type"] == "Area"] for node in nodes: area = float(node["value"]) * 10**6 # Convert bytes to km^2 total_area += area print(f"Total roof area of buildings in Paris: {total_area}")