Automated analysis of coverage and visibility zones using QGIS and Python.
This repository provides a script-based solution for evaluating viewsheds (areas visible from high points), calculating coverage, and analyzing overlaps between them. It integrates with QGIS and uses raster-based elevation data.
./data
: Input and output data (DEM files, input CSV, output CSV)../src
: All Python scripts.viewshed.py
: Creates viewsheds from high points.area_analysis.py
: Computes coverage metrics and overlaps.utils.py
: General-purpose functions (I/O, normalization, display).
./viewsheds_geotiff
: Raw viewsheds generated by the tool../normalized
: Viewsheds after NaN removal../fusion
: Viewshed files resulting from fusion operations (OR/AND).main.py
: The main script to run the analysis.
- QGIS (https://www.qgis.org/en/site/forusers/alldownloads.html)
- Plugins:
- SRTM Downloader (for DEM files)
- HCMGIS (for base maps)
- EarthData account for DEM data: https://urs.earthdata.nasa.gov/users/new
- Install plugins: SRTM Downloader and HCMGIS.
- Set map to Google Maps:
HCMGIS > BaseMaps > Google Maps
. - Use SRTM Downloader:
- Either set canvas extent or input coordinates manually.
- Login to EarthData when prompted.
- Merge DEM tiles: Use "Merge" tool.
- Output format:
Int16
- Save as:
./data/dem_file.tif
- Output format:
- Reproject the DEM:
- Use "Warp (Reproject)" tool.
- Target CRS: UTM zone for your area (e.g., EPSG:32631)
- Save as:
./data/dem_file_projected.tif
- Open QGIS > Python Console > Show Editor
- Load
main.py
- Run the script using the "Play" button
- Reads a CSV of observation points (lat/lon, height, name).
- Generates a viewshed (visibility map) for each point.
- Reprojects to appropriate CRS.
- Applies a visual style (
.qml
). - Saves results as individual
.tif
files.
- Removes NaN values from
.tif
files (required for further analysis). - Output files are saved to
./normalized
.
- Logical fusion of viewsheds using OR or AND.
- Results saved to
./fusion
.
- Calculates:
- Area covered by a single viewshed
- Coverage ratio relative to the network
- Overlap between two viewsheds
- Final metrics are stored in
./data/output.csv
.
Paths are defined in main.py
:
VISILITY_ANALYSIS_PATH
: Root folder (./analysis_shape
)DATA_PATH
:./data
CSV_PATH
: Input file (pts_hauts_x.csv
)DEM_PROJECTED_PATH
:dem_file_projected.tif
VIEWSHEDS_PATH
,NORM_VIEWSHEDS_PATH
,FUSION_PATH
: Subdirectories for outputsOUTPUT_PATH
:./data/output.csv
(You can externalize paths into a config.py
file if needed.)
Python Standard Library:
os
,csv
,numpy
Image Processing:
PIL.Image
,PIL.TiffTags
- Prepare DEM using QGIS.
- Normalize all viewsheds using
normalize_create()
. - Generate KPIs using
covered_surface()
. - Output will be saved in
output.csv
.
- Viewshed generation uses QGIS native plugin
Visibility Analysis
. - Normalization is required because the default plugin outputs use NaN for no-data values.
- QGIS may misinterpret the scale of
.tif
files unless color ramps are explicitly set to binary.