Skip to content

JanCaha/cpp-viewshed-library

Repository files navigation

Viewshed is a Cpp library to calculate Viewshed and extract LoS on Digital Surface Models

Library using GDAL, QT API and C++20 features to calculate visibility (viewshed), inverse visibility and additional information about it. The library is developed and tested on Linux.

Status

Tests for Library

Using the library

The core of the functionality is in the library itself that can be used directly from C++, however the project defines also couple of binaries to simply use of tool.

Binaries

There are two command line utilies: viewshed and inverseviewshed.

Usage: viewshed [options]
Viewshed.

Options:
  -h, --help                          Displays help on commandline options.
  --help-all                          Displays help including Qt specific
                                      options.
  -v, --version                       Displays version information.
  --dem < >                           Raster file representing DEM for viewshed
                                      calculation.
  --resultsFolder < >                 Output folder to store the results in.
  --observerPosition < >              Observer position in for XXX.XX;YY.YYY .
  --heightObserver < >                Height of the observer.
  --useCurvatureCorrections <true>    Use curvature corrections?
  --refractionCoefficient <0.142860>  Refraction coefficient.
  --earthDiameter <12740000>          Earth diameter.
  --visibilityMask < >                Raster file representing visibility mask,
                                      specifying areas to calculate visibility
                                      in, for viewshed calculation.  
Usage: inverseviewshed [options]
InverseViewshed.

Options:
  -h, --help                          Displays help on commandline options.
  --help-all                          Displays help including Qt specific
                                      options.
  -v, --version                       Displays version information.
  --dem < >                           Raster file representing DEM for viewshed
                                      calculation.
  --resultsFolder < >                 Output folder to store the results in.
  --targetPosition < >                Target position in for XXX.XX;YY.YYY .
  --heightObserver < >                Height of the observer.
  --heightTarget <0>                  Height of the target.
  --useCurvatureCorrections <true>    Use curvature corrections?
  --refractionCoefficient <0.142860>  Refraction coefficient.
  --earthDiameter <12740000>          Earth diameter.
  --visibilityMask < >                Raster file representing visibility mask,
                                      specifying areas to calculate visibility
                                      in, for viewshed calculation.

Besides that there are two binaries with GUI: viewshedcalculator and losextractor. That allow calculation of viewshed (and also inversviewshed) and its characteristics, and extraction of line-of-sight in form of CSV file.

Viewshed Calculator GUI

LoS Extractor GUI

Install from custom Conda channel

The library is available in the custom Conda channel:

https://jancaha.github.io/conda-channel/

You can install it with:

conda install -c https://jancaha.github.io/conda-channel -c conda-forge libviewshed

Or create a dedicated environment from the provided YAML file:

name: viewshed

channels:
  - https://jancaha.github.io/conda-channel
  - conda-forge

dependencies:
  - libviewshed
  - viewshed # python bindings for library

Use this command to build environment:

conda env create -f environment.yml
conda activate viewshed

Citation

If you use the library, please cite it accordingly:

@Software{CahaViewshed,
  author  = {Jan Caha},
  title   = {viewshed ({C++ Viewshed library based on GDAL and Qt})},
  year    = {2026}
  date    = {2026-05-11}
  version = {5.1.0}
  url     = {https://github.com/JanCaha/cpp-viewshed-library},
}

Development

Setup precommits

sudo apt-get install pre-commit
pre-commit install -f

About

Cpp Library to calculate Viewshed based on GDAL with comamnd line and GUI tools using Qt5.

Topics

Resources

License

Stars

Watchers

Forks

Contributors