QGIS access to OTB applications

From OTBWiki
Jump to: navigation, search

This is a guide to installing, running and updating the OrfeoToolbox modules from within QGIS

The OrfeoToolbox applications are available in QGIS via a Python plugin, built on top of the "QGIS Processing Framework".

More extensive information on the "QGIS Processing Framework" plugin can be found here.

This plugin can also provide an interface to the SAGA modules inside Qgis.

Updating the XML descriptors

The OTB processing plugin is located in QGIS sources in:

python/plugins/processing/algs/otb

See maintenance/README with information to update to XML applications description files, then make a pull request to QGIS.

How to compile and use remote modules (or any OTB app) in QGIS

On Ubuntu

In a clean Ubuntu 14.04 ("trusty"), here are the steps to build OTB :

1) Edit the /etc/apt/sources.list and check that it contains :

deb http://archive.ubuntu.com/ubuntu trusty main universe
deb-src http://archive.ubuntu.com/ubuntu trusty main universe

2) Update/Upgrade/Install requiered packages

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install aptitude
sudo aptitude install make cmake-curses-gui build-essential git libtool automake libbz2-dev python-dev libjpeg-dev libboost1.55-dev zlib1g-dev libcurl4-gnutls-dev

3) Create a directory to install OTB in /work then clone repository

sudo mkdir /work
sudo chown $USER /work
mkdir /work/otb
cd /work/otb
mkdir installdir build
git clone https://git@git.orfeo-toolbox.org/git/otb.git OTB

4) Configure OTB superbuild, for example here without QT and without OPENCV

cd build
cmake /work/otb/OTB/SuperBuild -DCMAKE_INSTALL_PREFIX=/work/otb/installdir -DOTB_USE_OPENCV=OFF -DOTB_USE_QT4=OFF

5) build and install (you can use "make -j 8" if you have a 8xCpu !)

make

6) Don't forget to add /work/otb/installdir/bin/ in your PATH (export PATH=$PATH:/work/otb/installdir/bin) and add /work/otb/installdir/lib/ in /etc/ld.so.conf (then make a ldconfig to refresh)

7) Now, configure, build and install remotes modules (for example here with Mosaic) (you can use "make -j 8" if you have a 8xCpu)

cd /work/otb/build/OTB/build/
cmake /work/otb/OTB/ -DModule_Mosaic=ON
make
make install

8) Installed remote module can now be used !

otbcli_Mosaic


Now we want to use the new installed apps in QGis. In order to add any OTB app which is not in QGis (e.g. remote module app) you just have to add a .xml file in the /usr/share/qgis/python/plugins/processing/algs/otb/description/5.XXX/ folder (replace XXX by the version). Here are examples of .xml files for some remote modules :

  1. Mosaic
  2. GRM

Older versions

This section compiles information from older version (2012 and earlier).

Notes for Windows users

On windows platform, the necessary binaries (for both Qgis and OTB) are available within the OSGeo4W distribution : http://trac.osgeo.org/osgeo4w/

As such, the installation procedure is simple to get the OTB functionnalities within Qgis :

  • Via the standard "Setup" installer, install the packages called "otb-python" and "osgearth", and "qgis" or "qgis-dev"
  • Start Qgis
  • Make sure your HTTP proxy settings are defined within the Preferences>Options>Network, if you need them to access the web.
  • Start the Python plugin installer
  • In the "Options" tab, choose to show all extensions, even the experimental ones.
  • Install the "Processing Framework Manager" plugin
  • Install the "Orfeo Toolbox Module Interface" plugin. You can type "orfeo" in the search tab to quickly get access to the entry
  • Hit the Processing>Panel menu entry to make the module list appear
  • You can run each module by double-clicking on their name.

Notes for Debian/Ubuntu users

Due to an issue (bugs.debian.org/558733) in the GDAL package, a symbol clash happens when using OTB within QGis.

A workaround to the issue has been provided in GDAL sources, but is not available in the 1.8.1 release.


The recommended procedure is to build a recent version of GDAL sources, and then build both OTB and QGis against this same GDAL version.


Installing GDAL

Set up where the source and installation are

export GDAL_SRC=</path/to/gdal/checkout>
export GDAL_INSTALL=</path/to/gdal/installation/directory>

Create the parent dir for source checkout

mkdir -p $GDAL_SRC/..

Create the installation dir

mkdir -p $GDAL_INSTALL

Checkout GDAL sources

svn checkout https://svn.osgeo.org/gdal/trunk/gdal $GDAL_SRC

Change directoy

cd $GDAL_SRC

Configure

./configure --prefix=$GDAL_INSTALL \
  --with-libtiff=internal \
  --with-geotiff=internal \
  --with-rename-internal-libtiff-symbols=yes \
  --with-rename-internal-libgeotiff-symbols=yes

We noted that in some cases libgeotiff and libtiff are not installed so this configuration may generate a Gdal/geotiff conflict. make sure that you have those two libraries in usr/lib before configuration , if not you have to download and put there.


