[GRASS5] Re: [GRASSLIST:4669] GRASS, GDAL and libgrass
Glynn Clements
glynn at gclements.plus.com
Thu Oct 28 19:08:36 EDT 2004
[CC'd to development list.]
Dylan Beaudette wrote:
> I would like to thank Hamish and Glynn for the helpful suggestions
> on getting libgrass compiled.
>
> However, it now seems that either I don't fully understand how GRASS
> and GDAL operate together (which is probably the case), or else
> there is some trickery that I am not aware of to get a working
> r.in.gdal and r.out.gdal...
>
> based on some tests it seems that:
> 1. a working r.in.gdal can be obtained by compiling GDAL without
> libgrass (i.e compilation of r.in.gdal breaks when GDAL is compiled
> with libgrass)
>
> 2. a functional replacement for r.out.gdal can be accomplished by
> re-compiling GDAL with libgrass after a GRASS itself has been
> compiled, and then using the libgrass-enabled gral_translate to
> convert between GRASS rasters and other formats.
>
> 3. re-compilation of GRASS from source requires that GDAL be
> re-compiled without libgrass, in order for a working
> r.in.gdal....ect - highly annoying to say the least.
That's about right.
> It would be ideal to have a working r.in.gdal / r.out.gdal without
> all of the above ... Am I just going about all of this in the wrong
> way? This is on a Debian Sarge machine, with GRASS CVS snapshot
> 10_23
Essentially, r.in.gdal and r.out.gdal have somewhat conflicting
requirements.
r.in.gdal is a binary executable which uses GDAL to read files and
uses the GRASS API to write the GRASS maps. Because it depends
directly upon the GRASS libraries, using a version of GDAL which was
built with libgrass support may not work, as the linked executable
ends up with multiple versions of the core GRASS functions. OTOH, GDAL
itself doesn't need GRASS support. Also, the GDAL library must exist
prior to compiling GRASS (i.e. you have to build GDAL before you build
GRASS).
r.out.gdal is a script which invokes the gdal_translate program, which
essentially converts maps between any two formats which GDAL supports.
In order for r.out.gdal to work, gdal_translate needs to be able to
read GRASS maps, which means that GDAL needs to have been built with
GRASS or libgrass support.
So you need to compile GRASS first, then build GDAL with GRASS
support. As r.out.gdal is a script, the GDAL library needn't exist
when GRASS was compiled; it only has to exist when you actually run
r.out.gdal.
One solution is for someone to write an r.out.gdal program which is an
inverse of r.in.gdal, i.e. which reads GRASS maps using the GRASS API
(and libraries) and writes them using GDAL. As with r.in.gdal, the
GDAL library wouldn't require GRASS/libgrass support, but it would
have to be built before GRASS.
The other solution would be to replace r.in.gdal with a script which
is the inverse of r.out.gdal, i.e. which uses gdal_translate to read
files and write GRASS maps (this assumes that GDAL's GRASS support
covers writing as well as reading). As with r.out.gdal, GDAL would
require GRASS support, but you could build it after having built
GRASS.
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-dev
mailing list