# GDAL/OGR - Swig - Perl

## Installation

This is one possible way to install the gdal and ogr libraries and the perl bindings, with a focus on the latter and working on a Linux. Starting in the gdal directory run
./configure
make
make install
cd swig/perl
running 'make generate' here is suggested
make build
make install

### Notes:

* The wrappers (*_wrap.cpp files) may be rebuilt (swig is required) with the command

    make generate

before "make build". In some cases "make veryclean" needs to be run prior to "make generate".

* Turning on debug in ./configure:

    export CFG=debug; ./configure

## Running the test code

    make test

### Notes:

* The test code is not very verbose. In the case of unexpected behavior, you may want to run the test in verbose mode:

    make test VERBOSE=1

* The test can be run even without installing GDAL itself (this works in Linux, I'm not sure about other environments):

    export LD_LIBRARY_PATH=../../.libs; make test

## Using the modules

The main documentation of the modules are generated from the pods:
gdal
gdalconst
ogr
osr

### Example: creating a vector data set

I used this code to import a GPS track, which I created with GPS::NMEA, into PostGIS.

    use ogr;
    my $datasource = ogr::Open('PG:dbname=gps', 1);
    my $layer = $datasource->CreateLayer('track');
    my $schema = $layer->GetLayerDefn();
    my $feature = new ogr::Feature($schema);
    $geometry = new ogr::Geometry($ogr::wkbLineString);
    while (<STDIN>) {
     chomp;
     s/^\(//;
     s/\)$//;
     my @l = split(/,/);
     for ($l[2],$l[4]) {
     my $i = int;
     $_ = $i + ($_-$i)/0.6;
     }
     $geometry->AddPoint($l[4],$l[2]);
    }
    $feature->SetGeometry($geometry);
    $layer->CreateFeature($feature);
    $layer->SyncToDisk;

Copyright 2006 Ari.Jolma at tkk.fi