-
Notifications
You must be signed in to change notification settings - Fork 201
1. Getting Started
This tutorial will help you to get started with libspatialindex using C++ on linux. The following code is run on Ubuntu 12. If you are using windows the installation may be different. First install some prerequisites please enter the following into terminal. You may very well already have these installed.
sudo apt-get update
sudo apt-get install curl
sudo apt-get install g++
sudo apt-get install make
Now we download and install the library. It doesn't matter what directory you download this in. Please note the version number, you can check if there are more recent versions in the download page here http://download.osgeo.org/libspatialindex/ . Now enter the following into your terminal:
curl -L http://download.osgeo.org/libspatialindex/spatialindex-src-1.8.5.tar.gz | tar xz
cd spatialindex-src-1.8.5
./configure
make
sudo make install
sudo ldconfig
libspatialindex should now be installed on your system. Let's try to make a small c++ program to test this. Create the file tutorial1.cpp somewhere and enter the following:
#include <iostream>
#include <spatialindex/capi/sidx_api.h>
using namespace std;
using namespace SpatialIndex;
int main(int argc, char* argv[])
{
char* pszVersion = SIDX_Version();
fprintf(stdout, "libspatialindex version: %s\n", pszVersion);
fflush(stdout);
free(pszVersion);
}
Now let's compile the code. Type the following into the console. Please note -std=c++0x
makes it compile into C++11, although not required here it will be used in later examples.
g++ -std=c++0x tutorial1.cpp -lspatialindex_c -lspatialindex -o tutorial1
Now run the program:
./tutorial1
and it should output the following:
libspatialindex version: 1.8.5