Compiling SAGA GIS

From gvSIG CE Wiki

Jump to: navigation, search

Note: Make sure to first complete all steps in Compiling the C/C++ support libraries before going through these instructions, as some of the support libraries will also be needed for SAGA GIS.

Note: These instructions have been prepared for SAGA GIS 2.1.x. The SAGA GIS support in SEXTANTE requires at least SAGA GIS 2.1.x.

This page details how to create a version of the SAGA GIS binaries without GUI support (and thus without any interactive modules), that has minimal dependencies on external libraries and can be bundled and shipped with gvSIG CE/SEXTANTE.

These instructions have been prepared under Linux, but everything has also been tested and verified on Windows and Mac OS X. If there are differences between operating systems, they will be mentioned explicitly.

Contents

wxWidgets

Note: These instructions are for building a version of wxWidgets with unicode support, which is meant to work with a unicode-enable SAGA GIS. Since version 2.1.x, SAGA requires support for unicode in wxWidgets.

This is the basic, cross-plattform C++ class library used by SAGA GIS. We will compile a minimal version with no GUI classes and minimal external dependencies, to run as a single library.

From the many downloads on the wxWidgets project page, choose "WxAll" from the Current Stable Release. You have to go to the SF.net Files section to find the correct version in the archive. At the time of writing, the correct link was this

Configuration:

 ./configure --prefix=$WORKSPACE/dist --disable-gui --enable-monolithic --with-libjpeg=no --with-libpng=no --with-regex=builtin --with-libtiff=no --with-zlib=builtin --with-odbc=builtin --with-expat=builtin --with-libmspack=no --with-sdl=no