Build and install

make
make install

Installing QGis

For now on, we need to make sure this GDAL build will be selected by the QGis and OTB configuration process:

export PATH=$GDAL_INSTALL/bin:$PATH
export LD_LIBRARY_PATH=$GDAL_INSTALL/lib:$LD_LIBRARY_PATH

Set up directories for building QGis

export QGIS_SRC=</path/to/qgis/checkout>
export QGIS_BUILD=</path/to/qgis/build/directory>
export QGIS_INSTALL=</path/to/qgis/installation/directory>
mkdir -p $QGIS_BUILD
mkdir -p $QGIS_INSTALL

Configure

cd $QGIS_BUILD
cmake $QGIS_SRC \
     -DCMAKE_INSTALL_PREFIX:STRING=$QGIS_INSTALL \
     -DCMAKE_BUILD_TYPE:STRING=Debug

Build and install

make -j3
make install


Installing OTB

The OTB applications are not part of the latest release, so it is necessary to build recent sources of OTB.

The installation procedure is described in the OTB Software Guide, in the Building from sources section and in the FAQ.

Install necessary software to build OTB

sudo aptitude install mercurial cmake libc6-dev libgcc1 libstdc++6 libtiff4-dev libgeotiff-dev \
  libpng12-dev libx11-dev libgl1-mesa-dev libgl1-mesa-dri libglu1-mesa-dev \
  libgdal1-dev proj uuid-dev libfltk1.1-dev fluid libexpat1-dev \
  libcurl4-gnutls-dev automake autoconf libtool libopenthreads-dev \
  libboost-graph-dev libmapnik-dev swig

The gcc version available on Ubuntu Lucid has a bug. It can be worked around by installing gcc 4.5 from this ppa, as follows :

sudo apt-add-repository ppa:ubuntu-toolchain-r/test
sudo aptitude update
sudo aptitude install g++-4.5 gcc-4.5


Configure the source, build and install directory Be sure to also have the GDAL_* variable defined as above, and that your previous GDAL build is in your path

export OTB_SRC=</path/to/OTB/checkout>
export OTB_BUILD=</path/to/OTB/build/directory>
export OTB_INSTALL=</path/to/OTB/installation/directory>

Be sure the directories exists

mkdir -p $OTB_SRC
mkdir -p $OTB_BUILD

The sources can be obtained using the Mercurial source control software :

hg clone http://hg.orfeo-toolbox.org/OTB $OTB_SRC

Configure

cmake \
 -DCMAKE_CXX_COMPILER:FILEPATH=/usr/bin/g++-4.5
 -DCMAKE_C_COMPILER:FILEPATH=/usr/bin/gcc-4.5
 -DCMAKE_INSTALL_PREFIX:PATH=$OTB_INSTALL \
 -DGDAL_INCLUDE_DIR:PATH=$GDAL_INSTALL/include \
 -DBUILD_APPLICATIONS:BOOL=ON \
 -DWRAP_PYTHON:BOOL=ON \
 -DBUILD_TESTING:BOOL=OFF \
 -DBUILD_EXAMPLES:BOOL=OFF \
 -DOTB_USE_VISU_GUI:BOOL=OFF \
 -DOTB_USE_CURL:BOOL=ON \
 -DOTB_USE_PQXX:BOOL=OFF \
 -DOTB_USE_PATENTED:BOOL=OFF \
 -DOTB_USE_EXTERNAL_BOOST:BOOL=ON \
 -DOTB_USE_EXTERNAL_EXPAT:BOOL=ON \
 -DOTB_USE_EXTERNAL_FLTK:BOOL=ON \
 -DOTB_USE_MAPNIK:BOOL=OFF \
 $OTB_SRC
make
make install

Installing the plugins

  • Set up the necessary environment before starting Qgis
 export PATH=$GDAL_INSTALL/bin:$QGIS_INSTALL/bin:$PATH
 export LD_LIBRARY_PATH=$GDAL_INSTALL/lib:$QGIS_INSTALL/lib:$OTB_INSTALL/lib/otb
 export PYTHONPATH=$OTB_INSTALL/lib/otb/python:$PYTHONPATH
 export ITK_AUTOLOAD_PATH=$OTB_INSTALL/lib/otb/applications
  • Check that everything is configured properly
 python -c "import otbApplication;print otbApplication.Registry.GetAvailableApplications()"

This should return a list of module names

  • Start qgis :
 $QGIS_INSTALL/bin/qgis
  • Start the Python plugin installer
  • In the "Options" tab, choose to show all extensions, even the experimental ones.
  • Install the "Processing Framework Manager" plugin
  • Install the "Orfeo Toolbox Module Interface" plugin (TODO : it would be cool to search otb in the extensions and get this plugin (for now need to search for orfeo))
  • At that point you may need to restart Qgis
  • Hit the Processing>Panel menu entry to make the module list appear
  • You can run each module by double-clicking on their name.