[GRASS5] Swig interface for Grass

Ari Jolma ari.jolma at tkk.fi
Tue Aug 30 10:25:44 EDT 2005

[note: this discussion got initiated outside this list]

Markus Neteler wrote:

>One example as "seed" may be sufficient to get other people
>interested, something like a proof of concept. This may break
>the barrier to do more python and perl with GRASS.

Well, I managed to get a Grass error message from a Perl program :)

I made a simple Swig interface file into which I added the main() from 
r.slope.aspect with a new name:

int r_slope_aspect (int argc, char **argv);

With this I get the wrapper code and the Grass Perl module. Then I made 
a simple Makefile.PL for the Perl extension, which lists the shared 
grass libs and object code files from the wrapper and the 
r_slope_aspect. Makefile.PL is standard, after running it gives 
Makefile, which is for making the necessary binaries for the Grass 
module and installing the module etc. I put into the test code a 
function call:


which gives me the Grass error "ERROR: LOCATION_NAME not set"

I have a Grass database and I get the same error running r.slope.aspect.

I had to comment out a lot of declarations from gisdefs.h because the 
functions are non-existing and Perl does not tolerate that.

The tedious part would be to write typemaps for all structs in Grass 
code. Converting all modules into functions is a more difficult job but 
could probably be automated (with a suitable Perl program of course).


Prof. Ari Jolma
Kartografia ja Geoinformatiikka / Cartography and Geoinformatics
Teknillinen Korkeakoulu / Helsinki University of Technology
POBox 1200, 02015 TKK, Finland
Email: ari.jolma at tkk.fi URL: http://www.tkk.fi/~jolma

More information about the grass-dev mailing list