Get a Network shapefile

📘

Check the API docs

https://renewmap.readme.io/reference/get-network-details-shpfile

✅

You will need an API key to get started.

Check the Getting Started page for instructions.

Save and run this script in any Python environment to get the latest RenewMap Projects data as an Esri shapefile.

  1. Save the script below as a Python file, eg get_renewmap_network_shp.py
  2. Run the script in ArcGIS Pro:
    1. Open your project
    2. Open a Python window (Alt + Shift + p)
    3. Paste and run the script
    4. A zipped folder containing the shapefile will save in your project working directory
  3. Alternatively, you can run the script in your favourite IDE, such as VSCode, or in a PowerShell or Bash terminal.
  4. Re-run the script to get the latest data.
"""
Updated: 10/06/2025
Author: [email protected]

This script fetches network data as a shapefile from the RenewMap Network API
and saves it to disk.
"""

import requests, zipfile, io
from typing import Dict
import os

API_KEY = "YOUR_API_KEY" # Replace with your actual API key
BASE_URL = "https://api.renewmap.com.au/api/v1/files/esri/shp/network.zip"
SAVE_PATH = "network"  # Directory to extract to

headers = {
    "Authorization": f"Bearer {API_KEY}"
}

class APIConfig:
    """Configuration class for API parameters.

    Attributes:
        base_url: Base URL for the API endpoint
        headers: HTTP headers for API requests
    """
    base_url: str = BASE_URL
    headers: Dict = headers
    save_path: str = SAVE_PATH

    def get_url(self):
        return self.base_url

def fetch_shapefile(config: APIConfig) -> None:
    """Fetch shapefile data from API and save to disk.

    Args:
        config: APIConfig object containing API configuration

    """
    url = config.get_url()
    response = requests.get(url, headers=config.headers)

    print(f"Fetching: {url}")
    print(f"Status code: {response.status_code}")
    
    if response.status_code == 200:
        print("Data retrieved successfully")
        # Create directory if it doesn't exist
        os.makedirs(config.save_path, exist_ok=True)
        # Extract the zip file
        z = zipfile.ZipFile(io.BytesIO(response.content))
        z.extractall(config.save_path)
        print("Shapefile saved to:", config.save_path)
        
        # Check for .shp files and print their paths
        shp_files = [f for f in os.listdir(config.save_path) if f.endswith('.shp')]
        if shp_files:
            print("\nFound shapefiles:")
            for shp_file in shp_files:
                shp_path = os.path.join(config.save_path, shp_file)
                print(f"- {os.path.abspath(shp_path)}")
        else:
            print("Warning: No .shp files found in the extracted contents")
    else:
        print("Error:", response.status_code)

config = APIConfig()
fetch_shapefile(config)