### Get Raw Overpass XML Data Source: https://context7.com/mvexel/overpass-api-python-wrapper/llms.txt Fetches data in raw Overpass XML format. The result is a string, and its type is 'str'. ```python xml_result = api.get( 'node["amenity"="bench"](51.500,-0.130,51.510,-0.110)', responseformat="xml" ) print(type(xml_result)) # ``` -------------------------------- ### Initialize Overpass API Client Source: https://context7.com/mvexel/overpass-api-python-wrapper/llms.txt Creates an API client instance. Customize the endpoint URL, timeout, and debug settings as needed. ```python import overpass # Default client using the public Overpass API endpoint api = overpass.API() ``` ```python import overpass # Custom timeout (in seconds) and endpoint api = overpass.API( endpoint="https://overpass-api.de/api/interpreter", timeout=60, debug=False ) ``` -------------------------------- ### Execute Overpass QL Query with Error Handling Source: https://context7.com/mvexel/overpass-api-python-wrapper/llms.txt Demonstrates robust error handling for network timeouts, API errors, and malformed queries using try-except blocks for specific exceptions. ```python import overpass from overpass import MultipleRequestsError, ServerLoadError api = overpass.API(timeout=30) try: result = api.get( 'node["natural"="peak"]["ele"](46.0,6.0,47.5,8.5)', responseformat="geojson" ) peaks = result["features"] print(f"Found {len(peaks)} mountain peaks") for peak in peaks[:5]: name = peak["properties"].get("name", "Unnamed") ele = peak["properties"].get("ele", "?") print(f" {name}: {ele}m") except MultipleRequestsError: print("Too many simultaneous requests — slow down and retry.") except ServerLoadError: print("Overpass server is under heavy load — try again later.") except Exception as e: print(f"Unexpected error: {e}") ``` -------------------------------- ### api.get() with Error Handling Source: https://context7.com/mvexel/overpass-api-python-wrapper/llms.txt Demonstrates proper error handling for network timeouts, API errors, and malformed queries. ```APIDOC ## api.get() with Error Handling ### Description Demonstrates proper error handling for network timeouts, API errors, and malformed queries. ### Method `api.get(query, responseformat='json', timeout=None)` ### Parameters - **query** (string) - The Overpass QL query string. - **responseformat** (string) - The desired format of the response. Options: "geojson", "json", "xml". Defaults to "json". - **timeout** (integer) - Optional timeout in seconds for this specific request. ### Request Example ```python import overpass from overpass import MultipleRequestsError, ServerLoadError api = overpass.API(timeout=30) try: result = api.get( 'node["natural"="peak"]["ele"](46.0,6.0,47.5,8.5)', responseformat="geojson" ) peaks = result["features"] print(f"Found {len(peaks)} mountain peaks") for peak in peaks[:5]: name = peak["properties"].get("name", "Unnamed") ele = peak["properties"].get("ele", "?") print(f" {name}: {ele}m") except MultipleRequestsError: print("Too many simultaneous requests — slow down and retry.") except ServerLoadError: print("Overpass server is under heavy load — try again later.") except Exception as e: print(f"Unexpected error: {e}") ``` ### Error Handling - **MultipleRequestsError**: Raised when too many simultaneous requests are detected. - **ServerLoadError**: Raised when the Overpass server is under heavy load. - **Exception**: Catches any other unexpected errors during the request. ``` -------------------------------- ### API() — Initialize the Overpass API Client Source: https://context7.com/mvexel/overpass-api-python-wrapper/llms.txt Creates a client instance connected to the Overpass API endpoint. Accepts optional parameters to customize the endpoint URL, timeout, and response format. ```APIDOC ## API() ### Description Creates a client instance connected to the Overpass API endpoint. Accepts optional parameters to customize the endpoint URL, timeout, and response format. ### Method `API()` ### Parameters #### Optional Parameters - **endpoint** (string) - The URL of the Overpass API endpoint. - **timeout** (integer) - The timeout in seconds for API requests. - **debug** (boolean) - Enables or disables debug mode. ### Request Example ```python import overpass # Default client using the public Overpass API endpoint api = overpass.API() # Custom timeout (in seconds) and endpoint api = overpass.API( endpoint="https://overpass-api.de/api/interpreter", timeout=60, debug=False ) ``` ``` -------------------------------- ### Execute Overpass QL Query with Bounding Box Source: https://context7.com/mvexel/overpass-api-python-wrapper/llms.txt Sends an Overpass QL query to retrieve data within a specified bounding box. The result is returned as a GeoJSON-compatible Python dictionary. ```python import overpass api = overpass.API() # Query all restaurants within a bounding box (south, west, north, east) result = api.get( 'node["amenity"="restaurant"](48.8566,2.3522,48.8666,2.3622)', responseformat="geojson" ) # result is a GeoJSON FeatureCollection dict for feature in result["features"]: name = feature["properties"].get("name", "Unnamed") coords = feature["geometry"]["coordinates"] print(f"{name}: {coords}") # Output example: # Le Petit Bistro: [2.3541, 48.8601] # Café de Paris: [2.3589, 48.8612] ``` -------------------------------- ### api.get() — Execute an Overpass QL Query Source: https://context7.com/mvexel/overpass-api-python-wrapper/llms.txt Sends an Overpass QL query to the API and returns the result as a GeoJSON-compatible Python dictionary. This is the primary method for retrieving OpenStreetMap data. ```APIDOC ## api.get() ### Description Sends an Overpass QL query to the API and returns the result as a GeoJSON-compatible Python dictionary. This is the primary method for retrieving OpenStreetMap data. ### Method `api.get(query, responseformat='json', timeout=None)` ### Parameters #### Path Parameters - **query** (string) - The Overpass QL query string. #### Query Parameters - **responseformat** (string) - The desired format of the response. Options: "geojson", "json", "xml". Defaults to "json". - **timeout** (integer) - Optional timeout in seconds for this specific request, overriding the client's default timeout. ### Request Example ```python import overpass api = overpass.API() # Query all restaurants within a bounding box (south, west, north, east) result = api.get( 'node["amenity"="restaurant"](48.8566,2.3522,48.8666,2.3622)', responseformat="geojson" ) # result is a GeoJSON FeatureCollection dict for feature in result["features"]: name = feature["properties"].get("name", "Unnamed") coords = feature["geometry"]["coordinates"] print(f"{name}: {coords}") ``` ### Response #### Success Response (200) - **result** (dict) - A dictionary representing the query result, typically in GeoJSON format. #### Response Example ```json { "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": { "name": "Le Petit Bistro", "amenity": "restaurant" }, "geometry": { "type": "Point", "coordinates": [ 2.3541, 48.8601 ] } } ] } ``` ``` -------------------------------- ### Control Response Format with `responseformat` Source: https://context7.com/mvexel/overpass-api-python-wrapper/llms.txt Specifies the output format for API responses. Supported formats include 'geojson', 'json', and 'xml'. GeoJSON is recommended for geospatial tools. ```python import overpass api = overpass.API() # GeoJSON format (best for geospatial tools and mapping libraries) geojson_result = api.get( 'node["amenity"="bench"](51.500,-0.130,51.510,-0.110)', responseformat="geojson" ) # Raw JSON (Overpass JSON format, includes OSM metadata) json_result = api.get( 'node["amenity"="bench"](51.500,-0.130,51.510,-0.110)', responseformat="json" ) print(json_result["elements"][0]) ``` -------------------------------- ### api.get() with Ways and Relations Source: https://context7.com/mvexel/overpass-api-python-wrapper/llms.txt Retrieves OpenStreetMap ways (lines/polygons) and relations in addition to nodes, enabling queries for roads, buildings, and complex multi-part features. ```APIDOC ## api.get() with Ways and Relations ### Description Retrieves OpenStreetMap ways (lines/polygons) and relations in addition to nodes, enabling queries for roads, buildings, and complex multi-part features. ### Method `api.get(query, responseformat='json', timeout=None)` ### Parameters - **query** (string) - The Overpass QL query string targeting ways or relations. - **responseformat** (string) - The desired format of the response. Options: "geojson", "json", "xml". Defaults to "json". - **timeout** (integer) - Optional timeout in seconds for this specific request. ### Request Example ```python import overpass api = overpass.API() # Query all cycleways in a bounding box result = api.get( 'way["highway"="cycleway"](52.4900,13.3800,52.5100,13.4200)', responseformat="geojson" ) print(f"Found {len(result['features'])} cycleways") for feature in result["features"]: geom_type = feature["geometry"]["type"] name = feature["properties"].get("name", "Unnamed") print(f"{name} ({geom_type})") ``` ``` -------------------------------- ### api.get() with Area Queries Source: https://context7.com/mvexel/overpass-api-python-wrapper/llms.txt Supports querying features within a named geographic area using Overpass QL's `area` selector, useful for country- or city-wide queries. ```APIDOC ## api.get() with Area Queries ### Description Supports querying features within a named geographic area using Overpass QL's `area` selector, useful for country- or city-wide queries. ### Method `api.get(query, responseformat='json', timeout=None)` ### Parameters - **query** (string) - The Overpass QL query string including the `area` selector. - **responseformat** (string) - The desired format of the response. Options: "geojson", "json", "xml". Defaults to "json". - **timeout** (integer) - Optional timeout in seconds for this specific request. ### Request Example ```python import overpass api = overpass.API() # Find all hospitals in Berlin result = api.get( """ area["name"="Berlin"]["boundary"="administrative"]["admin_level"="4"]; node["amenity"="hospital"](area); """, responseformat="geojson" ) print(f"Found {len(result['features'])} hospitals in Berlin") for feature in result["features"]: print(feature["properties"].get("name", "Unnamed hospital")) ``` ``` -------------------------------- ### Query Non-Point Features (Ways and Relations) Source: https://context7.com/mvexel/overpass-api-python-wrapper/llms.txt Retrieves OpenStreetMap ways (lines/polygons) and relations in addition to nodes. This enables queries for roads, buildings, and complex multi-part features. ```python import overpass api = overpass.API() # Query all cycleways in a bounding box result = api.get( 'way["highway"="cycleway"](52.4900,13.3800,52.5100,13.4200)', responseformat="geojson" ) print(f"Found {len(result['features'])} cycleways") for feature in result["features"]: geom_type = feature["geometry"]["type"] name = feature["properties"].get("name", "Unnamed") print(f"{name} ({geom_type})") ``` -------------------------------- ### responseformat Parameter Source: https://context7.com/mvexel/overpass-api-python-wrapper/llms.txt Controls the format of the data returned by the API. Supported values include "geojson", "json", and "xml". ```APIDOC ## responseformat Parameter ### Description Controls the format of the data returned by the API. Supported values include "geojson", "json", and "xml". ### Method `api.get(query, responseformat='json', timeout=None)` ### Parameters - **responseformat** (string) - The desired format of the response. Options: "geojson", "json", "xml". Defaults to "json". ### Request Example ```python import overpass api = overpass.API() # GeoJSON format (best for geospatial tools and mapping libraries) geojson_result = api.get( 'node["amenity"="bench"](51.500,-0.130,51.510,-0.110)', responseformat="geojson" ) # Raw JSON (Overpass JSON format, includes OSM metadata) json_result = api.get( 'node["amenity"="bench"](51.500,-0.130,51.510,-0.110)', responseformat="json" ) print(json_result["elements"][0]) ``` ``` -------------------------------- ### Query Features within a Named Area Source: https://context7.com/mvexel/overpass-api-python-wrapper/llms.txt Supports querying features within a named geographic area using Overpass QL's `area` selector. This is useful for country- or city-wide queries. ```python import overpass api = overpass.API() # Find all hospitals in Berlin result = api.get( """ area["name"="Berlin"]["boundary"="administrative"]["admin_level"="4"]; node["amenity"="hospital"](area); """, responseformat="geojson" ) print(f"Found {len(result['features'])} hospitals in Berlin") for feature in result["features"]: print(feature["properties"].get("name", "Unnamed hospital")) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.