This project contains sample Bash and Python scripts along with C++ CGAL executables which perform the following tasks:
- Download IGNF DSM and BDTOPO building footprint for a given IGNF building identifier
- Crop DSM using BDTOPO footprint (including an optional buffer)
- Transform DSM extract into a point cloud or a mesh supporting different options: normals calculation, walls and floor creation using BDTOPO, axis reordering, local reference coordinates
- Run different CGAL components in order to detect and reconstruct roof panels or building. Among them:
The following instructions have been tested on Ubuntu 22.04 and 20.04
First clone this project
git clone https://github.com/ignfab/building-roof-pipeline.git
sudo add-apt-repository ppa:ubuntugis/ppa
sudo apt-get update && sudo apt-get install python3-pip python3-venv python3-dev libgdal-dev gdal-bin gettext-base build-essential wget m4 xz-utils libssl-dev libtbb-dev libreadline-dev pkg-config liblapack-dev libgsl-dev gfortran libopenblas-dev libgsl-dev libcliquer-dev libopenmpi-dev
-
Enter the projet directory and create download and compilation scripts based on versions defined in
cpplibs_version.cfg
by using the following command:cd building-roof-pipeline/ bash patch_scripts.sh
This script copies scripts templates from
script_templates/
directory and replace version numbers usingenvsubst
available ingettext-base
package. -
Run the script responsible for downloading and compiling the C++ libraries needed for building CGAL components:
bash dl_and_build_cpplibs.sh -dc
See
bash dl_and_build_cpplibs.sh -h
for more information. The downloaded and compiled libraries are available in thecpplibs/
directory. -
Run the script responsible for building CGAL components:
bash build_cgal_components.sh
The CGAL executables are available in the
cmake-build/
directory
The prefered solution for running the Python scripts is to use virtualenv.
Create a virtual environment:
python3 -m venv venv/roof # create venv
source venv/roof/bin/activate # activate venv
With roof
virtual environment activated simply run
(roof) python3 -m pip install -r requirements.txt
Then install GDAL Python.
(roof) python3 -m pip install GDAL==$(gdal-config --version) --global-option=build_ext --global-option="-I/usr/include/gdal"
A simple Python pipeline script is provided. The following command will test import and transform of a DSM extract. Make sure the roof
virtual environment is activated.
(roof) python3 pipeline.py
Under the hood, pipeline.py
uses .ini
file to configure steps and variables. By default pipeline.py
uses the default.ini
file which only performs a sample DSM download and tranformation.
A sample full_pipeline.ini
file is provided which contains all the possible steps and variable for the pipeline
(roof) python3 pipeline.py --file full_pipeline.ini
See python3 pipeline.py --help
to get more information on how to use the pipeline.
The dsm_import.py
script uses GDAL/OGR Python bindings and shapely.
The dsm_transform.py
script uses numpy extensively to transform the downloaded DSM extract into a point cloud or a mesh including normals computation. The scripts uses the idea of sliding window implemented using numpy broadcasting to create faces and vertex normals efficiently.
The CGAL documentation provides all the necessary information to modify or add new behaviours to the .cpp
files in cgal_components/
.
DSM converted into point cloud with normals
DSM converted into mesh with normals
DSM converted into point cloud with normals + walls and floor from BDTOPO
CGAL region growing on converted DSM Mesh
CGAL Polygonal Surface Reconstruction using DSM converted into point cloud with walls and floor