HOW TO: Install latest geospatial & scientific software on Linux

Compiling and Installing

Why bother building software from source? Frequently, the latest and greatest scientific/geospatial software is not available in the standard package repositories (especially on server-oriented distributions, like CentOS). Third-party repositories may exist for some software, but these often conflict with each other and may still not be entirely up-to-date. Dependencies between standard and non-standard packages will often lead to conflicts that may be difficult or impossible to resolve without building some software from source. Building software from source also allows one to fine-tune the installation to one's needs and allows for packages to be installed on systems where one does not have administrator access.
This guide will describe how to build the latest releases and development versions of various geospatial/scientific software on Ubuntu 12.04 and CentOS 6.4. Ubuntu instructions should apply to Linux Mint and other Ubuntu/Debian derivatives with a few tweaks. Likewise, CentOS instructions should mostly work with RHEL, Fedora, and similar Linux distributions. In general, many of these instructions can be adapted to other operating systems as well.

Preliminaries

Basics

This guide has been tested to work on a clean install of Ubuntu 12.04 and CentOS 6.4. Make sure everything is up-to-date first (Ubuntu: sudo apt-get update && apt-get upgrade, CentOS: sudo yum update). To avoid conflicts it is typically best to first remove any existing packages before building new versions (e.g. before building the latest libLAS on Ubuntu, first remove the old package with sudo apt-get remove liblas-bin). This is not always possible or necessary (e.g. you can have GRASS 6.4 installed from packages alongside a built development version of GRASS 7), but it's good practice, especially if you're going to install new versions system-wide with make install.

Install Path