This should give:

 Configured wxWidgets 2.9.4 for `i686-pc-linux-gnu'
 
   Which GUI toolkit should wxWidgets use?                 base only
   Should wxWidgets be compiled into single library?       yes
   Should wxWidgets be linked as a shared library?         yes
   Should wxWidgets support Unicode?                       yes (using wchar_t)
   What level of wxWidgets compatibility should be enabled?
                                        wxWidgets 2.6      no
                                        wxWidgets 2.8      yes
   Which libraries should wxWidgets use?
                                        STL                no
                                        jpeg               none
                                        png                none
                                        regex              builtin
                                        tiff               none
                                        zlib               builtin
                                        expat              builtin
                                        libmspack          no
                                        sdl                no

Build and install:

 make
 make install

JasPer

This library provides JPEG 2000 support for SAGA.

 ./configure --prefix=$WORKSPACE/dist --disable-libjpeg --disable-opengl --enable-static=no --enable-shared=yes
 make
 make install

SAGA

http://www.saga-gis.org

Note: Building SAGA as described here will only work with SAGA 2.1.x and up! Enabling unicode support is mandatory since SAGA 2.1.x.

Configure SAGA without GUI and ODBC, and make sure that it can find the wx-config script:

 ./configure PATH="$PATH:$WORKSPACE/dist/bin" LDFLAGS="$LDFLAGS -L$WORKSPACE/dist/lib" prefix=$WORKSPACE/dist --enable-unicode --disable-gui --disable-odbc --with-local=$WORKSPACE/dist

When building, we must make sure that $WORKSPACE/dist/bin is in the path, so that the configuration scripts for wxWidgets and GDAL can be found by the build system:

 PATH="$PATH:$WORKSPACE/dist/bin" make

You can now install the system:

 make install

Creating a distribution package

Since SAGA has been compiled with minimal dependencies, it's easy to package everything needed into one directory.

Let's assume we are packaging things for distribution with gvSIG and that you have set the variable GVSIG_DIST_DIR to point to the folder where you have the whole gvSIG binary files tree. The precise steps differ a little depending on the operating system you are on.

Linux

Make a directory "saga" inside your gvSIG distribution for the saga_cmd binary and API libraries, as well as the wxWidgets libraries, and another subdirectory "saga/modules" for the module libraries. Then copy the binaries into the appropriate directories:

 mkdir $GVSIG_DIST_DIR/saga  
 mkdir $GVSIG_DIST_DIR/saga/modules
 cp $WORKSPACE/dist/bin/saga_cmd $GVSIG_DIST_DIR/saga/
 cp -d $WORKSPACE/dist/lib/libsaga_api*.so $GVSIG_DIST_DIR/saga/
 cp -d $WORKSPACE/dist/lib/libwx_base*.s* $GVSIG_DIST_DIR/saga/
 cp -d $WORKSPACE/dist/lib/saga/lib*.so $GVSIG_DIST_DIR/saga/modules/

If needed: Copy the 3rd party support libraries into the libs tree of your gvSIG distribution. You may already have these installed (e.g. for GRASS support), in which case you don't need to install them again:

 cp -d $WORKSPACE/dist/lib/libexpat.s* $GVSIG_DIST_DIR/libs/
 cp -d $WORKSPACE/dist/lib/libgdal.s* $GVSIG_DIST_DIR/libs/
 cp -d $WORKSPACE/dist/lib/libjasper.s* $GVSIG_DIST_DIR/libs/
 cp -d $WORKSPACE/dist/lib/libpq.s* $GVSIG_DIST_DIR/libs/
 cp -d $WORKSPACE/dist/lib/libproj.s* $GVSIG_DIST_DIR/libs/
 cp -d $WORKSPACE/dist/lib/libsqlite3.s* $GVSIG_DIST_DIR/libs/

Mac OS X

TODO

Windows

TODO

Single folder distribution

Alternatively, you can put everything listed above into a single directory for a full self-contained version of SAGA (for purposes other than bundling it with gvSIG).

Running SAGA

After compilation and installation of the SAGA binaries is complete, you might wish to run SAGA to make sure that it works.

To run SAGA, first export the environment variable SAGA_MLB to point to the folder in which the SAGA module libraries (grid_analysis, io_gdal, etc.) are stored.

To make sure that the system picks up the correct support libraries (GDAL etc.), you must also set your system's dynamic library loading path correctory. The exact steps depend on the operating system your are on. Please proceed as described below for your OS.

When your are done, you should be able to query SAGA libraries and modules, and run the latter to process data:

 saga_cmd -h
 saga_cmd <library-name>
 saga_cmd <library-name> 0

... to get an introduction, a listing of the modules inside a library (for <library-name>, substitute the actual file name, as it appears on your operating system), and usage details for the first module of the library, respectively.

E.g. to import a GeoTIFF dataset to a SAGA grid file on a Linux system, do:

 ./saga_cmd libio_gdal 0 -GRIDS $HOME/import.sgrd -FILES $HOME/sample.tif

Further details can be found on the SAGA Wiki.

Linux

For an installation inside the gvSIG distribution folder:

 export SAGA_MLB="$GVSIG_DIST_DIR/saga"
 export LD_LIBRARY_PATH="$GVSIG_DIST_DIR/libs:$LD_LIBRARY_PATH"

On linux, the SAGA library names must be prefixed with the system's dynamic library prefix "lib", e.g. libio_gdal.

Mac OS X

TODO

Windows

TODO

TODO

  • Unfortunately, the Kriging module will not run in no-GUI mode, as its variogram part needs graphics. The code is in src/modules_geostatistics/geostatistics/geostatistics_kriging -- and would probably need factoring out the variogramming parts.
  • We also need to evaluate how important/desirable a Unicode version of wxWidgets/SAGA would be. There have been some mailing list comments that suggest major problems with Unicode strings in a number of SAGA modules. So this should only be pursued if there is a definitive advantage for integration with gvSIG.

SAGA GIS has the following additional dependencies:

  • projection modules > Proj4 [DONE]
  • GDAL import/export > GDAL [DONE]
  • Projection - GeoTRANS > GeoTRANS library (?)
  • LAS import/export > libLAS
  • PDF export > libHaru
  • image analysis > OpenCV / Vigra

However, the official SAGA binaries only ship with wxWidget, GDAL and libLAS DLLs, so the question is whether these are linked statically or included in the SAGA source code???

List of interactive modules that need to be excluded:

  • Grid - Analysis > Least Cost Path (interactive version)
  • Grid - Tools > Change Cell Values
  • Grid - Tools > Change Grid Values - Flood Fill
  • Grid - Tools > Cutting
  • Grid - Tools > Grid Value Request
  • Projection - Georeferencing > Create Reference Points
  • Projection - Georeferencing > Move Grid
  • Recreation - Fractals > Mandelbrot Set
  • Recreation - Fractals > Newton-Raphson
  • Recreation - Games > Mine Sweeper
  • Recreation - Games > Sudoku
  • Reports - HTML > Create Web Content
  • Shapes - Points > Select Points
  • Terrain Analysis - Hydrology > Downslope Area
  • Terrain Analysis - Hydrology > Flow Depth
  • Terrain Analysis - Hydrology > Flow Sinuosity
  • Terrain Analysis - Hydrology > Isochrones Constant Speed
  • Terrain Analysis - Hydrology > Isochrones Variable Speed
  • Terrain Analysis - Hydrology > Lake Flood (interactive version)
  • Terrain Analysis - Lighting, Visibility > Visibility (single point)
  • Terrain Analysis - Profiles > Flow Path Profile
  • Terrain Analysis - Profiles > Profile
  • Terrain Analysis - Profiles > Swath Profile

Note: For some of these modules, it may be easily possible to provide a non-interactive alternative (e.g. see the Lake Flood module, which provides both)! Note2: It is unclear whether these are really all interactive modules in SAGA. Maybe there are some which are not clearly marked [interactive].

Next steps

Go to Running gvSIG CE to learn where to place your binaries in the gvSIG CE program folder.

Previous steps

Go back to Compiling GRASS GIS.

Or go all the way back to Compiling the C/C++ support libraries.