osm-power-grid-map-analysis

December 22, 2025 ยท View on GitHub

This repository is used to build maps and graph analysis on OpenStreetMap (OSM) power grid data (power lines and substations). It has been created in the context of #MapYourGrid project, led by OpenEnergyTransition.

This repository contains 2 elements :

  • Three python scripts that 1) downloads data from OSM via Overpass for a given country ; 2) cleans and prepares it for building a graph ; 3) Builds and analyses a graph.
  • A QGIS project to render this data with 1) A map showing high-voltage network on OSM and recent contributions especially through the project #MapYourGrid ; 2) A map showing basic grid consistency.

See result examples for Nepal below.

Nepal high-voltage networkNepal progress map

Configure and run python scripts

  • Go to scripts directory
  • Optional : Set up and activate a Python Virtual Environment
  • Install the python dependancies listed in requirements.txt : pip install -r requirements.txt.
  • Set the desired two-letters COUNTRY_CODE in config.py
  • Set the desired BUFFER_DISTANCE (in meters) in config.py. This buffer is drawn auround substation to catch all power lines ending around. BUFFER_DISTANCE should be ideally 0, but in practise, we may need some tolerance.
  • Run the 3 step-scripts in the order. You can also run run_all_scripts.py to run all scripts at once and for several countries (configure the countries you want to process in the COUNTRY_LIST variable).

Using Podoma

You can extract data from Podoma instead of Overpass. You will need a Podoma instance for it.

Configure and export QGIS project

  • If it is not yet done, download and install QGIS : https://qgis.org/download/ (if you are not familiar with QGIS, choose the Long Term Release, it is supposed to be more stable, but in reality, it will probably not change anything).
  • Go to qgis directory and open the QGIS project file project_map_graph.qgz.
  • Then, you can choose between manual and automatized map production.

Manual map production

  • See #QGIStips below if needed.
  • Go to Project / Properties / Variable and set the country_name variable.
  • Import all produced files by the python scripts (by default in data folder) into QGIS except pre_graph_power_lines.gpkg which is not needed. #QGIStips
  • Copy/paste style from the existing layers, e.g. from Bolivia (BO), to the new layers with the same name. #QGIStips
  • In the layer selection, disable all layers that are not concerning the country you work on. Disable, do not remove them : Graph & Map layer groups must stay as they are used for building the map legend, and BO - Bolivia group is used as style reference.

The QGIS project may help to produce two map templates (see example for Nepal above).

  • For the high-voltage network map, you need to enable only the following layers :
    • pre_graph_power_nodes
    • osm_brut_power_tower_transition
    • osm_brut_power_line
    • osm_brut_country_shape
    • OpenStreetMap
  • For the grid connectivity map, you need to enable only the following layers :
    • post_graph_power_nodes
    • post_graph_power_lines
    • osm_brut_country_shape

Once the right layers are enable:

  • Go to menu Projects / Layout / Manual.
  • In the Elements list, choose the map legend associated to one of the two templates. Disable the other map legend.
  • Move and zoom/unzoom the map to the desired country with the Move Item Content button :
  • Export your map in the desired format the menu Layout / Export as image, PDF ... . Be careful to not export as vectorized format if OpenStreetMap background layer is enable.

Automatized map production

  • Go to Menu -> Plugins / Python Console.
  • In the new window, click on the 'show editor' button, then on 'open a script' button and choose automation-script.py file.
  • Configure the countries you want to process in the COUNTRY_LIST variable
  • The default template layout is QGIS_AUTOMATIZED_LAYOUT = "Automatized-Square" (see below example). You can change it to "Automatized" and set QGIS_EXPORT_HAS_LEGEND = True to have the same template as manual process.
  • Run the script.
  • Be aware that :
    • Once the script started, there is no way to stop it (Ctrl+C isn't working). Be patient until the end (or kill Qgis process), and do not use a too long country list.
    • the 3 python scripts previously presented must have been executed for the concerned countries (they are not called from QGIS).

Nepal high-voltage networkNepal progress map

QGIS tips for beginners

  • Be sure QGIS Layers panel is shown. It is usually shown on screen left. If not, find the menu panel option, and activate it.
  • To import layer into QGIS, either :
    • Drag and drop layer file into QGIS layer panel (if shown)
    • Menu Layer / Add Layer / Add vector layer (or control+shift+V), then source browse for your file
    • Find the layer from QGIS explorer panel (if shown)
  • To copy/paste a style between two layers :
    • In the layer panel, right-click on the reference style layer : choose Styles / Copy Style / All categories ;
    • right-click on the destination layer : choose Styles / Paste Style / All categories