Here I will assume that everything is being built in this starting directory: /opt/source. You can dynamically change this install path to your needs in the field below (this page's instructions will be updated immediately to reflect the new path, for easier copy-pasting). For example, if building in the home directory, you can enter something like '/home/username/bin/src'.

Tip: In order to allow other users to access the same compiled software (without always doing a system-wide make install), a universal group can be created for all such users:

# create new group 'geo'
sudo groupadd geo
# add user1 and user2 to the 'geo' group
sudo usermod -a -G geo user1
sudo usermod -a -G geo user2
# log out and log back in to obtain new group access
# confirm group access
groups
cat /etc/group|grep -i geo
# create new directory for compiled software
sudo mkdir /opt/source
# change group ownership of directory
sudo chown -R :geo /opt/source
# give group read/write access to directory, with 'sticky' bit set (so that new directories/files retain group permissions).
sudo chmod u+rwx,g+rws /opt/source
    

Compiling with make

Compiling some large software with 'make' (e.g. GRASS and Point Cloud Library) can take a long time, even on a powerful computer. To speed up compilation, use the '-j' option with the number of CPU threads on the machine, plus one. For example:

# set the 'threads' variable to the computer's # of cpu threads+1
threads=`expr \`cat /proc/cpuinfo |grep -i 'core id'|wc -l\` \+ 1`
echo $threads
# then use 'make -j' option to compile all software (e.g. make -j9 on an 8-thread CPU)
make -j$threads
    
The output to the make can be very long, with possible error messages burried in the long output. You can save the output to text files for later parsing:

# save text output to 'out.txt' and error messages to 'err.txt'; run in the background
make -j$threads 1>out.txt 2>err.txt &
# or similarly, put all the output in one file
make -j$threads 1>out.txt 2>&1 &
# watch progress
tail -f out.txt
# see what will happen during 'make install', without installing:
make -n install
    
Check out.txt and err.txt for errors. Sometimes err.txt will show many non-critical warnings, most of which you can ignore. If you get no errors at the end of out.txt (should say something like 'No errors detected'), then you've compiled your software successfully. If you run into compilation problems, look at the list of parts that failed to compile at the end of the output. If some dependency file/library is missing, search for it with apt-file on Ubuntu and yum provides on CentOS -- see Tips). Then run make clean and/or make distclean in the source directory and re-run configure/cmake/make.

Compiling with cmake

When re-running cmake with new parameters, a full clean-up may require the removal of the build directory. For example, if building inside the initially empty directory 'cmake_build', remove it with rm -rf cmake_build, then re-create it with mkdir cmake_build, and re-run ccmake/cmake/make. Alternatively, a clean-up script like the following should remove most of the old ccmake/cmake/make build attempt:

### cmake_clean.sh
#!/bin/bash
make clean
rm cmake_install.cmake
rm CMakeCache.txt
rm -rf CMakeFiles
    

Setting environmental variables

After compiling a new piece of software, we need to tell the system where to find the new software libraries with the $LD_LIBRARY_PATH variable, where to find the binaries with the $PATH variable, and where to find the python modules with the $PYTHONPATH variable. One way to do this is to create a file of all variables one needs to export for custom compiled software. For example, we can create a file called /opt/source/scripts/export_paths.sh with paths similar to those shown:

### /opt/source/scripts/export_paths.sh

## proj
export LD_LIBRARY_PATH="/opt/source/proj-4.8.0/build/lib:$LD_LIBRARY_PATH"
export PATH="/opt/source/proj-4.8.0/build/bin:$PATH"

## libtiff
export LD_LIBRARY_PATH="/opt/source/tiff-4.0.3/build/lib:$LD_LIBRARY_PATH"
export PATH="/opt/source/tiff-4.0.3/build/bin:$PATH"

## geotiff
export LD_LIBRARY_PATH="/opt/source/libgeotiff-1.4.0/build/lib:$LD_LIBRARY_PATH"
export PATH="/opt/source/libgeotiff-1.4.0/build/bin:$PATH"

## geos
export LD_LIBRARY_PATH="/opt/source/geos-3.3.8/build/lib:$LD_LIBRARY_PATH"
export PATH="/opt/source/geos-3.3.8/build/bin:$PATH"

## gdal
export LD_LIBRARY_PATH="/opt/source/gdal-trunk/build/lib:$LD_LIBRARY_PATH"
export PATH="/opt/source/gdal-trunk/build/bin:$PATH"
export PATH="/opt/source/gdal-trunk/swig/python/scripts:$PATH"
export PYTHONPATH="$PYTHONPATH:/opt/source/gdal-trunk/build/lib/python2.7/site-packages"
    
Then run the script with:

# use 'source' keyword:
source /opt/source/scripts/export_paths.sh
# alternative method:
. /opt/source/scripts/export_paths.sh
# see the library paths
echo $LD_LIBRARY_PATH
# see the binary paths
echo $PATH
# see the python paths
echo $PYTHONPATH
# see the modules that python sees (local and global)
python -c 'import sys, pprint; pprint.pprint(sys.path)'
# see all global system libraries
ldconfig -p
    
Note that you need to use the source keyword, not just execute the script. The variables will remain in memory during the shell session, but the script will need to be re-run with each new shell/terminal session. The advantage of this is that system libraries can be kept separate from custom-installed ones, with no conflict. For example, you may have a packaged version of proj installed along with a custom compiled one. By default the packaged version's libraries are used by the system, unless the export_paths.sh script is run.
To make new paths for binaries and python modules permanently recognized, add them to ~/.profile for individual users, or for all users to a file in the /etc/profile.d directory. For example:

### /etc/profile.d/custom_exports.sh
export PATH="/opt/source/proj-4.8.0/build/bin:$PATH"
export PATH="/opt/source/tiff-4.0.3/build/bin:$PATH"
export PATH="/opt/source/libgeotiff-1.4.0/build/bin:$PATH"
export PATH="/opt/source/geos-3.3.8/build/bin:$PATH"
export PATH="/opt/source/gdal-trunk/build/bin:$PATH"
export PATH="/opt/source/gdal-trunk/swig/python/scripts:$PATH"
export PATH="/opt/source/proj-4.8.0/build/bin:$PATH"
export PYTHONPATH="$PYTHONPATH:/opt/source/gdal-trunk/build/lib/python2.7/site-packages"
    
You can also add the LD_LIBRARY_PATH exports to these profile files, but this will fail to work on some systems (fails on Ubuntu, but seems to work on CentOS). To make custom library paths recognized permanently for all system users, add the library paths to the file in the /etc/ld.so.conf.d directory. For example:

### /etc/ld.so.conf.d/mylibs.conf
/opt/source/proj-4.8.0/build/lib
/opt/source/tiff-4.0.3/build/lib
/opt/source/libgeotiff-1.4.0/build/lib
/opt/source/geos-3.3.8/build/lib
/opt/source/gdal-trunk/build/lib
    
Then refresh the shared libraries.

# refresh the shared libraries
sudo ldconfig
# check to make sure it installed
ldconfig -p |grep -i gdal
    
In addition, you may occasionally need to export the CPATH variable, pointing to the include directory of some custom software builds, in order for other software to find the include files (e.g. this is necessary for grass to find a local liblas install).

GDAL

GDAL/OGR is a powerful library and set of utilities for dealing with raster and vector data. It is used by many other geospatial projects (GRASS GIS, QGIS, etc).
Before building the latest development version of GDAL, it is recommended to first install custom builds of proj, tiff, geotiff, geos, libkml (use packaged version on Ubuntu), hdf4, hdf5, and netcdf (depending on which data formats you need support for). Make sure all the library/path environmental variables are set for these custom builds. That is, run: source /opt/source/scripts/export_paths.sh on the shell before compiling (see Preliminaries).
Alternatively, older packaged versions of these libraries can usually be used with the latest GDAL code as well. On Ubuntu, most of these packages are available in the default 12.04 install (see instructions below). On CentOS, most of the geospatial packages are not available by default, but may be installed through third-party repositories, like EPEL, ELGIS, RepoForge, etc. Also see the building instructions on the GDAL website.
GDAL also has internal versions of libtiff, geotiff, and jpeg libraries. These can also be used and are often recommended (i.e. they have some custom changes). However, some software, like PDAL requires an external version of geotiff to be compiled with GDAL, so this is the option we choose here.
First let's get the necessary dependencies.
On Ubuntu, the easiest way to pull in all of the necessary GDAL dependencies is to install the stock GDAL package (libgdal1-dev). Here we will split these packages up into what is necessary and what is optional.

### On Ubuntu

# basic dependencies (enough to build GDAL) 
sudo apt-get install subversion g++ libsqlite3-dev libxml2-dev python-dev python-numpy swig libexpat1-dev libcurl4-gnutls-dev
# more dependencies (recommended)
sudo apt-get install libkml-dev libgif-dev libgif4 libjasper-dev libpng12-dev libfreexl1 libepsilon0
# optional dependencies (for maximum features)
sudo apt-get install  autotools-dev libdap-dev libdap11 libdapclient3 libdapserver7  libltdl-dev libmysqlclient-dev libmysqlclient18 libodbc1 libogdi3.2 libpq-dev libpq5 libspatialite-dev libspatialite3 libsqlite3-dev libtool libxerces-c2-dev libxerces-c28 mysql-common odbcinst odbcinst1debian2 unixodbc unixodbc-dev uuid-dev

# in addition, if not building proj, libtiff, geotiff, geos, hdf4/5,
# and/or netcdf from source, you can install the packaged versions below
# (generally building most of these from source is recommended)
# (for mpi support with hdf5, see the libhdf5-mpi-dev,
#  libhdf5-mpich-dev, and libhdf5-openmpi-dev packages)
# sudo apt-get install libproj0 proj proj-data proj-bin libtiff4-dev libgeotiff-dev libgeos-dev libhdf4-alt-dev libhdf5-serial-dev libnetcdf-dev
    

### On CentOS

# basic dependencies (enough to build GDAL) 
sudo yum install subversion gcc-c++ sqlite-devel libxml2-devel python-devel numpy swig expat-devel libcurl-devel
# more dependencies (optional)
sudo yum install xerces-c-devel unixODBC-devel
# additionally, if postgres database support is needed
sudo yum install postgresql postgresql-devel
    
Now let's get the source code.

# get the latest development version
cd /opt/source
svn checkout https://svn.osgeo.org/gdal/trunk/gdal gdal-trunk
cd gdal-trunk
mkdir build
# see configure options
./configure --help
    
Now let's set the compilation options. We compile without python bindings because we will install these manually later. This is to avoid the python modules from being installed system-wide, outside of the build directory (which will cause conflicts with any packaged versions of GDAL that may be installed on the system).

### On Ubuntu
./configure \
--prefix=/opt/source/gdal-trunk/build \
--with-jpeg=external \
--with-jpeg12 \
--without-libtool \
--without-python \
--with-libkml \
--with-static-proj4=/opt/source/proj-4.8.0/build \
--with-libtiff=/opt/source/tiff-4.0.3/build \
--with-geotiff=/opt/source/libgeotiff-1.4.0/build \
--with-geos=/opt/source/geos-3.3.8/build/bin/geos-config \
--with-hdf4=/opt/source/hdf-4.2.9/build \
--with-hdf5=/opt/source/hdf5-1.8.11/build \
--with-netcdf=/opt/source/netcdf-4.3.0/build \

## If using packaged versions of proj, tiff, geotiff, geos, hdf4/5, and/or netcdf
## replace the lines toward the end with something like:
## (gdal should find most paths automatically)
#  --with-libtiff --with-geotiff --with-geos --with-hdf4 --with-hdf5 --with-netcdf
    

### On CentOS
./configure \
--prefix=/opt/source/gdal-trunk/build \
--with-jpeg=external \
--with-jpeg12 \
--without-libtool \
--without-python \
--with-libkml=/opt/source/libkml-trunk/build \
--with-static-proj4=/opt/source/proj-4.8.0/build \
--with-libtiff=/opt/source/tiff-4.0.3/build \
--with-geotiff=/opt/source/libgeotiff-1.4.0/build \
--with-geos=/opt/source/geos-3.3.8/build/bin/geos-config \
--with-hdf4=/opt/source/hdf-4.2.9/build \
--with-hdf5=/opt/source/hdf5-1.8.11/build \
--with-netcdf=/opt/source/netcdf-4.3.0/build \
    
We are now ready to compile and install.

# optionally view configured options
nano GDALmake.opt
# compile
make -j$threads
# install into build dir
make install
    
Next, update the environmental variables for your new library and binary path.

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths
export LD_LIBRARY_PATH="/opt/source/gdal-trunk/build/lib:$LD_LIBRARY_PATH"
export PATH="/opt/source/gdal-trunk/build/bin:$PATH"
export PATH="/opt/source/gdal-trunk/swig/python/scripts:$PATH"
    
Now export the above variables and test out the new build.

# check gdal version
# (can also check built paths with --prefix --libs --dep-libs --datadir)
gdal-config --version
# check supported formats
gdal-config --formats
# see if ogr is enabled
gdal-config --ogr-enabled
# supported raster formats (check for tif, jpeg, png, hdf4/5, netcdf etc)
gdalinfo --formats
# supported vector formats (check for shapefile, kml, etc)
ogrinfo --formats
    
Finally, we should build the python modules as well (necessary to use gdal scripts, like gdal_merge.py). First we need to create the path in which the python module will be installed and add it to the $PYTHONPATH variable.

# on Ubuntu
mkdir -p /opt/source/gdal-trunk/build/lib/python2.7/site-packages
export PYTHONPATH="$PYTHONPATH:/opt/source/gdal-trunk/build/lib/python2.7/site-packages"

# on CentOS
mkdir -p /opt/source/gdal-trunk/build/lib64/python2.6/site-packages
export PYTHONPATH="$PYTHONPATH:/opt/source/gdal-trunk/build/lib64/python2.6/site-packages"
    
Now we can install the python module.

cd /opt/source/gdal-trunk/swig
make -j$threads
cd python
python setup.py install --prefix=/opt/source/gdal-trunk/build
    
Once you confirm in which 'site-packages' directory the python module got installed, add it to your stored list of environmental paths.

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths

### On Ubuntu (with python 2.7)
export PYTHONPATH="$PYTHONPATH:/opt/source/gdal-trunk/build/lib/python2.7/site-packages"

### On CentOS (with python 2.6)
export PYTHONPATH="$PYTHONPATH:/opt/source/gdal-trunk/build/lib64/python2.6/site-packages"
    
Now change to a new shell/terminal, re-export these variables and check the python module install.

# check python install (should see version and path to local python module)
python -c 'import osgeo.gdal; print osgeo.gdal.__version__; print osgeo.gdal.__file__'
# test to make sure python scripts are working
gdal_merge.py --version
    

GRASS GIS

GRASS GIS is arguably the most feature rich open source GIS available. The latest development version, GRASS 7, provides numerous enhancements, including lidar support. Compiling GRASS from source can get tricky. See the generic, as well as the Ubuntu-specific compiling instructions on the GRASS Wiki.
To get maximum functionality in GRASS we will assume you have built: gdal (and all its dependencies), laszip, and liblas (mostly in that order). In addition, on CentOS you will need to compile wxPython (not available in the stock packages). Make sure all the library/path environmental variables are set for these custom builds. That is, run: source /opt/source/scripts/export_paths.sh on the shell before compiling (see Preliminaries).
Alternatively, older packaged versions of these libraries can usually be used with the latest GRASS code as well. On Ubuntu, most of these packages are available in the default 12.04 install (see instructions below). On CentOS, most of the geospatial packages are not available by default, but may be installed through third-party repositories, like EPEL, ELGIS, RepoForge, etc.
Now let's grab the source code for GRASS 7, either from the development trunk or a slightly more stable SVN snapshot. I would recommend using the trunk version unless it fails to compile, in which case you can try an older snapshot version instead.

### On Ubuntu
# Install subversion
sudo apt-get install subversion
    

### On CentOS
# Install subversion
sudo yum install subversion
    

## Method 1: get the code from SVN trunk
cd /opt/source
svn checkout https://svn.osgeo.org/grass/grass/trunk grass-trunk
cd grass-trunk
# to update the repository (e.g. if you want to rebuild GRASS a few weeks later)
svn up
# clean up any old build attempts
make distclean
    

## Method 2: alternatively, get an SVN snapshot
# check http://grass.osgeo.org/grass70/source/snapshot for the latest snapshot filename
cd /opt/source
wget http://grass.osgeo.org/grass70/source/snapshot/grass-7.0.svn_src_snapshot_2013_06_01.tar.gz
tar xvfz grass-7.0.svn_src_snapshot_2013_06_01.tar.gz
cd grass-7.0.svn_src_snapshot_2013_06_01
    
Next we need to install a long list of dependencies. Not all of these are necessary for a leaner install (e.g. for a server install you may not need or want opengl/nviz visualization support), but this will allow for the most compilation options.

### On Ubuntu
sudo apt-get install flex bison fftw-dev proj python-wxgtk2.8 tcl8.5-dev tk8.5-dev libcairo2-dev libglu1-mesa-dev libblas-dev liblapack-dev libreadline-dev libwxbase2.8-dev libxmu-headers libxmu-dev python-numpy libwxgtk2.8-dev
    

### On CentOS
sudo yum install flex bison fftw-devel tcl-devel tk-devel cairo-devel blas-devel lapack-devel readline-devel libXmu-devel numpy wxGTK-devel mesa-libGLU-devel wxBase sqlite-devel python-dateutil
    
Optionally, you may want to install postgres database support, in which case you'll need a few more dependencies.

### On Ubuntu
# optional postgres install
sudo apt-get install postgresql libpq-dev
    

### On CentOS
# optional postgres install
sudo yum install postgresql postgresql-devel
    
In addition, if you are not compiling proj, tiff, geotiff, geos, gdal, and/or liblas from source, you can use the stock packages available in Ubuntu (most of these are not available on CentOS).

### On Ubuntu
# stock packages of proj, tiff, geotiff, geos, netcdf, gdal, and liblas
# (generally building most of these from source is recommended)
# sudo apt-get install proj proj-bin proj-data libproj-dev libtiff4-dev libgeotiff-dev libgeos-dev libnetcdf-dev netcdf-bin libgdal1-dev gdal-bin python-gdal libgdal1-1.7.0 liblas-dev
    
Now we run configure in the GRASS source directory. Here we enable GRASS with the maximum options available; you may choose to omit some of these. To avoid installing nviz use --without-opengl; to avoid postgres support, remove the --with-postgres* options at the end. The only key feature we are omitting is ffmpeg support. This is only important for nviz animations and is not such a critical feature. Presently, installing ffmpeg support in GRASS 7 is really difficult (it seems that GRASS 7 uses very old ffmpeg libraries and compiling with new dependencies gives errors).

### On Ubuntu
mkdir build
CFLAGS="-g -Wall" ./configure \
  --prefix=/opt/source/grass-trunk/build \
  --with-sqlite --with-lapack --with-readline --with-openmp \
  --with-opengl --with-blas --with-wxwidgets \
  --without-ffmpeg \
  --with-tcltk-includes=/usr/include/tcl8.5 \
  --with-freetype-includes=/usr/include/freetype2/ \
  --with-postgres --with-postgres-includes=/usr/include/postgresql \
  --with-proj-share=/opt/source/proj-4.8.0/build/share/proj \
  --with-proj-includes=/opt/source/proj-4.8.0/build/include \
  --with-proj-libs=/opt/source/proj-4.8.0/build/lib \
  --with-tiff-includes=/opt/source/tiff-4.0.3/build/include \
  --with-tiff-libs=/opt/source/tiff-4.0.3/build/lib \
  --with-geos=/opt/source/geos-3.3.8/build/bin/geos-config \
  --with-netcdf=/opt/source/netcdf-4.3.0/build/bin/nc-config \
  --with-gdal=/opt/source/gdal-trunk/build/bin/gdal-config \
  --with-liblas=/opt/source/libLAS-1.7.0/cmake_build/apps/liblas-config

## If using packaged versions of proj, tiff/geotiff, geos, netcdf, and gdal
## replace the lines toward the end with something like:
## (grass should find most paths automatically)
#  --with-proj-share=/usr/share/proj --with-tiff --with-geos --with-netcdf --with-gdal
    

### On CentOS
mkdir build
CFLAGS="-g -Wall" ./configure \
  --prefix=/opt/source/grass-trunk/build \
  --with-sqlite --with-lapack --with-readline --with-openmp \
  --with-opengl --with-blas --with-wxwidgets \
  --without-ffmpeg \
  --with-tcltk-includes=/usr/include \
  --with-freetype-includes=/usr/include/freetype2 \
  --with-postgres --with-postgres-includes=/usr/include/pgsql/server \
  --with-proj-share=/opt/source/proj-4.8.0/build/share/proj \
  --with-proj-includes=/opt/source/proj-4.8.0/build/include \
  --with-proj-libs=/opt/source/proj-4.8.0/build/lib \
  --with-tiff-includes=/opt/source/tiff-4.0.3/build/include \
  --with-tiff-libs=/opt/source/tiff-4.0.3/build/lib \
  --with-geos=/opt/source/geos-3.3.8/build/bin/geos-config \
  --with-netcdf=/opt/source/netcdf-4.3.0/build/bin/nc-config \
  --with-gdal=/opt/source/gdal-trunk/build/bin/gdal-config \
  --with-liblas=/opt/source/libLAS-1.7.0/cmake_build/apps/liblas-config
    
We are now ready to compile:

### On Ubuntu
# If using a custom built proj for your grass install,
# first remove any existing libproj-dev package
# (otherwise the packaged proj libraries will interfere with the compilation)
# you can re-install this package (and any related dependencies)
# after the grass make compilation finishes

# remove any installed proj development package
sudo apt-get remove libproj-dev proj
# compile and save output to text files; watch progress in out.txt
make -j$threads 1>out.txt 2>err.txt &
tail -f out.txt
# replace  proj development package
sudo apt-get install libproj-dev proj
    

### On CentOS
# compile and save output to text files; watch progress in out.txt
make -j$threads 1>out.txt 2>err.txt &
tail -f out.txt
    
Check the output for errors (err.txt may show many non-critical warnings most of which you can ignore). If you get no errors at the end of out.txt (should say 'No errors detected'), then you've built GRASS successfully! If you run into compilation problems, look at the list of parts that failed to compile at the end of the output. Change to that directory and run make again. Look at the output and see if some dependency file/library is missing (you can then search for it with apt-file on Ubuntu and yum provides on CentOS -- see Tips). Then run make distclean in the source GRASS directory and re-run configure and make.
Finally, install GRASS into build directory:

make install
    
In order to use GRASS, we will need to set a few environmental variables. Create a file to store your GRASS environmental variables (similar to export_paths.sh).

### grass environmental variables (see Preliminaries)
### create: /opt/source/scripts/export_grass_paths.sh
### then run: 'source export_grass_paths.sh' to update the environment paths
export GISBASE="/opt/source/grass-trunk/build/grass-7.0.svn"
export PYTHONPATH="$PYTHONPATH:/opt/source/grass-trunk/build/grass-7.0.svn/etc/python/"
export LD_LIBRARY_PATH="$GISBASE/lib:$LD_LIBRARY_PATH"
export GRASS_LD_LIBRARY_PATH="$GISBASE/lib"
export PATH="$GISBASE/bin:$GISBASE/scripts:$PATH"
export PATH="/opt/source/grass-trunk/build/bin:$PATH"
export GIS_LOCK=$$; export GISRC="$HOME/.grass7/rc"
    
Change to a new shell/terminal and re-export these new paths. You should now be able to start GRASS.

# check python install (should see path to loaded local python module)
python -c 'import grass.script as grass; print grass.__file__'
# check grass build parameters
grass70 --config
# start grass
grass70
    

GRASS add-on: r.surf.nnbathy

An optional add-on module for GRASS GIS, r.surf.nnbathy, allows for interpolating rasters with triangulation and natural neighbor algorithms. It is useful for creating quick, reasonably accurate DEMs and making raster Delaunay TINs.
This module requires the Natural Neighbor Interpolation Library. Let's get a few dependencies in case they are not installed.

### On CentOS
sudo yum install gcc-c++ subversion
    

### On Ubuntu
sudo apt-get install g++ subversion
    
Now let's compile.

cd /opt/source
svn checkout https://nn-c.googlecode.com/svn/nn nn-c
cd nn-c
mkdir build
./configure --prefix=/opt/source/nn-c/build --exec-prefix=/opt/source/nn-c/build
make -j$threads
make install
# check install
./build/bin/nnbathy -v
    
Next, update the environmental variables for your new library and binary path.

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths
export LD_LIBRARY_PATH="/opt/source/nn-c/build/lib:$LD_LIBRARY_PATH"
export PATH="/opt/source/nn-c/build/bin:$PATH"
    
We can now get the r.surf.nnbathy module.

mkdir /opt/source/grass-addon
cd /opt/source/grass-addon
wget http://www.sieczka.org/prog/grass/r.surf.nnbathy
chmod +x r.surf.nnbathy
# create a link to the installed grass 7 directory where the other modules reside
ln -s /opt/source/grass-addon/r.surf.nnbathy /opt/source/grass-trunk/build/grass-7.0.svn/bin/r.surf.nnbathy
    
You should now be able to use the new module in GRASS and through python scripting.

# check in grass
grass70 -text
r.surf.nnbathy --help
    

libLAS

libLAS is a library and set of command-line tools for working with the lidar LAS format. It is also used by GRASS 7 to import LAS files.
It is recommended to first install custom builds of proj, tiff, geotiff, and gdal. Make sure all the library/path environmental variables are set for these custom builds. That is, run: source /opt/source/scripts/export_paths.sh on the shell before compiling (see Preliminaries).
Alternatively, older packaged versions of these libraries can usually be used with the latest libLAS code as well. On Ubuntu, most of these packages are available in the default 12.04 install (see instructions below). On CentOS, most of the geospatial packages are not available by default, but may be installed through third-party repositories, like EPEL, ELGIS, RepoForge, etc.
Before we compile libLAS, we will first need to install the laszip compression library. Also see the complete libLAS compilation instructions on their website.

Compile laszip

First let's install some basic dependencies:

### On Ubuntu
sudo apt-get install git cmake g++
# install graphical cmake gui
sudo apt-get install cmake-gui
# alternatively, install command-line cmake text interface 'ccmake'
sudo apt-get install cmake-curses-gui
    

### On CentOS
sudo yum install git cmake gcc-c++ make
# install cmake graphical gui (not required)
# sudo yum install cmake-gui
    
Next we can get the source code and compile laszip.

# get the latest released version
cd /opt/source
wget http://download.osgeo.org/laszip/laszip-2.1.0.tar.gz
tar xvfz laszip-2.1.0.tar.gz
cd laszip-2.1.0
mkdir build
mkdir cmake_build
cd cmake_build
# run cmake
cmake .. -DCMAKE_INSTALL_PREFIX=/opt/source/laszip-2.1.0/build
# compile
make -j$threads
# install into build dir
make install
    
Next, update the environmental variables for your new library and binary path.

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths
export LD_LIBRARY_PATH="/opt/source/laszip-2.1.0/build/lib:$LD_LIBRARY_PATH"
export PATH="/opt/source/laszip-2.1.0/build/bin:$PATH"
    
Let's test the install.

# test install (also run with --libs and --includes parameters to check stored paths)
laszip-config --version
# run another test utility
laszippertest
rm test.tmp zippertest.log
    

Compile liblas

If using custom builds of proj, tiff, geotiff, gdal, laszip, etc: make sure all the library/path environmental variables are set for these custom builds. That is, run: source /opt/source/scripts/export_paths.sh on the shell before compiling (see Preliminaries).
Let's get some more dependencies.

### On Ubuntu
sudo apt-get install libboost-dev libboost-program-options1.46-dev libboost-thread1.46-dev
    

### On CentOS
sudo yum install boost-devel boost-program-options boost-thread
    
In addition, if you are not compiling proj, tiff, geotiff, and/or gdal from source, you can use the stock packages available in Ubuntu (most of these are not available on CentOS).

### On Ubuntu
# stock packages of proj, tiff, geotiff, and gdal
# generally building most of these from source is recommended
# sudo apt-get install proj proj-bin proj-data libproj-dev libtiff4-dev libgeotiff-dev libgdal1-dev gdal-bin python-gdal libgdal1-1.7.0
    
Next, let's get the code.

# get latest release
cd /opt/source
wget http://download.osgeo.org/liblas/libLAS-1.7.0.tar.gz
tar xvfz libLAS-1.7.0.tar.gz
cd libLAS-1.7.0
mkdir build
mkdir cmake_build
cd cmake_build
    
Next we need to set up some compile options.

cmake -G "Unix Makefiles" .. -DCMAKE_INSTALL_PREFIX=/opt/source/libLAS-1.7.0/build
# run ccmake (or use cmake-gui in graphical environment)
ccmake .. \
  -DCMAKE_INSTALL_PREFIX=/opt/source/libLAS-1.7.0/build \
  -DTIFF_INCLUDE_DIR=/opt/source/tiff-4.0.3/build/include \
  -DTIFF_LIBRARY=/opt/source/tiff-4.0.3/build/lib/libtiff.so \
  -DGEOTIFF_INCLUDE_DIR=/opt/source/libgeotiff-1.4.0/build/include \
  -DGEOTIFF_LIBRARY=/opt/source/libgeotiff-1.4.0/build/lib/libgeotiff.so \
  -DGDAL_CONFIG=/opt/source/gdal-trunk/build/bin/gdal-config \
  -DGDAL_INCLUDE_DIR=/opt/source/gdal-trunk/build/include \
  -DGDAL_LIBRARY=/opt/source/gdal-trunk/build/lib/libgdal.so \
  -DLASZIP_INCLUDE_DIR=/opt/source/laszip-2.1.0/build/include \
  -DLASZIP_LIBRARY=/opt/source/laszip-2.1.0/build/lib/liblaszip.so
    
In ccmake/cmake-gui:
  • Enable all of the 'WITH_' options except WITH_ENDIANWARE.
  • Run 'Configure' to make new some options show up.
  • Make sure all the GDAL, GEOTIFF, TIFF, and LASZIP paths are correctly set.
  • Run 'Configure' again as needed.
  • Run 'Generate' and exit.
Now we are ready to compile.

make -j$threads
# install into build dir
make install
    
Next, update the environmental variables for your new library and binary path. The CPATH export is needed for grass 7 to find liblas include files (alternatively, create a symlink: sudo ln -s /opt/source/libLAS-1.7.0/build/include/liblas/ /usr/local/include/liblas)

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths
export LD_LIBRARY_PATH="/opt/source/libLAS-1.7.0/build/lib:$LD_LIBRARY_PATH"
export PATH="/opt/source/libLAS-1.7.0/build/bin:$PATH"
export CPATH="/opt/source/libLAS-1.7.0/build/include:$CPATH"
    
Let's test the install.

# confirm that liblas got installed with GeoTIFF/GDAL support
# output at top should say something like:
# libLAS 1.7.0 with GeoTIFF 1.4.0 GDAL 1.11dev LASzip 2.1.0
lasinfo
# another optional test
/opt/source/libLAS-1.7.0/cmake_build/bin/Release/liblas_test
    
Next, we should add python support for libLAS scripting.

cd /opt/source/libLAS-1.7.0/python 

# create directory for new python module and add to python module search path

### On Ubuntu (with python 2.7)
mkdir -p /opt/source/libLAS-1.7.0/build/lib/python2.7/site-packages
export PYTHONPATH="$PYTHONPATH:/opt/source/libLAS-1.7.0/build/lib/python2.7/site-packages"

### On CentOS (with python 2.6)
mkdir -p /opt/source/libLAS-1.7.0/build/lib/python2.6/site-packages
export PYTHONPATH="$PYTHONPATH:/opt/source/libLAS-1.7.0/build/lib/python2.6/site-packages"

# install python module
python setup.py install --prefix=/opt/source/libLAS-1.7.0/build
    
Once you confirm in which 'site-packages' directory the python module got installed, add it to your stored list of environmental paths.

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths

### On Ubuntu (with python 2.7)
export PYTHONPATH="$PYTHONPATH:/opt/source/libLAS-1.7.0/build/lib/python2.7/site-packages"

### On CentOS (with python 2.6)
export PYTHONPATH="$PYTHONPATH:/opt/source/libLAS-1.7.0/build/lib/python2.6/site-packages"
    
Now change to a new shell/terminal, re-export the new python environmental variables and check the module install.

# check python install (should see path to loaded local python module)
python -c 'import liblas; print liblas.__file__'
    
One last thing -- we need to do a few more tweaks in order for GRASS 7 to compile.

## for grass 7 compilation with liblas
# make liblas-config executable
chmod +x /opt/source/libLAS-1.7.0/cmake_build/apps/liblas-config
# test (also run with --libs and --includes parameters to check stored paths)
/opt/source/libLAS-1.7.0/cmake_build/apps/liblas-config --version
    

PDAL

PDAL is a library for dealing with point cloud and lidar data. It is essentially a libLAS fork/rewrite. The project is under heavy development, and at the moment does not have as many end-user utilities as libLAS, but it promises to be the future of point cloud data handling.
To compile PDAL, first build the latest versions of cmake, proj, tiff, geotiff, and GDAL. A recent version of boost is also required, but it is probably best to use the embedded boost version that comes with the PDAL source code. Optionally, you can also build laszip, flann, and Points2Grid for additional functionality. Also see the list of dependencies and unix compiling instructions on the PDAL website.
First, let's get some dependencies (numpy is required for python bindings support).

### On Ubuntu
sudo apt-get install git libxml2-dev python-numpy

### On CentOS
sudo yum install git libxml2-devel numpy
    
Next, let's get the source code.

cd /opt/source
git clone https://github.com/PDAL/PDAL.git pdal-trunk
cd pdal-trunk
mkdir cmake_build
mkdir build
cd cmake_build
    
We are now ready to compile.

## run cmake
# - these options can also be set interactively inside ccmake
# - the laszip, p2g, and flann options at the end are optional

ccmake .. \
  -DCMAKE_INSTALL_PREFIX=/opt/source/pdal-trunk/build \
  -DWITH_LIBXML2=on \
  -DWITH_PYTHON=on \
  -DPDAL_EMBED_BOOST=on \
  -DWITH_GEOTIFF=on \
  -DGEOTIFF_INCLUDE_DIR=/opt/source/libgeotiff-1.4.0/build/include \
  -DGEOTIFF_LIBRARY=/opt/source/libgeotiff-1.4.0/build/lib/libgeotiff.so \
  -DTIFF_INCLUDE_DIR=/opt/source/tiff-4.0.3/build/include \
  -DTIFF_LIBRARY=/opt/source/tiff-4.0.3/build/lib/libtiff.so \
  -DWITH_GDAL=on \
  -DGDAL_CONFIG=/opt/source/gdal-trunk/build/bin/gdal-config \
  -DGDAL_INCLUDE_DIR=/opt/source/gdal-trunk/build/include \
  -DGDAL_LIBRARY=/opt/source/gdal-trunk/build/lib/libgdal.so \
  -DGEOS_CONFIG=/opt/source/geos-3.3.8/build/bin/geos-config \
  -DGEOS_INCLUDE_DIR=/opt/source/geos-3.3.8/build/include \
  -DGEOS_CONFIG_PREFER_PATH=/opt/source/geos-3.3.8/build/bin \
  -DWITH_LASZIP=on \
  -DLASZIP_INCLUDE_DIR=/opt/source/laszip-2.1.0/build/include \
  -DLASZIP_LIBRARY=/opt/source/laszip-2.1.0/build/lib/liblaszip.so \
  -DWITH_P2G=on \
  -DP2G_INCLUDE_DIR=/opt/source/p2g-trunk/build/include \
  -DP2G_LIBRARY=/opt/source/p2g-trunk/build/lib/libpts2grd.so \
  -DWITH_FLANN=on \
  -DFLANN_INCLUDE_DIR=/opt/source/flann-1.8.4-src/build/include \
  -DFLANN_LIBRARY=/opt/source/flann-1.8.4-src/build/lib/libflann.so \
  -DFLANN_LIBRARY_DEBUG=/opt/source/flann-1.8.4-src/build/lib/libflann.so \

## run 'configure'; optionally set 'ENABLE_CTEST' to on to generate tests
## check options/paths, run 'configure' as needed, then 'generate' and exit

# compile
make -j$threads
# optionally run a test (if enabled ctest option)
ctest .
# install into build dir
make install
    
Finally, update the environmental variables for your new library, binaries, and python path.

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths
export LD_LIBRARY_PATH="/opt/source/pdal-trunk/build/lib:$LD_LIBRARY_PATH"
export PATH="/opt/source/pdal-trunk/build/bin:$PATH"
export PYTHONPATH="$PYTHONPATH:/opt/source/pdal-trunk/python"
    
Now let's test our new build.

# should see pdal, geotiff, gdal, laszip versions in header
pcinfo --version
# test with sample lidar las file
pcinfo --stats -i /opt/source/pdal-trunk/test/data/simple.las
# check python install (should see path to loaded local python module)
python -c 'import pdal; print pdal.__file__'
    

SPDLib

SPDLib is a set of open source tools and libraries for processing lidar data. It is similar to PDAL/liblas/lastools, but offers the additional functionality of processing full waveform lidar data (in addition to discrete lidar returns). For more information on SPDLib's functionality, see the SPDLib start guide, tutorials, and manual.
Before compiling SPDLib, you will need to build the latest versions of cmake, boost, hdf5, gdal, liblas, and cgal. When compiling HDF5, be sure to use the --enable-cxx configure option, and not use the --enable-parallel option (no MPI support). Additionally, on CentOS, you will need to compile the latest version of xerces from source because the packaged version is not up-to-date (this is not necessary on Ubuntu). Also, see the SPDLib install instructions.
First let's install some basic dependencies.

### On Ubuntu
sudo apt-get install mercurial libgmp-dev libmpfr-dev libgsl0-dev python-numpy libxerces-c-dev

### On CentOS
sudo yum install mercurial gmp-devel mpfr-devel gsl-devel numpy
    
Next let's get the latest development source code (the newest code repository is on bitbucket, rather than sourceforge).

cd /opt/source
hg clone https://bitbucket.org/petebunting/spdlib spdlib-trunk
cd spdlib-trunk
mkdir build
    
Next we are ready to compile. We will run cmake in the root source directory (at the moment, spdlib doesn't seem to compile out-of-source with cmake). You can use the cmake_clean.sh script to clean up failed cmake build attempts.

### On Ubuntu

## run cmake
## note: the options can also be set interactively in ccmake/cmake-gui

ccmake . \
    -DCMAKE_INSTALL_PREFIX=/opt/source/spdlib-trunk/build \
    -DBOOST_ROOT=/opt/source/boost_1_53_0/build \
    -DBoost_NO_BOOST_CMAKE=TRUE \
    -DBOOST_INCLUDE_DIR=/opt/source/boost_1_53_0/build/include \
    -DBOOST_LIB_PATH=/opt/source/boost_1_53_0/build/lib \
    -DGDAL_INCLUDE_DIR=/opt/source/gdal-trunk/build/include \
    -DGDAL_LIBRARY=/opt/source/gdal-trunk/build/lib/libgdal.so \
    -DGDAL_CONFIG=/opt/source/gdal-trunk/build/bin/gdal-config \
    -DGDAL_LIB_PATH=/opt/source/gdal-trunk/build/lib \
    -DHDF5_INCLUDE_DIR=/opt/source/hdf5-1.8.11/build/include \
    -DHDF5_LIB_PATH=/opt/source/hdf5-1.8.11/build/lib \
    -DLIBLAS_INCLUDE_DIR=/opt/source/libLAS-1.7.0/build/include \
    -DLIBLAS_LIB_PATH=/opt/source/libLAS-1.7.0/build/lib \
    -DCGAL_LIB_PATH=/opt/source/CGAL-4.2/build/lib \
    -DCGAL_INCLUDE_DIR=/opt/source/CGAL-4.2/build/include \

# run 'configure', check all options (use advanced view to see all paths),
# then run 'configure' again as needed, 'generate' and exit.

# compile
make -j$threads
# install into build dir
make install
    

### On CentOS

## run cmake
## note: the options can also be set interactively in ccmake/cmake-gui

ccmake . \
    -DCMAKE_INSTALL_PREFIX=/opt/source/spdlib-trunk/build \
    -DBOOST_ROOT=/opt/source/boost_1_53_0/build \
    -DBoost_NO_BOOST_CMAKE=TRUE \
    -DBOOST_INCLUDE_DIR=/opt/source/boost_1_53_0/build/include \
    -DBOOST_LIB_PATH=/opt/source/boost_1_53_0/build/lib \
    -DGDAL_INCLUDE_DIR=/opt/source/gdal-trunk/build/include \
    -DGDAL_LIBRARY=/opt/source/gdal-trunk/build/lib/libgdal.so \
    -DGDAL_CONFIG=/opt/source/gdal-trunk/build/bin/gdal-config \
    -DGDAL_LIB_PATH=/opt/source/gdal-trunk/build/lib \
    -DHDF5_INCLUDE_DIR=/opt/source/hdf5-1.8.11/build/include \
    -DHDF5_LIB_PATH=/opt/source/hdf5-1.8.11/build/lib \
    -DLIBLAS_INCLUDE_DIR=/opt/source/libLAS-1.7.0/build/include \
    -DLIBLAS_LIB_PATH=/opt/source/libLAS-1.7.0/build/lib \
    -DCGAL_LIB_PATH=/opt/source/CGAL-4.2/build/lib \
    -DCGAL_INCLUDE_DIR=/opt/source/CGAL-4.2/build/include \
    -DXERCESC_LIB_PATH=/opt/source/xerces-c-3.1.1/build/lib \
    -DXERCESC_INCLUDE_DIR=/opt/source/xerces-c-3.1.1/build/include \

# run 'configure', check all options (use advanced view to see all paths),
# then run 'configure' again as needed, 'generate' and exit.

# compile
make -j$threads
# install into build dir
make install
    
Finally, update the environmental variables for your new library and binary path.

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths
export LD_LIBRARY_PATH="/opt/source/spdlib-trunk/build/lib:$LD_LIBRARY_PATH"
export PATH="/opt/source/spdlib-trunk/build/bin:$PATH"
    
Now we can test our new build.

# show spd version info
spd-config --version
spdversion

# create sample spd file from liblas test las file
mkdir /opt/source/spdlib-trunk/samples
cd /opt/source/spdlib-trunk/samples
spdtranslate --if LAS --of SPD -x LAST_RETURN -b 1 -i /opt/source/libLAS-1.7.0/test/data/autzen.las -o sample.spd
spdinfo sample.spd
# create sample raster
spdinterp -b 1 --dsm --topo -f GTiff -i sample.spd -o sample.tif
gdalinfo sample.tif
    
We can also install the spdlib python bindings. First we compile the old python bindings.

## build old python bindings
cd /opt/source/spdlib-trunk/python

ccmake . \
    -DBOOST_ROOT=/opt/source/boost_1_53_0/build \
    -DBoost_NO_BOOST_CMAKE=TRUE \
    -DGDAL_INCLUDE_DIR=/opt/source/gdal-trunk/build/include \
    -DGDAL_LIBRARY=/opt/source/gdal-trunk/build/lib/libgdal.so \
    -DGDAL_CONFIG=/opt/source/gdal-trunk/build/bin/gdal-config \
    -DHDF5_INCLUDE_DIR=/opt/source/hdf5-1.8.11/build/include \
    -DHDF5_LIB_PATH=/opt/source/hdf5-1.8.11/build/lib \
    -DSPDLIB_IO_INCLUDE_DIR=/opt/source/spdlib-trunk/build/include \
    -DSPDLIB_IO_LIB_PATH=/opt/source/spdlib-trunk/build/lib \

# you may also want to explicitly specify the python version
# to use, if multiple python versions are installed
# e.g. on Ubuntu, if python 3.2 and 2.7 are installed, use:
    -DPYTHON_INCLUDE_DIR=/usr/include/python2.7 \
    -DPYTHON_LIBRARY=/usr/lib/python2.7/config/libpython2.7.so \

# run 'configure', check all options (use advanced view to see all paths),
# then run 'configure' again as needed, 'generate' and exit.

make -j$threads
    
We also need to add the python module directory to the stored list of environmental paths.

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths

export PYTHONPATH="$PYTHONPATH:/opt/source/spdlib-trunk/python"
    
Now let's test the python bindings.

# first change directory to make sure the module is found on pythonpath
cd ..
# check python install (should see path to local python module)
python -c 'import spdpy; print spdpy.__file__'
    
We can also build the new version of the python bindings.

cd /opt/source/spdlib-trunk/ngpython
# make sure the spdlib python setup can find gdal include files
export CPATH="/opt/source/gdal-trunk/build/include:$CPATH"
# compile and install into build dir
python setup.py build
python setup.py install --prefix=/opt/source/spdlib-trunk/build
    
Once you confirm in which 'site-packages' directory the python module got installed, add it to your stored list of environmental paths.

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths

# On Ubuntu
export PYTHONPATH="$PYTHONPATH:/opt/source/spdlib-trunk/build/lib/python2.7/site-packages"

# On CentOS
export PYTHONPATH="$PYTHONPATH:/opt/source/spdlib-trunk/build/lib64/python2.6/site-packages"
    
Finally, let's test the new python bindings.

# check python install (should see path to local python module)
python -c 'import spdpy2; print spdpy2.__file__'

# run test python script with sample spd file generated above
# (should see some output and no errors)
cd /opt/source/spdlib-trunk/samples
python ../ngpython/test.py sample.spd
    

SPDLib Points Viewer

SPDLib Points Viewer is a GUI tool for visualizing SPD 3D point clouds, DTMs, vectors, and TINs. Before compiling the viewer, first build spdlib and all its dependencies as described above.
First let's get some dependencies.

### On Ubuntu
sudo apt-get install libxmu-dev libxi-dev freeglut3-dev libqt4-dev

### On CentOS
sudo yum install libXmu-devel libXi-devel freeglut-devel qt-devel
    
Now we can download and compile the viewer.

cd /opt/source
# download the latest development version
hg clone https://bitbucket.org/petebunting/spd-3d-points-viewer spdpointsviewer-trunk
cd spdpointsviewer-trunk

# run cmake in the source directory (out-of-source builds do not seem to work)
ccmake . \
    -DBOOST_ROOT=/opt/source/boost_1_53_0/build \
    -DBoost_NO_BOOST_CMAKE=TRUE \
    -DSPDLIB_IO_INCLUDE_DIR=/opt/source/spdlib-trunk/build/include \
    -DSPDLIB_IO_LIB_PATH=/opt/source/spdlib-trunk/build/lib \
    -DGDAL_INCLUDE_DIR=/opt/source/gdal-trunk/build/include \
    -DGDAL_LIBRARY=/opt/source/gdal-trunk/build/lib/libgdal.so \
    -DGDAL_CONFIG=/opt/source/gdal-trunk/build/bin/gdal-config \
    -DHDF5_INCLUDE_DIR=/opt/source/hdf5-1.8.11/build/include \
    -DHDF5_LIB_PATH=/opt/source/hdf5-1.8.11/build/lib \
    -DHDF5_hdf5_LIBRARY=/opt/source/hdf5-1.8.11/build/lib/libhdf5.so \
    -DHDF5_hdf5_LIBRARY_DEBUG=/opt/source/hdf5-1.8.11/build/lib/libhdf5.so \
    -DHDF5_hdf5_LIBRARY_RELEASE=/opt/source/hdf5-1.8.11/build/lib/libhdf5.so \

# run 'configure', check all options (use advanced view to see all paths),
# then run 'configure' again as needed, 'generate' and exit.

# compile
make -j$threads
# seems that no 'make install' available

# test new build
./SPDPointsViewer
    
Finally, update the environmental variables for your new binary path.

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths
export PATH="/opt/source/spdpointsviewer-trunk:$PATH"
    

LAStools

LAStools/LASlib is a collection of command-line/GUI utilites and a C++ library for dealing with lidar pointclouds. libLAS is a fork/rewrite/extension of lastools; each of the two sets of lidar libraries/utilities have their own strengths and benefits (see comparison).
Building LAStools is straightforward:

### On Ubuntu
sudo apt-get install g++
    

### On CentOS
sudo yum install make gcc-c++
    

# download and build
cd /opt/source
wget http://www.cs.unc.edu/~isenburg/lastools/download/lastools.zip
unzip lastools.zip
cd lastools
make -j$threads
    
The resulting binaries will be found in the 'bin' directory. It is recommended not to run 'make install' because most of lastools' executables have the same names as the liblas utilities. Thus I will avoid adding the bin directory to the PATH variable, to prevent conflicts with the liblas install.
This will build only a third of the available tools; the rest of the tools are provided under a restrictive license, only as Windows binary executables. Fortunately, Linux users can still run most of these utilities with Wine. (The GUIs of most lastools utilities do not always work well, but running them on the command line usually works fine.)

### On Ubuntu
sudo apt-get install wine
    
On CentOS, we will need to enable the Extra Packages for Enterprise Linux (EPEL) repository in order to obtain wine. This will cause third-party repositories to be pulled into the system, but this is much easier than building wine from source.

### On CentOS
# set up EPEL -- find the latest rpm link here:
# http://download.fedoraproject.org/pub/epel/6/i386/repoview/epel-release.html
sudo rpm -Uvh 'http://ftp.osuosl.org/pub/fedora-epel/6/i386/epel-release-6-8.noarch.rpm'
    
After this, you may also want to check that the main repository is enabled in /etc/yum.repos.d/epel.repo (should say enabled=1 under the first, base package).

### On CentOS
# (once EPEL repository is enabled)
sudo yum install wine
    
You can now run most of the *.exe files in the bin directory by adding the prefix 'wine' on the command-line.

cd bin
# example: create a concave boundary polygon shapefile around a pointcloud
wine lasboundary.exe mylas.las
# or, to avoid calling wine explicitly just make the windows binaries executable:
chmod +x *.exe
./lasboundary.exe mylas.las
    

LidarViewer

LidarViewer is an impressive pointcloud visualizer, which can render billions of points on a modern PC. Points can be color-coded by a specific attribute (class, intensity), or by RGB values taken from aerial photos. In addition, the viewer provides real-time hillshade rendering of pointclouds, providing DEM-like raw pointcloud viewing. It is arguably the best open source viewer for massive pointclouds (> ~100 million points).
Features available in the viewer are documented in the LidarViewer manual. Some features are not completely documented; browsing the LidarViewer source code can reveal the full command-line options available in the viewer.

Compile Vrui

Vrui is the visualization toolkit that LidarViewer requires to display 3D pointclouds. First let's install some dependencies (also see the full Vrui install instructions).

### On Ubuntu

# necessary dependencies
sudo apt-get install build-essential g++ zlib1g-dev libgl1-mesa-dev libglu1-mesa-dev 
# optional dependencies: imaging
# (recommended -- necessary for LidarViewer to drape images onto pointclouds)
sudo apt-get install libpng12-dev libtiff4-dev libjpeg-dev
# optional dependencies: video
# sudo apt-get install libtheora-dev libogg-dev
# optional dependencies: audio
# sudo apt-get install libspeex-dev libasound2-dev libopenal-dev
# optional dependencies: hardware interfacing (e.g. USB, firewire, bluetooth)
# sudo apt-get install libusb-1.0-0-dev  libdc1394-22-dev libbluetooth-dev 
    

### On CentOS

# necessary dependencies
sudo yum install gcc-c++ make zlib-devel mesa-libGL-devel mesa-libGLU-devel
# optional dependencies: imaging
# (recommended -- necessary for LidarViewer to drape images onto pointclouds)
sudo yum install libpng-devel libjpeg-devel libtiff-devel
# optional dependencies: video
sudo yum install libv4l-devel libogg-devel libtheora-devel
# optional dependencies: audio
sudo yum install alsa-lib-devel speex-devel
# optional dependencies: hardware interfacing (e.g. USB, firewire, bluetooth)
sudo yum install libdc1394-devel bluez-libs-devel libusb1-devel
    
Next, let's compile Vrui. By default Vrui will get installed in the home directory; here we install it in a more general location, so that it can be used by multiple users.

cd /opt/source
wget http://idav.ucdavis.edu/~okreylos/ResDev/Vrui/Vrui-2.7-001.tar.gz
tar xvfz Vrui-2.7-001.tar.gz
cd Vrui-2.7-001/
mkdir build
# compile Vrui and install into "build" directory
# (this changes the installation directory set in 'makefile')
make -j$threads INSTALLDIR=/opt/source/Vrui-2.7-001/build
make install INSTALLDIR=/opt/source/Vrui-2.7-001/build
# optional: compile example programs to check if install worked
cd ExamplePrograms
make -j$threads VRUI_MAKEDIR=/opt/source/Vrui-2.7-001/build/share/make
# run sample 3D program
./bin/ShowEarthModel
# also see Vrui documentation here:
firefox /opt/source/Vrui-2.7-001/build/share/doc/index.html
    
Finally, update the environmental variables for your new library and binary path.

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths
export LD_LIBRARY_PATH="/opt/source/Vrui-2.7-001/build/lib64:$LD_LIBRARY_PATH"
export PATH="/opt/source/Vrui-2.7-001/build/bin:$PATH"
    

Compile LidarViewer

We are now ready to build LidarViwer.

cd /opt/source
wget http://idav.ucdavis.edu/~okreylos/ResDev/LiDAR/LidarViewer-2.11.tar.gz
tar xvfz LidarViewer-2.11.tar.gz
cd LidarViewer-2.11
make -j$threads INSTALLDIR=/opt/source/LidarViewer-2.11/build \
                VRUI_MAKEDIR=/opt/source/Vrui-2.7-001/build/share/make
make install INSTALLDIR=/opt/source/LidarViewer-2.11/build \
             VRUI_MAKEDIR=/opt/source/Vrui-2.7-001/build/share/make
# check to see if install worked with example pointcloud
wget http://keckcaves.org/data/LidarViewerExamples.zip
unzip LidarViewerExamples.zip
./build/bin/LidarViewer LidarViewerExamples/PtArena.lidar
    
Finally, update the environmental variables for your new library and binary path.

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths
export PATH="/opt/source/LidarViewer-2.11/build/bin:$PATH"
    

CloudCompare (On Ubuntu)

CloudCompare is a 3D pointcloud viewer/editor. It works great for viewing smaller pointclouds (< ~100 million points).
Before compiling CloudCompare, it is best to build the latest versions of cmake and boost. Optionally, you can compile CloudCompare with liblas (and laszip) support as well (for viewing .las and .laz files), however this feature does not yet seem to be fully implemented. You can also compile CloudCompare with PCL and kinect support, but these plugins are still being developed. Also see the cmake compilation instructions on the CloudCompare website.
First, let's get the necessary dependencies:

### On Ubuntu
sudo apt-get install git libqt4-dev libqt4-core
    
Now let's get the latest source code.

cd /opt/source
git clone git://github.com/cloudcompare/trunk cc-trunk
cd cc-trunk
mkdir build
mkdir cmake_build
cd cmake_build
    
We are now ready to compile.

## run cmake
# note: liblas support is optional and not yet fully implemented

ccmake .. \
  -DCMAKE_INSTALL_PREFIX=/opt/source/cc-trunk/build \
  -DOPTION_BUILD_CCVIEWER=on \
  -DOPTION_USE_LIBLAS=ON \
  -DLIBLAS_INCLUDE_DIR=/opt/source/libLAS-1.7.0/build/include \
  -DLIBLAS_RELEASE_LIBRARY_FILE=/opt/source/libLAS-1.7.0/build/lib/liblas.so \
  -DBOOST_ROOT=/opt/source/boost_1_53_0/build \
  -DBoost_NO_BOOST_CMAKE=TRUE \

# run 'configure'; enable all the 'INSTALL_*' options except QKINECT and QPCL
# check options/paths; run 'configure' again as needed; run 'generate' and exit

# compile
make -j$threads
# install into build dir
make install
    
Finally, update the environmental variables for your new library and binary path.

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths
export LD_LIBRARY_PATH="/opt/source/cc-trunk/build/lib:$LD_LIBRARY_PATH"
export PATH="/opt/source/cc-trunk/build/bin:$PATH"
    
Test out the new build.

# run CloudCompare
CloudCompare
# run viewer
ccViewer
    

OpenSceneGraph (On Ubuntu)

OpenSceneGraph is a sophisticated 3D graphics library used by osgEarth and many other 3D visualization projects.
Here I provide instructions for building OpenSceneGraph on Ubuntu. We will do this by first installing the stock OpenSceneGraph packages. This will pull in related dependencies, which will save us the hassle of tracking them down. Also see the list of dependencies on the OpenSceneGraph website.

### On Ubuntu
# first let's install some basic dependencies for compilation
sudo apt-get install g++ subversion cmake cmake-qt-gui
# these should be enough to build a bare minimum openscenegraph install
sudo apt-get install libopenscenegraph80 libopenscenegraph-dev openscenegraph libqt4-core libqt4-dev
# optional deps: these may or may not be necessary for your needs
# (e.g. to add tiff image support install libtiff4-dev,
#  or link to a custom built version of the tiff library)
sudo apt-get install zlib1g-dev libxml2-dev libpng12-dev libjpeg-turbo8-dev libtiff4-dev libxrandr-dev libboost-dev libcairo2-dev librsvg2-dev libpoppler-glib-dev libgtkglextmm-x11-1.2-dev libcurl4-gnutls-dev
    
Now we are ready to download and compile.

# get the latest development version
cd /opt/source
svn checkout http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk osg-trunk
cd osg-trunk
mkdir build
mkdir cmake_build
cd cmake_build
# run cmake
cmake ..  -DCMAKE_INSTALL_PREFIX=/opt/source/osg-trunk/build
# optionally check cmake options/paths (run Configure, Generate, and exit GUI)
cmake-gui ..
# compile
make -j$threads
# install into build directory
make install
    
Next, update the environmental variables for your new library and binary path.

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths
export LD_LIBRARY_PATH="/opt/source/osg-trunk/build/lib64:$LD_LIBRARY_PATH"
export PATH="/opt/source/osg-trunk/build/bin:$PATH"
    
Finally, let's test out the new build.

# print OpenSceneGraph version
osgversion
# show example 3D model
cd /opt/source/osg-trunk
wget http://www.openscenegraph.org/downloads/stable_releases/OpenSceneGraph-3.0/data/OpenSceneGraph-Data-3.0.0.zip
unzip OpenSceneGraph-Data-3.0.0.zip 
cd OpenSceneGraph-Data-3.0.0
osgviewer cow.osg
    

osgEarth (On Ubuntu)

osgEarth is a terrain visualizer, similar to Google Earth and ArcGlobe. It allows you to drape vectors and rasters over elevation DEMs and overlay shapefile features in a 3D globe environment. The project is under rapid development so installing the latest version is very rewarding.
Here I only provide instructions for building osgEarth on Ubuntu. The simplest way to build osgEarth is to first install and then remove the stock osgEarth package. This will pull in most of the necessary dependencies, saving us the trouble of tracking them down. This is not the cleanest route as it will install some unnecessary packages, but it's the simplest way to get all the required dependencies. Also see the osgEarth building instructions on the osgEarth website.
First, you will need build the latest OpenSceneGraph development version because the stock OpenSceneGraph package in Ubuntu is currently too outdated. You will need to compile the latest OSG version and update the necessary library/path environmental variables as described in this guide.
Next, let's get some dependencies.

### On Ubuntu
# get basic dependencies for compiling
sudo apt-get install g++ cmake-qt-gui cmake git 
# install stock osgearth packages to pull in necessary dependencies
sudo apt-get install libosgearth-dev osgearth
# remove stock osgearth packages after dependencies are pulled in
# (these can also be left installed and should not interfere with the new installation)
sudo apt-get remove osgearth libosgearth1 libosgearth-dev
# install more needed dependencies
# (custom builds of gdal/tiff libraries can also be used)
sudo apt-get install libgdal-dev libqt4-core libqt4-dev
    
Now we are ready to download and compile.

# get the source code
cd /opt/source
git clone git://github.com/gwaldron/osgearth.git osgearth-trunk
cd osgearth-trunk
mkdir build
mkdir cmake_build
cd cmake_build
# run cmake and point to the new OSG build
# the CMAKE_PREFIX_PATH option is used to make sure that cmake
# uses the new osg libraries, rather than those installed from stock packages
cmake .. \
  -DCMAKE_PREFIX_PATH=/opt/source/osg-trunk/build \
  -DCMAKE_INSTALL_PREFIX=/opt/source/osgearth-trunk/build \
  -DOSG_DIR=/opt/source/osg-trunk/build
# optionally use the cmake GUI to look over configuration options
# make sure all the 'osg' paths point to the newly installed OpenSceneGraph
# run 'Configure', then 'Generate' and exit the GUI
cmake-gui .. 
# compile
make -j$threads
# install into build dir
make install
    
Next, update the environmental variables for your new library and binary path.

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths
export LD_LIBRARY_PATH="/opt/source/osgearth-trunk/build/lib64:$LD_LIBRARY_PATH"
export PATH="/opt/source/osgearth-trunk/build/bin:$PATH"
export OSG_FILE_PATH="/opt/source/osgearth-trunk/data"
    

# optional: vim users can add this line to .vimrc/.gvimrc to load .earth files as .xml files
au BufRead *.earth set filetype=xml
    
Now let's test the new build.

# see the osgearth version
osgearth_version
# run sample visualization
cd ../tests
osgearth_viewer boston_buildings.earth
    

Misc Tools & Libraries

These are other miscellaneous libraries/tools that are often needed as dependencies for other geospatial/scientific software described above.

MPI

MPI is a parallel computing standard that allows programs to take advantage of multiple processors. There are two competing MPI implementations available on most Linux distributions: mpich and openmpi. Generally, mpich is older and more compatible, particularly on CentOS, but both implementations have their own advantages.
Here I will describe how to install the mpich or openmpi MPI implementations from standard repositories on CentOS and Ubuntu. These libraries can then be used by boost, hdf5, flann, VTK, PCL, and other software.
Note: There also exists the openmp multiprocessing API, which is installed by default on CentOS and Ubuntu through the libgomp and libgomp1 packages, respectively.

Method 1: mpich (On Ubuntu)

### On Ubuntu

# install
sudo apt-get install libmpich2-dev

# check if main binary is installed (should be in /usr/bin)
which mpirun 
# check if libraries are installed (should see several mpich libraries)
ldconfig -p | grep -i mpich
    
Export mpich paths (necessary for some software, like netcdf, to compile):

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths
export LD_LIBRARY_PATH="/usr/lib/mpich2/lib:$LD_LIBRARY_PATH"
export CPATH="/usr/include/mpich2:$CPATH"
    

Method 1: mpich (On CentOS)

### On CentOS

# install
sudo yum install mpich2-devel

# check if main binary is installed (should be in /usr/bin)
which mpirun
    
Export mpich paths:

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths
export LD_LIBRARY_PATH="/usr/lib64/mpich2/lib:$LD_LIBRARY_PATH"
export PATH="/usr/lib64/mpich2/bin:$PATH"
export CPATH="/usr/include/mpich2-x86_64:$CPATH"
    

Method 2: openmpi (On Ubuntu)

### On Ubuntu

# install
sudo apt-get install libopenmpi1.5-dev openmpi1.5-bin

# check if main binary is installed (should be in /usr/bin)
which mpirun 
# check if libraries are installed (should see several libraries)
ldconfig -p | grep -i mpi
    
Export openmpi paths:

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths
export LD_LIBRARY_PATH="/usr/lib/openmpi/lib:$LD_LIBRARY_PATH"
export CPATH="/usr/lib/openmpi/include:$CPATH"
    

Method 2: openmpi (On CentOS)

### On CentOS

# install standard openmpi package
sudo yum install openmpi-devel

# alternatively, install an older version of openmpi
# (potentially more compatible with some boost versions and other packages).
# sudo yum install compat-openmpi-devel
    
Export openmpi paths:
If installing the standard openmpi package, use:

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths
export LD_LIBRARY_PATH="/usr/lib64/openmpi/lib:$LD_LIBRARY_PATH"
export PATH="/usr/lib64/openmpi/bin:$PATH"
export CPATH="/usr/include/openmpi-x86_64:$CPATH"
    
If installing the compat-openmpi package, use:

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths
export LD_LIBRARY_PATH="/usr/lib64/compat-openmpi/lib:$LD_LIBRARY_PATH"
export PATH="/usr/lib64/compat-openmpi/bin:$PATH"
export CPATH="/usr/include/compat-openmpi-x86_64:$CPATH"
    

The CPATH include file exports are needed when compiling some software (e.g. compiling gdal with a custom mpi-compiled hdf5 build).
You can also make the library path exports more permanent by adding them to /etc/ld.so.conf.d and running ldconfig (see Preliminaries).

CMake

CMake is a build system that many open source projects depend on. Latest versions of cmake may be required by development versions of some software (e.g. PCL and PDAL). See the official install instructions on the cmake website.
Let's get some basic dependencies (ncurses is required for ccmake).

### On Ubuntu
sudo apt-get install g++ libncurses5-dev

### On CentOS
sudo yum install gcc-c++ ncurses-devel
    
Now we can download and compile cmake.

# download latest version
# check here: http://www.cmake.org/cmake/resources/software.html
cd /opt/source
wget http://www.cmake.org/files/v2.8/cmake-2.8.11.1.tar.gz
tar xvfz cmake-2.8.11.1.tar.gz
cd cmake-2.8.11.1
mkdir build
./bootstrap --prefix=/opt/source/cmake-2.8.11.1/build
make -j$threads
# install into build dir
make install
# test out
./build/bin/cmake --version
./build/bin/ccmake --version
    
Finally, update the environmental variables for your new binary path.

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths
export PATH="/opt/source/cmake-2.8.11.1/build/bin:$PATH"
    

Boost

Boost is a set of C++ libraries that many open source project depend on. Latest versions of boost may be required by development versions of some software (e.g. PCL and PDAL). Also see the official install instructions on the boost website.
If installing boost with multiprocessor support, first install one of the MPI packages.
First, let's get some dependencies.

### On Ubuntu
sudo apt-get install g++ python-dev libbz2-dev zlib1g-dev

### On CentOS
sudo yum install gcc-c++ python-devel bzip2-devel zlib-devel
    
Now we can download, compile, and build.

# get latest release
# check here: http://www.boost.org/users/download/
cd /opt/source
wget http://iweb.dl.sourceforge.net/project/boost/boost/1.53.0/boost_1_53_0.tar.gz
tar xvfz boost_1_53_0.tar.gz
cd boost_1_53_0
mkdir build
./bootstrap.sh --prefix=/opt/source/boost_1_53_0/build
# for mpi support: edit project-config.jam and add this line:
#   using mpi ;
nano project-config.jam
./b2 -j$threads stage threading=multi --layout=tagged link=shared
./b2 install
    
Finally, update the environmental variables for your new library.

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths
export LD_LIBRARY_PATH="/opt/source/boost_1_53_0/build/lib:$LD_LIBRARY_PATH"
    

PROJ

PROJ is a cartographic projection library which most other GIS software depends on. It contains the share/proj/epsg file of the geospatial reference EPSG code numbers and allows for transformation of coordinates in different projection systems.
The only essential dependency required for proj is a C++ compiler.

### On Ubuntu
sudo apt-get install g++

### On CentOS
sudo yum install gcc-c++
    
Next, let's download and install.

cd /opt/source
wget http://download.osgeo.org/proj/proj-4.8.0.tar.gz
tar xvfz proj-4.8.0.tar.gz 
cd proj-4.8.0
mkdir build
./configure --prefix=/opt/source/proj-4.8.0/build
# compile
make -j$threads
# install into build dir
make install
    
Next, update the environmental variables for your new library and binary path.

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths
export LD_LIBRARY_PATH="/opt/source/proj-4.8.0/build/lib:$LD_LIBRARY_PATH"
export PATH="/opt/source/proj-4.8.0/build/bin:$PATH"
    
Now we can check the install.

# run proj
proj
# test coordinate transformation
# should see coordinates: 70d57'18.075"W  42d15'11.203"N 0.000
echo "338730 4679730" | cs2cs -v +init=epsg:26919 +to +init=epsg:4269
    

LibTIFF

LibTIFF is a library for TIFF images, used by geotiff, gdal, and most raster-capable GIS software. Also see the LibTIFF build instructions on their website.
Let's install some basic dependencies (for compression and jpeg support).

### On Ubuntu
sudo apt-get install g++ zlib1g-dev libjpeg-turbo8-dev

### On CentOS
sudo yum install gcc-c++ zlib-devel libjpeg-turbo-devel
    
Now let's download and compile.

cd /opt/source
wget http://download.osgeo.org/libtiff/tiff-4.0.3.tar.gz
tar xvfz tiff-4.0.3.tar.gz
cd tiff-4.0.3
# nb: build dir already exists
./configure --prefix=/opt/source/tiff-4.0.3/build/ \
            --exec-prefix=/opt/source/tiff-4.0.3/build
make -j$threads
# check compilation results (passes on CentOS, 1 fail on Ubuntu--probably ok)
make check
# install to build dir
make install
# confirm install
./build/bin/tiffinfo
    
Finally, update the environmental variables for your new library and binary path.

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths
export LD_LIBRARY_PATH="/opt/source/tiff-4.0.3/build/lib:$LD_LIBRARY_PATH"
export PATH="/opt/source/tiff-4.0.3/build/bin:$PATH"
    

GeoTIFF

GeoTIFF is a library for geospatial TIFF images. It is used by most raster-enabled GIS software.
GeoTIFF builds on proj and libtiff, so these should be installed first. Make sure all the library/path environmental variables are set for these custom builds. That is, run: source /opt/source/scripts/export_paths.sh on the shell before compiling (see Preliminaries).
Once you've built proj and libtiff as described above, we can build geotiff.

cd /opt/source
wget http://download.osgeo.org/geotiff/libgeotiff/libgeotiff-1.4.0.tar.gz
tar xvfz libgeotiff-1.4.0.tar.gz 
cd libgeotiff-1.4.0/
mkdir build
./configure --prefix=/opt/source/libgeotiff-1.4.0/build \
            --with-proj=/opt/source/proj-4.8.0/build \
            --with-libtiff=/opt/source/tiff-4.0.3/build \
            --with-zlib --with-jpeg
# compile
make -j$threads
# install into build dir
make install
# test out geotiff by making a sample geo tiff file
cd build/bin
./makegeo
./listgeo newgeo.tif
rm newgeo.tif
    
Finally, update the environmental variables for your new library and binary path.

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths
export LD_LIBRARY_PATH="/opt/source/libgeotiff-1.4.0/build/lib:$LD_LIBRARY_PATH"
export PATH="/opt/source/libgeotiff-1.4.0/build/bin:$PATH"
    

GEOS

GEOS is a spatial geometry library frequently used in GIS software and spatial databases.
GEOS does not have many dependency requirements beyond basic compiler tools. Also see the build instructions on their website.
First let's get some basic dependencies.

### On Ubuntu
sudo apt-get install build-essential swig python-dev

### On CentOS
sudo yum install gcc-c++ swig python-devel
    
Now we are ready to download and install.

cd /opt/source
wget http://download.osgeo.org/geos/geos-3.3.8.tar.bz2
tar xvjf geos-3.3.8.tar.bz2 
cd geos-3.3.8
mkdir build
./configure --prefix=/opt/source/geos-3.3.8/build --enable-python
# compile
make -j$threads
# check compilation result (passes on Ubuntu; may get errors on CentOS, but probably still ok)
make check
# install into build dir
make install
# check install
./build/bin/geos-config --version
    
The old python bindings for GEOS are unmaintained as the effort has been shifted to Shapely (see README).
Finally, update the environmental variables for your new library and binary path.

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths
export LD_LIBRARY_PATH="/opt/source/geos-3.3.8/build/lib:$LD_LIBRARY_PATH"
export PATH="/opt/source/geos-3.3.8/build/bin:$PATH"
    

HDF4

HDF4 is the older version of the HDF format, used for large data storage by a multitude of software (e.g. gdal). It is generally preferable to use the new version of HDF -- HDF5. However, while HDF5 strives to be backwards-compatible with HDF4, it is often still necessary to use HDF4 to work with data stored in the older format.
Here I will describe how to build HDF4 with autotools (i.e. configure). It is also possible to build HDF4 with cmake, however this seems to be less well supported (e.g. hard to specify ZLIB and JPEG directories). Also see the install instructions that come with the HDF4 source code.
First, let's get some dependencies.

### On Ubuntu
sudo apt-get install g++ zlib1g-dev libjpeg-dev bison flex

### On CentOS
sudo yum install gcc-c++ zlib-devel libjpeg-devel bison flex
    
Next, let's get the source code.

cd /opt/source
# download latest release
# check here: http://www.hdfgroup.org/ftp/HDF/HDF_Current/src/
wget http://www.hdfgroup.org/ftp/HDF/HDF_Current/src/hdf-4.2.9.tar.gz
tar xvfz hdf-4.2.9.tar.gz
cd hdf-4.2.9
mkdir build
    
We are now ready to compile.

# set compile options
# --disable-netcdf and --disable-fortran are necessary
# when compiling netcdf with hdf4 support
./configure \
  --prefix=/opt/source/hdf-4.2.9/build \
  --with-zlib \
  --with-jpeg \
  --enable-shared \
  --disable-netcdf \
  --disable-fortran

# compile
make -j$threads
# check build (should all pass)
make check
# install into build dir
make install
make install-examples
# check install
make installcheck
    
Finally, update the environmental variables for your new library and binary path.

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths
export LD_LIBRARY_PATH="/opt/source/hdf-4.2.9/build/lib:$LD_LIBRARY_PATH"
export PATH="/opt/source/hdf-4.2.9/build/bin:$PATH"
export CPATH="/opt/source/hdf-4.2.9/build/include:$CPATH"
    
The CPATH include files export may be needed when compiling some software (e.g. netcdf with hdf4).

HDF5

HDF5 is the latest incarnation of the HDF format, used for large data storage by a multitude of software (gdal, flann, vtk, etc).
Here I will describe how to build HDF5 with autotools (i.e. configure). It is also possible to build HDF5 with cmake, however this seems to be less well supported (e.g. when building netcdf with HDF5 support). If multiprocessor support is desired, install MPI first. Note that if you're building spdlib with HDF5, you will need to compile HDF5 without MPI support (no --enable-parallel flag, with --enable-cxx flag; see configure instructions below). Also see the install instructions that come with the HDF5 source code.
First, let's install some basic dependencies.

### On Ubuntu
sudo apt-get install g++ zlib1g-dev

### On CentOS
sudo yum install gcc-c++ zlib-devel
    
Next, let's get the source code.

# get latest source code; check here:
# http://www.hdfgroup.org/ftp/HDF5/current/src/
# http://www.hdfgroup.org/HDF5/release/obtain5.html

cd /opt/source
wget http://www.hdfgroup.org/ftp/HDF5/current/src/hdf5-1.8.11.tar.gz
tar xvfz hdf5-1.8.11.tar.gz
cd hdf5-1.8.11
# ugly hack for this version -- the INSTALL_VMS.txt file does not exist,
# but the installer may assume its presence (especially if using cmake),
# so create a blank file:
touch release_docs/INSTALL_VMS.txt
mkdir build
    
We are now ready to compile. The CFLAGS=-O0 parameter is optional -- it lowers the optimization level which avoids some errors during the make test.

## Method 1: Build without MPI support
# --enable-cxx: compile c++ interface (necessary if building spdlib)
# --with-zlib: enable zlib support (necessary if building spdlib)
CFLAGS=-O0 \
./configure \
  --prefix=/opt/source/hdf5-1.8.11/build \
  --enable-shared \
  --enable-build-all \
  --with-zlib \
  --with-pthread \
  --enable-cxx \

# compile
make -j$threads
# test build -- all tests should pass
make -j$threads check
# install into build dir
make install
    

## Method 2: Build with MPI support
# use CC to set mpi compiler
CFLAGS=-O0 \
CC="mpicc" \
./configure \
  --prefix=/opt/source/hdf5-1.8.11/build \
  --enable-shared \
  --enable-build-all \
  --with-zlib \
  --with-pthread \
  --enable-parallel \

# compile
make -j$threads
# test build (some parallel tests may fail)
make -j$threads check
# install into build dir
make install
    
Finally, update the environmental variables for your new library and binary path.

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths
export LD_LIBRARY_PATH="/opt/source/hdf5-1.8.11/build/lib:$LD_LIBRARY_PATH"
export PATH="/opt/source/hdf5-1.8.11/build/bin:$PATH"
export CPATH="/opt/source/hdf5-1.8.11/build/include:$CPATH"
    
The CPATH include files export may be needed when compiling some software (e.g. netcdf with hdf5).

NetCDF

NetCDF is a popular data format used to store a variety of geospatial and scientific data. It is used by gdal, grass, qgis and other geospatial software. We will build the latest version of the NetCDF library, which should be backwards compatible with older NetCDF formats as well (also see: NetCDF format).
Before building NetCDF, it is best to build the latest version of HDF5 and (optionally) HDF4. In addition, if multiprocessor support is desired, you can install one of the MPI libraries as well. Here I will describe how to build NetCDF with autotools (i.e. configure); it is also possible to build NetCDF with cmake, but this seems to be currently less well supported (especially for building parallel support). Also see the install notes, install documentation, building instructions and cmake instructions on the NetCDF website.
First let's get some dependencies.

### On Ubuntu
sudo apt-get install g++ zlib1g-dev libcurl4-gnutls-dev

### On CentOS
sudo yum install gcc-c++ zlib-devel libcurl-devel
    
Next, let's get the source code. We will get the C version of the source code because it is more robust and standardized than the C++ version.

cd /opt/source
# get latest C source code release
# check here: http://www.unidata.ucar.edu/downloads/netcdf/current/index.jsp
wget http://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-4.3.0.tar.gz
tar xvfz netcdf-4.3.0.tar.gz 
cd netcdf-4.3.0/
mkdir build
    
Now we are ready to compile.

## Method 1: Build without MPI support
H4DIR="/opt/source/hdf-4.2.9/build" \
H5DIR="/opt/source/hdf5-1.8.11/build" \
CPPFLAGS="-I${H5DIR}/include -I${H4DIR}/include" \
LDFLAGS="-L${H5DIR}/lib -L${H4DIR}/lib" \
./configure \
  --prefix=/opt/source/netcdf-4.3.0/build \
  --enable-netcdf-4 \
  --enable-shared \
  --enable-utilities \
  --enable-hdf4 \
  --enable-hdf4-file-tests \
  --enable-v2

# compile
make -j$threads
# test build -- shouldn't take too long; all tests should pass
make check 1>out.txt 2>err.txt &
cat out.txt err.txt |grep -i 'fail\|error'
# install into build dir
make install
# check how netcdf was compiled
./build/bin/nc-config --all
    

## Method 2: Build with MPI support
# (HDF5 should also be built with MPI support)
H4DIR="/opt/source/hdf-4.2.9/build" \
H5DIR="/opt/source/hdf5-1.8.11/build" \
CPPFLAGS="-I${H5DIR}/include -I${H4DIR}/include" \
LDFLAGS="-L${H5DIR}/lib -L${H4DIR}/lib" \
CC="mpicc" \
./configure \
  --prefix=/opt/source/netcdf-4.3.0/build \
  --enable-netcdf-4 \
  --enable-shared \
  --enable-utilities \
  --enable-hdf4 \
  --enable-hdf4-file-tests \
  --enable-v2 \
  --enable-parallel-tests 

# you can also optionally add the --enable-pnetcdf parameter,
# which will require pnetcdf (a separate package) to also be built

# compile
make -j$threads
# test build -- shouldn't take too long
# some tests may fail if using the --enable-parallel-tests option
make check 1>out.txt 2>err.txt &
cat out.txt err.txt |grep -i 'fail\|error'
# you can also run the parallel tests manually, e.g.
./h5_test/tst_h_par
# install into build dir
make install
# check how netcdf was compiled
./build/bin/nc-config --all
    
Finally, update the environmental variables for your new library and binary path.

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths
export LD_LIBRARY_PATH="/opt/source/netcdf-4.3.0/build/lib:$LD_LIBRARY_PATH"
export PATH="/opt/source/netcdf-4.3.0/build/bin:$PATH"
export CPATH="/opt/source/netcdf-4.3.0/build/include:$CPATH"
    

libkml (On CentOS)

libkml is a KML library. It is used by GDAL and other GIS software to read/write KML files.
Ubuntu has a fairly up-to-date libkml version in the stock libkml-dev package; thus building from source on Ubuntu is currently not necessary. The instructions below describe how to build from scratch on CentOS. Also see the building instructions and a dependencies list on the libkml website.

### On CentOS

# install dependencies
sudo yum install gcc-c++ zlib-devel libtool expat-devel subversion libcurl-devel python-devel swig
# download latest development version
cd /opt/source
svn co http://libkml.googlecode.com/svn/trunk/ libkml-trunk
cd libkml-trunk
mkdir build
# compile
./autogen.sh
./configure --prefix=/opt/source/libkml-trunk/build --disable-java --enable-python
make -j$threads
# test compilation (should all pass on CentOS)
make check
# install into build dir
make install
    
Next, update the environmental variables for your new library and python module.

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths
export LD_LIBRARY_PATH="/opt/source/libkml-trunk/build/lib:$LD_LIBRARY_PATH"
export PYTHONPATH="$PYTHONPATH:/opt/source/libkml-trunk/build/lib64/python2.6/site-packages"
    
Finally, change to a new shell/terminal, re-export the new environmental variables and check whether the python module is loaded.

# check python install (should see path to loaded local python module)
python -c 'import kmldom; print kmldom.__file__'
    

wxPython (On CentOS)

wxPython is a python wrapper for the wxWidgets GUI toolkit. On CentOS wxWidgets is available in the standard repositories, but wxPython is only available through third-party add-on repos. wxPython is required for GRASS and other visual GIS software.
Here I will provide instructions for building wxpython on CentOS (this should not be necessary on Ubuntu as it has fairly up-to-date wxpython packages). Also see the installation and build instructions on the wxpython website.
Let's download and install wxpython.

### On CentOS

# install the basic dependencies
sudo yum install gcc-c++ python-devel wxGTK-devel
# get the source code
cd /opt/source
wget http://hivelocity.dl.sourceforge.net/project/wxpython/wxPython/2.8.12.1/wxPython-src-2.8.12.1.tar.bz2
tar xvjf wxPython-src-2.8.12.1.tar.bz2
cd wxPython-src-2.8.12.1/wxPython
mkdir build
# install python module (will create full path automatically)
python setup.py install --root=/opt/source/wxPython-src-2.8.12.1/wxPython/build
    
Next, update the environmental variables for your new python module.

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths
export PATH="/opt/source/wxPython-src-2.8.12.1/wxPython/build/usr/bin:$PATH"
export PYTHONPATH="$PYTHONPATH:/opt/source/wxPython-src-2.8.12.1/wxPython/build/usr/lib64/python2.6/site-packages/wx-2.8-gtk2-unicode"
export PYTHONPATH="$PYTHONPATH:/opt/source/wxPython-src-2.8.12.1/wxPython/build/usr/lib/python2.6/site-packages"
    
Now let's check the install. First start a new shell/terminal and re-export the new python module paths.

# check python install (should see path to loaded local python module)
python -c 'import wx; print wx.__file__'
python -c 'import wxversion; print wxversion.__file__'
    

Points2Grid

Points2Grid is a simple tool for gridding pointclouds into rasters. The old Points2Grid project is now being worked on by the PDAL group.
To build p2g, it is best to first install the latest versions of cmake and boost. In addition, for *.las file support, install liblas as well.
First let's get some basic dependencies.

### On Ubuntu
sudo apt-get install git libbz2-dev libcurl4-gnutls-dev

### On CentOS
sudo yum install git bzip2-devel libcurl-devel
    
Now let's get the latest development code.

cd /opt/source
git clone https://github.com/CRREL/points2grid.git p2g-trunk
cd p2g-trunk
mkdir build
mkdir cmake_build
    
A slight modification to the code is necessary for proper memory management (see INSTALL text file in p2g source directory).

# find total system ram in bytes:
echo `cat /proc/meminfo | grep MemTot | awk -F" " '{print $2}'`*1000 | bc
# divide by 55 -- this is the recommended memory limit for p2g
echo `cat /proc/meminfo | grep MemTot | awk -F" " '{print $2}'`*1000/55 | bc
# edit Interpolation.hpp file and modify this line:
#   static const unsigned int MEM_LIMIT = 200000000;
# replace the MEM_LIMIT value to the RAM-IN-BYTES/55 value from above
nano ./include/points2grid/Interpolation.hpp
    
Now we are ready to compile.

cd cmake_build

## run cmake
# - these options can also be set interactively inside ccmake
# - the liblas options are only necessary if building with las support

ccmake ..  \
 -DCMAKE_INSTALL_PREFIX=/opt/source/p2g-trunk/build \
 -DBOOST_ROOT=/opt/source/boost_1_53_0/build \
 -DBoost_NO_BOOST_CMAKE=TRUE \
 -DBoost_IOSTREAMS_LIBRARY_RELEASE=/opt/source/boost_1_53_0/build/lib/libboost_iostreams.so \
 -DBoost_IOSTREAMS_LIBRARY_DEBUG=/opt/source/boost_1_53_0/build/lib/libboost_iostreams.so \
 -DBoost_PROGRAM_OPTIONS_LIBRARY_RELEASE=/opt/source/boost_1_53_0/build/lib/libboost_program_options.so \
 -DBoost_PROGRAM_OPTIONS_LIBRARY_DEBUG=/opt/source/boost_1_53_0/build/lib/libboost_program_options.so \
 -DLIBLAS_INCLUDE_DIR=/opt/source/libLAS-1.7.0/build/include \
 -DLIBLAS_LIBRARY=/opt/source/libLAS-1.7.0/build/lib/liblas.so \
 -DLIBLAS_C_LIBRARY=/opt/source/libLAS-1.7.0/build/lib/liblas_c.so \

# run 'configure', check options/paths, then
# run 'configure' again as needed, run 'generate' and exit

## compile and install into build dir
make -j$threads
make install
    
Finally, update the environmental variables for your new library and binary path.

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths
export LD_LIBRARY_PATH="/opt/source/p2g-trunk/build/lib:$LD_LIBRARY_PATH"
export PATH="/opt/source/p2g-trunk/build/bin:$PATH"
    
Test out the new build.

# test with las support (create 1-m raster from sample lidar file):
cd /opt/source/p2g-trunk/build/bin
./points2grid -i ../../example.las -o example --input_format=las --output_format=arc --idw --resolution=1 --fill --interpolation_mode=incore
    

Eigen

Eigen is a C++ template library for linear algebra, used by PCL, CGAL, MeshLab, etc.
It is recommended to first install the latest version of cmake. Then install a few dependencies.

### On Ubuntu
sudo apt-get install libfftw3-dev fftw-dev gfortran

### On CentOS
sudo yum install fftw-devel gcc-gfortran
    
Now we can download, build, and install.

# download latest release
cd /opt/source
wget http://bitbucket.org/eigen/eigen/get/3.1.3.tar.gz
tar xvfz 3.1.3.tar.gz
mv eigen-eigen-2249f9c22fe8 eigen_3_1_3
cd eigen_3_1_3
mkdir build
mkdir cmake_build
cd cmake_build
# run ccmake (press c, confirm paths, press c again, press g, and exit)
ccmake .. -DCMAKE_INSTALL_PREFIX=/opt/source/eigen_3_1_3/build
make -j$threads
# install into build dir
make install

# optional -- build tests (takes a long time)
make check
./test/geo_transformations_1
    

FLANN

FLANN is a C++ library for performing nearest neighbor searches. It is used by the PCL, PDAL, and other software.
A recent version of cmake is recommended. Optionally, you can enable MPI support for multiprocessing, by first installing MPI libraries, and then compiling boost with MPI support. You can also install HDF5 (also potentially with MPI support), which is the storage format that flann uses (but this is not required to compile flann). Also see the manual on the flann website.
Besides cmake you need to install numpy if compiling flann python bindings.

### On Ubuntu
sudo apt-get install python-numpy

### On CentOS
sudo yum install numpy
    
Next, let's get the latest source code.

cd /opt/source
wget http://people.cs.ubc.ca/~mariusm/uploads/FLANN/flann-1.8.4-src.zip
unzip flann-1.8.4-src.zip
cd flann-1.8.4-src
mkdir build
mkdir cmake_build
cd cmake_build
    
Next, run cmake with or without MPI support.

## Method 1: Build without MPI support
## run cmake
# main options (these can also be set interactively inside ccmake)
#  BUILD_MATLAB_BINDINGS:  whether to build hdf matlab support
#  HDF5*:                  used to set custom HDF5 paths,
#                          when built with autotools/configure;
#                          the compiler is 'h5cc' rather than 'h5pcc' 
#                          because we built hdf5 w/o parallel support
#                          note: if building HDF5 with cmake,
#                          use this HDF5 setting instead:
#                          -DHDF5_DIR=
#                           /opt/source/hdf5-1.8.11/build/share/cmake/hdf5

ccmake .. \
  -DCMAKE_INSTALL_PREFIX=/opt/source/flann-1.8.4-src/build \
  -DBUILD_MATLAB_BINDINGS=off \
  -DHDF5_hdf5_LIBRARY=/opt/source/hdf5-1.8.11/build/lib/libhdf5.so \
  -DHDF5_hdf5_LIBRARY_DEBUG=/opt/source/hdf5-1.8.11/build/lib/libhdf5.so \
  -DHDF5_hdf5_LIBRARY_RELEASE=/opt/source/hdf5-1.8.11/build/lib/libhdf5.so \
  -DHDF5_C_INCLUDE_DIR=/opt/source/hdf5-1.8.11/build/include \
  -DHDF5_DIFF_EXECUTABLE=/opt/source/hdf5-1.8.11/build/bin/h5diff \
  -DHDF5_C_COMPILER_EXECUTABLE=/opt/source/hdf5-1.8.11/build/bin/h5cc \
  -DUSE_MPI=off \

# -> run 'configure'; ignore 'gtest not found' warnings
# -> check  options and paths
# -> re-run configure as needed
# -> generate and exit
    

## Method 2: Build with MPI support
## run cmake
# main options (these can also be set interactively inside ccmake)
#  BUILD_MATLAB_BINDINGS:  whether to build hdf matlab support
#  BOOST_ROOT:             path to custom built boost directory
#                          boost is only needed when compiling w/ mpi
#  Boost_NO_BOOST_CMAKE:   used because we are using a custom boost 
#                          build, which will not have boost.cmake files
#                          (on CentOS boost-devel package creates
#                           '/usr/lib64/boost/Boost*.cmake' files)
#  HDF5*:                  used to set custom HDF5 paths,
#                          when built with autotools/configure;
#                          the compiler is 'h5pcc' rather than 'h5cc' 
#                          because we built hdf5 w/ parallel support
#                          note: if building HDF5 with cmake,
#                          use this HDF5 setting instead:
#                          -DHDF5_DIR=
#                           /opt/source/hdf5-1.8.11/build/share/cmake/hdf5
#  USE_MPI:                whether to use MPI (will need boost w/ mpi)

ccmake .. \
  -DCMAKE_INSTALL_PREFIX=/opt/source/flann-1.8.4-src/build \
  -DBUILD_MATLAB_BINDINGS=off \
  -DHDF5_hdf5_LIBRARY=/opt/source/hdf5-1.8.11/build/lib/libhdf5.so \
  -DHDF5_hdf5_LIBRARY_DEBUG=/opt/source/hdf5-1.8.11/build/lib/libhdf5.so \
  -DHDF5_hdf5_LIBRARY_RELEASE=/opt/source/hdf5-1.8.11/build/lib/libhdf5.so \
  -DHDF5_C_INCLUDE_DIR=/opt/source/hdf5-1.8.11/build/include \
  -DHDF5_DIFF_EXECUTABLE=/opt/source/hdf5-1.8.11/build/bin/h5diff \
  -DHDF5_C_COMPILER_EXECUTABLE=/opt/source/hdf5-1.8.11/build/bin/h5pcc \
  -DUSE_MPI=on \
  -DBOOST_ROOT=/opt/source/boost_1_53_0/build \
  -DBoost_NO_BOOST_CMAKE=TRUE \

# -> run 'configure'; ignore 'gtest not found' warnings
# -> check  options and paths
# -> re-run configure as needed
# -> generate and exit
    
We can now compile and install.

# compile
make -j$threads
# install into build dir
make install

# note that you will get python install errors --
# we will install python manually into local path below
    
Update the environmental variables for your new library and binary path.

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths
export LD_LIBRARY_PATH="/opt/source/flann-1.8.4-src/build/lib:$LD_LIBRARY_PATH"
export PATH="/opt/source/flann-1.8.4-src/build/bin:$PATH"
    
Now let's install the python bindings.

cd /opt/source/flann-1.8.4-src/build/share/flann/python/
python setup.py install --prefix=/opt/source/flann-1.8.4-src/build
    
Once you confirm in which 'site-packages' directory the python module got installed, add it to your stored list of environmental paths.

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths

### On Ubuntu:
export PYTHONPATH="$PYTHONPATH:/opt/source/flann-1.8.4-src/build/lib/python2.7/site-packages"

### On CentOS:
export PYTHONPATH="$PYTHONPATH:/opt/source/flann-1.8.4-src/build/lib/python2.6/site-packages"
    
Finally, test the python bindings.

# check python install (should see path to loaded local python module)
python -c 'import pyflann; print pyflann.__file__'
    

Qhull

Qhull is a library for computing convex hulls, Delaunay, and Voronoi polygons/polyhedrons from points. It is used by the Point Cloud Library.
Before building Qhull, building the latest version of cmake is recommended.

# download latest release
# check here: http://www.qhull.org/download/
cd /opt/source
wget http://www.qhull.org/download/qhull-2012.1-src.tgz
tar xvfz qhull-2012.1-src.tgz
cd qhull-2012.1
# nb: build directory already exists
mkdir cmake_build
cd cmake_build

## run cmake
ccmake .. -DCMAKE_INSTALL_PREFIX=/opt/source/qhull-2012.1/build
# run 'configure', check options/paths,
# run 'configure' again as needed, then generate and exit

# compile
make -j$threads
# install into build dir
make install

# test
/opt/source/qhull-2012.1/build/bin/qhull
    
Finally, update the environmental variables for your new library and binary path.

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths
export LD_LIBRARY_PATH="/opt/source/qhull-2012.1/build/lib:$LD_LIBRARY_PATH"
export PATH="/opt/source/qhull-2012.1/build/bin:$PATH"
    

CGAL

CGAL is a feature-rich C++ library of geometric algorithms. It is useful for performing efficient geometric operations on vectors and pointclouds in C++.
Before building CGAL, it is best to build a new version of cmake and boost. You can also optionally build eigen for additional functionality, but this is not required. Also see the installation manual on the CGAL website.
First let's get some dependencies.

### On Ubuntu
# all that is required to build cgal (besides cmake/boost)
sudo apt-get install libgmp-dev libmpfr-dev
# for image support (recommended)
sudo apt-get install zlib1g-dev 
# optional: if not building eigen from source, install from packages
sudo apt-get install libeigen3-dev
# optional for demos using qt3 (some use qt3, others qt4)
sudo apt-get install libqt3-mt-dev libqt3-compat-headers
# more optional deps
sudo apt-get install libmpfi-dev libntl-dev libqglviewer-dev libcoin60-dev libipe-dev
# even more optional deps
sudo apt-get install libblas-dev liblapack-dev libf2c2-dev f2c
    

### On CentOS
# all that is required to build cgal (besides cmake/boost)
sudo yum install gmp-devel mpfr-devel
# for image support (recommended)
sudo yum install zlib-devel
# optional for demos (some use qt3, others qt4)
sudo yum install qt3-devel qt-devel
# even more optional deps
sudo yum install blas-devel lapack-devel
    
Now let's get the latest source code.

# get latest release
# check here: http://www.cgal.org/download.html
cd /opt/source
wget https://gforge.inria.fr/frs/download.php/32359/CGAL-4.2.tar.gz
tar xvfz CGAL-4.2.tar.gz
cd CGAL-4.2/
mkdir build
mkdir cmake_build
cd cmake_build
    
We are now ready to compile.

## run cmake
## note: the options can also be set interactively in ccmake/cmake-gui

# basic options (demos, examples, and qt are optional)
ccmake .. \
  -DCMAKE_INSTALL_PREFIX=/opt/source/CGAL-4.2/build \
  -DBOOST_ROOT=/opt/source/boost_1_53_0/build \
  -DBoost_NO_BOOST_CMAKE=TRUE \
  -DWITH_CGAL_Core=on \
  -DWITH_CGAL_ImageIO=on \
  -DWITH_demos=on \
  -DWITH_examples=on \
  -DWITH_CGAL_Qt3=on \
  -DWITH_CGAL_Qt4=on \

# if eigen is installed (provide path if used custom build)
  -DWITH_Eigen3=on \
  -DEIGEN3_INCLUDE_DIR=/opt/source/eigen_3_1_3/build/include \

# more options
  -DWITH_ZLIB=on \
  -DWITH_BLAS=on \
  -DWITH_LAPACK=on \

# even more possible options for Ubuntu (depending on what is installed)
  -DWITH_OpenGL=on \
  -DWITH_NTL=on \
  -DWITH_MPFI=on \
  -DWITH_Coin3D=on \
  -DWITH_QGLViewer=on \
  -DWITH_IPE=on \

# run 'configure', check all options (use advanced view to see all paths),
# then run 'configure' again as needed, 'generate' and exit.

# compile
make -j$threads
# install into build dir
make install

# optionally compile demos
make -j$threads demos
# test
./demo/Mesh_2/mesh

# optionally compile examples (takes a long time; some may not work)
make -j$threads examples
# test
./examples/Polygon/Polygon
    
Finally, update the environmental variables for your new library and binary path.

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths
export LD_LIBRARY_PATH="/opt/source/CGAL-4.2/build/lib:$LD_LIBRARY_PATH"
export PATH="/opt/source/CGAL-4.2/build/bin:$PATH"
    

xerces

xerces is an XML library from the Apache foundation. A new version of xerces is required for some software, like spdlib. An up-to-date version is provided in the standard packages on Ubuntu, while on CentOS the packaged version is outdated.
First let's get some dependencies.

### On Ubuntu
sudo apt-get install g++

### On CentOS
sudo yum install gcc-c++ 
    
Now we can get the source code and compile.

cd /opt/source
# get latest release
# check here: http://xerces.apache.org/mirrors.cgi
wget http://mirror.symnds.com/software/Apache//xerces/c/3/sources/xerces-c-3.1.1.tar.gz
tar xvfz xerces-c-3.1.1.tar.gz
cd xerces-c-3.1.1
mkdir build
./configure --prefix=/opt/source/xerces-c-3.1.1/build
make -j$threads
make install
    
Finally, update the environmental variables for your new library and binary path.

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths
export LD_LIBRARY_PATH="/opt/source/xerces-c-3.1.1/build/lib:$LD_LIBRARY_PATH"
export PATH="/opt/source/xerces-c-3.1.1/build/bin:$PATH"
    

Misc Utilities

These are other miscellaneous utilities useful for working on the command-line.

Byobu (On CentOS)

Byobu is a user-friendly enhancement to screen. It allows you to run multiple shell sessions from a single ssh connection; processes continue to run remotely even if a connection is broken and you can pick up where you left off by re-connecting to the last Byobu session.
Here I provide instructions for compiling Byobu on CentOS. On Ubuntu, Byobu is available in the standard byobu package. Also see the official compilation instructions on the Byobu website.

### On CentOS

# first install screen
sudo yum install screen

# download the latest release; check for latest version here:
# https://launchpad.net/byobu/+download
cd /opt/source
wget https://launchpad.net/byobu/trunk/5.43/+download/byobu_5.43.orig.tar.gz
tar xvfz byobu_5.43.orig.tar.gz 
cd byobu-5.43
mkdir build
./configure --prefix=/opt/source/byobu-5.43/build
make -j$threads
make install
    
Finally, update the environmental variables for your new library and binary path.

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths
export LD_LIBRARY_PATH="/opt/source/byobu-5.43/build/lib:$LD_LIBRARY_PATH"
export PATH="/opt/source/byobu-5.43/build/bin:$PATH"
    
Now run byobu on the command line and press F9 for the help menu.

htop (On CentOS)

htop is an interactive process viewer, similar to top, but with more advanced features, including the ability to see multiple processor thread use in a colorful output.
Here I provide instructions for building htop on CentOS. On Ubuntu it is available in the standard htop package.

### CentOS

# install basic dependencies
sudo yum install gcc-c++ ncurses-devel

# download, compile, and install
cd /opt/source
wget http://iweb.dl.sourceforge.net/project/htop/htop/1.0.2/htop-1.0.2.tar.gz
tar xvfz htop-1.0.2.tar.gz 
cd htop-1.0.2
mkdir build
./configure --prefix=/opt/source/htop-1.0.2/build/
make -j$threads
make install
    
Finally, update the environmental variables for your new binary path.

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths
export PATH="/opt/source/htop-1.0.2/build/bin:$PATH"
    
Now run htop on the command line.

lftp

lftp is a sophisticated ftp client, useful for downloading/mirroring ftp directories (similar to rsync for ftp). Both CentOS and Ubuntu have an lftp package in the basic repositories (on Centos lftp and lftp-scripts, on Ubuntu lftp), but these are rather out of date, especially on CentOS. Here we will compile the latest released version of lftp. (Note that at the moment version 4.4.8 has some compilation issues, so we will compile 4.4.7 instead).
Let's get some basic dependencies to get lftp to work with most major features.

### On Ubuntu
sudo apt-get install g++ libncurses5-dev libreadline-dev zlib1g-dev libexpat1-dev libgnutls-dev libstring-crc32-perl libdigest-md5-file-perl

### CentOS
sudo yum install gcc-c++ ncurses-devel readline-devel zlib-devel expat-devel gnutls-devel perl-String-CRC32
    
Now we can compile.

cd /opt/source
# get latest version
# check here: http://lftp.yar.ru/get.html
wget http://ftp.yar.ru/pub/source/lftp/lftp-4.4.7.tar.gz
tar xvfz lftp-4.4.7.tar.gz 
cd lftp-4.4.7
mkdir build
./configure --prefix=/opt/source/lftp-4.4.7/build
# compile
make -j$threads
# check compilation
make check
# install into build dir
make install
    
Finally, update the environmental variables for your new library and binary path.

### add to /opt/source/scripts/export_paths.sh (see Preliminaries)
### then run: 'source export_paths.sh' to update these environment paths
export LD_LIBRARY_PATH="/opt/source/lftp-4.4.7/build/lib:$LD_LIBRARY_PATH"
export PATH="/opt/source/lftp-4.4.7/build/bin:$PATH"   
    
Lastly, test the build.

# check version
lftp --version
# check file verification script; should see no output
/opt/source/lftp-4.4.7/build/share/lftp/verify-file
    

Tips and Troubleshooting

Note that bleeding-edge development versions are not very dependable and may not always build. You can try using more stable snapshots of development code instead of the latest repository code if you get errors. You will also want to regularly update your repositories and rebuild them to get more recent updates by using svn up or git checkout.
Occasionally, you may have to revert to an older version of the development repository to get things to compile. This will vary with each repository and version control system used, but here is an example using git.

# show current revision number
git describe --tags
# show past changes in quick one-liners
git log --oneline
# check out specific revision (from one of the revision numbers shown above)
git checkout 18e25db
# go back to latest revision
git checkout master
    
If you get errors while compiling you may have a missing dependency. This can be tricky to track down. Here are some tips for tracking down specific files in the available packages.

### On Ubuntu

sudo apt-get install apt-file
# after installation, a GUI will launch to update your list of packages/files
# you can re-run this update periodically with:
apt-file update
# see which packages will install the file 'avcodec.h'
apt-file search "avcodec.h"
# see which files the package 'proj' will install
apt-file -F list proj
    

### On CentOS

# see which packages will install the file 'epsg'
# (you can also specify the exact path)
yum provides "*/epsg"
    
More generally, here are some useful command-line tips for working with packages:

### On Ubuntu

# search for an available package by name
apt-cache pkgnames|grep -i postgis
apt-cache search postgis | grep -i postgis
# search for package starting with name keyword
apt-cache pkgnames postgis
# show description and version number of available package
apt-cache show postgis
# search for installed packages and see their version numbers
dpkg -l "*postgis*"
# show package dependencies
apt-cache depends proj
apt-cache showpkg proj
# show package changelog
apt-get changelog vim
# install specific package version
sudo apt-get install vsftpd=2.3.5-3ubuntu1
# install package without upgrading already installed packages
sudo apt-get install cpuburn --no-upgrade
# find out what files a package has installed
dpkg -L postgis
# find out what package a file on your system belongs to
dpkg -S /usr/share/proj/epsg
# search for a file on your entire system, avoiding permission denied errors
sudo find / -iname "epsg" 2> /dev/null
# increase disk space by removing downloaded .deb files (also see 'apt-get autoclean')
sudo apt-get clean
# remove packages that were automatically installed to satisfy dependencies, but are no longer needed
sudo apt-get autoremove
    

### On CentOS

# search for specific package name
yum list "*proj*"
# search for packages with multiple key words
yum search proj data
# show info about a package
yum info proj
# show package dependencies
yum deplist proj-epsg
# list files a package installs (use --enablerepo=epel, etc for specific repos)
repoquery --list proj-epsg
# list all installed packages
yum list installed | more
# list enabled repositories
yum repolist
# list all available repositories (also see /etc/yum.repos.d)
yum repolist all
# install package from specific repo (enabled or disabled)
sudo yum install phpmyadmin --enablerepo=epel
# clean cached files
sudo yum clean all
# search for a file on your entire system, avoiding permission denied errors
sudo find / -iname "epsg" 2> /dev/null
    

further resources

Some useful links: