Monday, 4 February 2013

Compiling points2grid on Fedora with g++

Gridding large [x,y,z] point cloud datasets. Matlab and python have both failed me with their inefficient use of memory. So I'm having to turn to other tools.

Points2Grid is a tool, written in C++, which promises to do the job in a simple intuitive way. It accepts ascii and las (lidar) formats and outputs gridded data, plus gridded data densities.

First install LIBLAS which is Lidar data translation libraries. The recommended version is 1.2.1. I installed liblas 1.6.1 because it was the oldest version on the site that had a working link. I installed this by issuing:

cd libLAS-1.6.1/
mkdir makefiles
cd makefiles
cmake -G "Unix Makefiles" ../
make
sudo make install
view raw p2g1.sh hosted with ❤ by GitHub


Make a note of where the libraries are installed. On my system: /usr/local/include/liblas/

Download points2grid from here

In Interpolation.h, adjust MEM_LIMIT variable in the  file to reflect the memory limitations of your system. From the README guide, 

"As a rule of thumb, set the MEM_LIMIT to be (available memory in bytes)/55. For jobs that generate
grids cells greater than the MEM_LIMIT, points2grid goes "out-of-core", resulting in significantly worse performance."
Find this value using:
mem=$(cat /proc/meminfo | grep MemTot | awk -F" " '{print $2}')
echo "$mem/55" | bc
view raw p2g2.sh hosted with ❤ by GitHub
I then had to point the code to where the liblas directories had been installed. In Interpolation.cppreplace:
#replace
#include <liblas/laspoint.hpp>
#include <liblas/lasreader.hpp>
#with
#include </usr/local/include/liblas/liblas.hpp>
#include </usr/local/include/liblas/reader.hpp>
#replace
liblas::LASHeader const& header = reader.GetHeader();
#with
liblas::Header const& header = reader.GetHeader();
#replace
liblas::Reader reader(ifs); //liblas::LASReader reader(ifs);
#with
liblas::LASReader reader(ifs);
#replace
liblas::LASPoint const& p = reader.GetPoint();
#with
liblas::Point const& p = reader.GetPoint();
view raw p2gg.sh hosted with ❤ by GitHub


It should then install with a simple 'make' command. Happy gridding!


No comments: