[GRASSLIST:1769] r.patch color table question

I am using grayscale imagery to fill in blank areas in a color imagery set. I have used r.composite to create composite color images from the rgb channels in the color imagery. To create a corresponding color table for the grayscale imagery, I am using r.composite and specifying the grayscale image for all three channels. This works, but it seems rather inelegant.

Can anyone suggest a more efficient approach?

Thanks,
Rich

Richard W. Greenwood, PLS
Greenwood Mapping, Inc.
Rich <at> GreenwoodMap <dot> com
(307) 733-0203
http://www.GreenwoodMap.com

Richard Greenwood wrote:

I am using grayscale imagery to fill in blank areas in a color imagery set.
I have used r.composite to create composite color images from the rgb
channels in the color imagery. To create a corresponding color table for
the grayscale imagery, I am using r.composite and specifying the grayscale
image for all three channels. This works, but it seems rather inelegant.

Can anyone suggest a more efficient approach?

You could use r.reclass or r.mapcalc, but you would need to compute
the categories transformation manually. There isn't another tool which
will do the same job as running r.composite with the same map for each
of the three channels.

Bear in mind that you aren't just creating a colour table. You are
changing the category values to match the "encoding" which the colour
maps use. r.patch operates upon categories, not colours.

For a given intensity level k in the range 0 to levels-1, where
"levels" is the argument to r.composite's levels=/lev_[rgb]= options
(the default is 32), the corresponding category is:

  k + k * levels + k * levels * levels
= k * (1 + levels + levels * levels)
= k * (1 + (1 + levels) * levels)

E.g. for levels=32:

  category = k * 1057 // 1024 + 32 + 1 = 1057

For an intensity value in the range 0-255, the corresponding value of
k is given by either:

  (x + 128 / (levels - 1)) * (levels - 1) / 256
or:
  x * levels / 256

depending upon whether r.composite's -c switch was used (the former is
with -c, the latter without).

So, for the default r.composite settings (levels=32, without -c), you
should be able to use:

  r.mapcalc 'outmap = (x / 8) * 1057'

[Note: all of this relies upon integer arithmetic; don't try to
calculate or simplify any of the above using real-number arithmetic.]

--
Glynn Clements <glynn.clements@virgin.net>

Glynn,

I am afraid that I will run out of ways of says "thanks" before I run out of questions<g>. I went the r.reclass route and it works great.

Is there a source of documentation for the format of GRASS files? Specifically, I am curious about the format of the colr files.

Thanks,
Rich

At 10:37 PM 11/15/2003, Glynn Clements wrote:

Richard Greenwood wrote:

> I am using grayscale imagery to fill in blank areas in a color imagery set.
> I have used r.composite to create composite color images from the rgb
> channels in the color imagery. To create a corresponding color table for
> the grayscale imagery, I am using r.composite and specifying the grayscale
> image for all three channels. This works, but it seems rather inelegant.
>
> Can anyone suggest a more efficient approach?

You could use r.reclass or r.mapcalc, but you would need to compute
the categories transformation manually. There isn't another tool which
will do the same job as running r.composite with the same map for each
of the three channels.

Bear in mind that you aren't just creating a colour table. You are
changing the category values to match the "encoding" which the colour
maps use. r.patch operates upon categories, not colours.

For a given intensity level k in the range 0 to levels-1, where
"levels" is the argument to r.composite's levels=/lev_[rgb]= options
(the default is 32), the corresponding category is:

        k + k * levels + k * levels * levels
= k * (1 + levels + levels * levels)
= k * (1 + (1 + levels) * levels)

E.g. for levels=32:

        category = k * 1057 // 1024 + 32 + 1 = 1057

For an intensity value in the range 0-255, the corresponding value of
k is given by either:

        (x + 128 / (levels - 1)) * (levels - 1) / 256
or:
        x * levels / 256

depending upon whether r.composite's -c switch was used (the former is
with -c, the latter without).

So, for the default r.composite settings (levels=32, without -c), you
should be able to use:

        r.mapcalc 'outmap = (x / 8) * 1057'

[Note: all of this relies upon integer arithmetic; don't try to
calculate or simplify any of the above using real-number arithmetic.]

--
Glynn Clements <glynn.clements@virgin.net>

Richard W. Greenwood, PLS
Greenwood Mapping, Inc.
Rich <at> GreenwoodMap <dot> com
(307) 733-0203
http://www.GreenwoodMap.com

Richard Greenwood wrote:

Is there a source of documentation for the format of GRASS files?
Specifically, I am curious about the format of the colr files.

It's described in the Programmer's Reference Manual:

  http://mpa.itc.it/markus/grass50progman/node40.html

The full document in PDF format is at:

  http://grass.itc.it/grass5/progmangrass50.pdf

Note: that document is rather incomplete and some information may be
out of date. However, there haven't been any substantive changes to
the format of the "colr" files in the lifetime of the 5.0 CVS tree
(i.e. since 1999-12-29), so that isn't an issue here.

--
Glynn Clements <glynn.clements@virgin.net>

I'm trying to tweak out the last of my build errors on OSX. When I 'make' grass I am getting the error:

GRASS GIS source code compiled.

Compilation error in module: src/raster/r.in.gdal (ignored)

* In case of errors please check following web page for hints:
     http://grass.itc.it/grass5/source/compilation_hints.html

* Install GRASS with (possibly as root)
     make install
cp -f error.log error.log.powerpc-apple-darwin7.0.0

I'm rather perplexed on this one. My gdal config file looks like this:

./configure \
--with-grass=no \
--with-png=internal \
--with-jpeg=internal \
--with-gif=internal \
--with-libtiff=internal \
--with-geotiff=internal \
--with-libz=internal \
--without-ogr \
--without-pg \
--without-ogdi \
--without-python

My grass config file look like this:

./configure \
--with-postgres-includes=/sw/include/postgresql \
--with-postgres-libs=/sw/lib/postgresql \
--with-gdal=/urs/local/bin/gdal-config \
--with-includes=/sw/include \
--with-libs=/sw/lib \
--with-opengl-includes=/usr/X11R6/include \
--without-odbc \
--with-proj \

However, I'm still not getting a functional a grass build with a functional gdal. On the gdal web site I found the following:

"In order to run GDAL after installing it is necessary for the shared library to be findable. This can often be accomplished by setting LD_LIBRARY_PATH to include /usr/local/lib."

Is this the problem? I'm not following what is being referred to here...

Kirk R. Wythers wrote:

I'm trying to tweak out the last of my build errors on OSX. When I
'make' grass I am getting the error:

GRASS GIS source code compiled.

Compilation error in module: src/raster/r.in.gdal (ignored)

We need to see the actual error messages from the output from "make".

However, I'm still not getting a functional a grass build with a
functional gdal. On the gdal web site I found the following:

"In order to run GDAL after installing it is necessary for the shared
library to be findable. This can often be accomplished by setting
LD_LIBRARY_PATH to include /usr/local/lib."

Is this the problem?

No.

I'm not following what is being referred to here...

That comment refers to a problem which may occur when running
r.in.gdal. Your problem is with compiling it.

--
Glynn Clements <glynn.clements@virgin.net>

On Nov 18, 2003, at 11:22 AM, Glynn Clements wrote:

Kirk R. Wythers wrote:

I'm trying to tweak out the last of my build errors on OSX. When I
'make' grass I am getting the error:

GRASS GIS source code compiled.

Compilation error in module: src/raster/r.in.gdal (ignored)

We need to see the actual error messages from the output from "make".

Here is a grep for gdal in the make output. Let me know if more text of the make output would be helpfull

truffula:~/tmp/grass-5.0.3 kirkw$ grep gdal make.out
GISGEN: src/raster/r.in.gdal - Tue Nov 18 13:28:49 CST 2003
/Users/kirkw/tmp/grass-5.0.3/src/raster/r.in.gdal
gcc -L/Users/kirkw/tmp/grass-5.0.3/src/libes/LIB.powerpc-apple-darwin7.0.0 -L/sw/lib -o /Users/kirkw/tmp/grass-5.0.3/dist.powerpc-apple-darwin7.0.0/etc/bin/cmd/r.in.gdal OBJ.powerpc-apple-darwin7.0.0/main.o OBJ.powerpc-apple-darwin7.0.0/gbgetsymbol.o OBJ.powerpc-apple-darwin7.0.0/gdalbridge.o OBJ.powerpc-apple-darwin7.0.0/make_loc.o \
         /usr/local/lib/gdal.a /usr/local/lib/ogr.a /usr/local/lib/gdal.a /usr/local/lib/cpl.a -lm -ldl -lm -lproj -lgis -lintl -lI -lz
ld: table of contents for archive: /usr/local/lib/gdal.a is out of date; rerun ranlib(1) (can't load from it)
ld: table of contents for archive: /usr/local/lib/gdal.a is out of date; rerun ranlib(1) (can't load from it)
GISGEN failure at STEP: src/raster/r.in.gdal
Compilation error in module: src/raster/r.in.gdal (ignored)
truffula:~/tmp/grass-5.0.3 kirkw$

Kirk R. Wythers wrote:

>> I'm trying to tweak out the last of my build errors on OSX. When I
>> 'make' grass I am getting the error:
>>
>> GRASS GIS source code compiled.
>>
>> Compilation error in module: src/raster/r.in.gdal (ignored)
>
> We need to see the actual error messages from the output from "make".

Here is a grep for gdal in the make output. Let me know if more text of
the make output would be helpfull

I can't be sure whether the rest of the text might be helpful without
seeing it. Certainly, an error message in building r.in.gdal won't
necessarily include the string "gdal". However:

/usr/local/lib/gdal.a /usr/local/lib/cpl.a -lm -ldl -lm -lproj -lgis
-lintl -lI -lz
ld: table of contents for archive: /usr/local/lib/gdal.a is out of
date; rerun ranlib(1) (can't load from it)

This would certainly explain the failure. It indicates that the GDAL
library hasn't been built correctly. You may be able to fix the
problem by running:

  ranlib /usr/local/lib/gdal.a

--
Glynn Clements <glynn.clements@virgin.net>

On Nov 18, 2003, at 4:30 PM, Glynn Clements wrote:

Kirk R. Wythers wrote:

here is the whole section concerning gdal:

#################################################################
/Users/kirkw/tmp/grass-5.0.3/src/raster/r.in.dted/r.in.dted
   make -f OBJ.powerpc-apple-darwin7.0.0/make.rules

make[1]: Nothing to be done for `all'.

GISGEN: src/raster/r.in.gdal - Tue Nov 18 13:28:49 CST 2003

#################################################################
/Users/kirkw/tmp/grass-5.0.3/src/raster/r.in.gdal
   make -f OBJ.powerpc-apple-darwin7.0.0/make.rules

gcc
-L/Users/kirkw/tmp/grass-5.0.3/src/libes/LIB.powerpc-apple-darwin7.0.0
-L/sw/lib -o
/Users/kirkw/tmp/grass-5.0.3/dist.powerpc-apple-darwin7.0.0/etc/bin/cmd/r.in.gdal OBJ.powerpc-apple-darwin7.0.0/main.o
OBJ.powerpc-apple-darwin7.0.0/gbgetsymbol.o OBJ.powerpc-apple-darwin7.0.0/gdalbridge.o
OBJ.powerpc-apple-darwin7.0.0/make_loc.o /usr/local/lib/gdal.a /usr/local/lib/ogr.a
/usr/local/lib/gdal.a /usr/local/lib/cpl.a -lm -ldl -lm -lproj -lgis -lintl -lI -lz
ld: table of contents for archive: /usr/local/lib/gdal.a is out of
date; rerun ranlib(1) (can't load from it)
ld: table of contents for archive: /usr/local/lib/ogr.a is out of date;
rerun ranlib(1) (can't load from it)
ld: table of contents for archive: /usr/local/lib/gdal.a is out of
date; rerun ranlib(1) (can't load from it)
ld: table of contents for archive: /usr/local/lib/cpl.a is out of date;
rerun ranlib(1) (can't load from it)

This suggests a problem with building the GDAL libraries

This is the output from each ranlib:

Try:
  ranlib /usr/local/lib/gdal.a

barbaloot:~/tmp/grass-5.0.3 kirkw$ sudo ranlib /usr/local/lib/gdal.a
Password:
ranlib: file: /usr/local/lib/gdal.a(pnggccrd.o) has no symbols
ranlib: file: /usr/local/lib/gdal.a(pngvcrd.o) has no symbols
ranlib: file: /usr/local/lib/gdal.a(tif_pixarlog.o) has no symbols
ranlib: file: /usr/local/lib/gdal.a(cpl_vsil_unix_stdio_64.o) has no symbols

  ranlib /usr/local/lib/ogr.a

barbaloot:~/tmp/grass-5.0.3 kirkw$ sudo ranlib /usr/local/lib/ogr.a
ranlib: file: /usr/local/lib/ogr.a(ogrsurface.o) has no symbols

  ranlib /usr/local/lib/cpl.a

barbaloot:~/tmp/grass-5.0.3 kirkw$ sudo ranlib /usr/local/lib/cpl.a
ranlib: file: /usr/local/lib/cpl.a(cpl_vsil_unix_stdio_64.o) has no symbols

Same outcome in that gdal did not compile with grass. But, new errors in the make process:

GISGEN: src/raster/r.in.gdal - Tue Nov 18 18:35:14 CST 2003

#################################################################
/Users/kirkw/tmp/grass-5.0.3/src/raster/r.in.gdal
   make -f OBJ.powerpc-apple-darwin7.0.0/make.rules

gcc -L/Users/kirkw/tmp/grass-5.0.3/src/libes/LIB.powerpc-apple-darwin7.0.0 -L/s\
w/lib -o /Users/kirkw/tmp/grass-5.0.3/dist.powerpc-apple-darwin7.0.0/etc/bin/cm\
d/r.in.gdal OBJ.powerpc-apple-darwin7.0.0/main.o OBJ.powerpc-apple-darwin7.0.0/\
gbgetsymbol.o OBJ.powerpc-apple-darwin7.0.0/gdalbridge.o OBJ.powerpc-apple-darw\
in7.0.0/make_loc.o \
         /usr/local/lib/gdal.a /usr/local/lib/ogr.a /usr/local/lib/gdal.a /usr/l\
ocal/lib/cpl.a -lm -ldl -lm -lproj -lgis -lintl -lI -lz
ld: Undefined symbols:
___gxx_personality_v0
operator delete(void*)
operator new(unsigned long)
vtable for __cxxabiv1::__class_type_info
vtable for __cxxabiv1::__si_class_type_info
___cxa_pure_virtual
operator delete(void*)
operator new(unsigned long)
GISGEN failure at STEP: src/raster/r.in.gdal

--
Glynn Clements <glynn.clements@virgin.net>

------------------------------------------------------------------------
Kirk R. Wythers tel: 612.625.2261
Dept. of Forest Resources fax: 612.625.5212
University of Minnesota email: kwythers@umn.edu
------------------------------------------------------------------------

Kirk R. Wythers wrote:

>> here is the whole section concerning gdal:
>>
>> #################################################################
>> /Users/kirkw/tmp/grass-5.0.3/src/raster/r.in.dted/r.in.dted
>> make -f OBJ.powerpc-apple-darwin7.0.0/make.rules
>>
>> make[1]: Nothing to be done for `all'.
>>
>> GISGEN: src/raster/r.in.gdal - Tue Nov 18 13:28:49 CST 2003
>>
>> #################################################################
>> /Users/kirkw/tmp/grass-5.0.3/src/raster/r.in.gdal
>> make -f OBJ.powerpc-apple-darwin7.0.0/make.rules
>>
>> gcc
>> -L/Users/kirkw/tmp/grass-5.0.3/src/libes/LIB.powerpc-apple-darwin7.0.0
>> -L/sw/lib -o
>> /Users/kirkw/tmp/grass-5.0.3/dist.powerpc-apple-darwin7.0.0/etc/bin/
>> cmd/r.in.gdal OBJ.powerpc-apple-darwin7.0.0/main.o
>> OBJ.powerpc-apple-darwin7.0.0/gbgetsymbol.o
>> OBJ.powerpc-apple-darwin7.0.0/gdalbridge.o
>> OBJ.powerpc-apple-darwin7.0.0/make_loc.o
>> /usr/local/lib/gdal.a /usr/local/lib/ogr.a
>> /usr/local/lib/gdal.a /usr/local/lib/cpl.a -lm -ldl -lm -lproj -lgis
>> -lintl -lI -lz
>> ld: table of contents for archive: /usr/local/lib/gdal.a is out of
>> date; rerun ranlib(1) (can't load from it)
>> ld: table of contents for archive: /usr/local/lib/ogr.a is out of
>> date;
>> rerun ranlib(1) (can't load from it)
>> ld: table of contents for archive: /usr/local/lib/gdal.a is out of
>> date; rerun ranlib(1) (can't load from it)
>> ld: table of contents for archive: /usr/local/lib/cpl.a is out of
>> date;
>> rerun ranlib(1) (can't load from it)
>
> This suggests a problem with building the GDAL libraries

This is the output from each ranlib:

>
> Try:
> ranlib /usr/local/lib/gdal.a

barbaloot:~/tmp/grass-5.0.3 kirkw$ sudo ranlib /usr/local/lib/gdal.a
Password:
ranlib: file: /usr/local/lib/gdal.a(pnggccrd.o) has no symbols
ranlib: file: /usr/local/lib/gdal.a(pngvcrd.o) has no symbols
ranlib: file: /usr/local/lib/gdal.a(tif_pixarlog.o) has no symbols
ranlib: file: /usr/local/lib/gdal.a(cpl_vsil_unix_stdio_64.o) has no
symbols

> ranlib /usr/local/lib/ogr.a

barbaloot:~/tmp/grass-5.0.3 kirkw$ sudo ranlib /usr/local/lib/ogr.a
ranlib: file: /usr/local/lib/ogr.a(ogrsurface.o) has no symbols

> ranlib /usr/local/lib/cpl.a

barbaloot:~/tmp/grass-5.0.3 kirkw$ sudo ranlib /usr/local/lib/cpl.a
ranlib: file: /usr/local/lib/cpl.a(cpl_vsil_unix_stdio_64.o) has no
symbols

That shouldn't be a problem; these should just be warnings. Depending
upon the GDAL build options, those .o files may well be empty.

As the "rerun ranlib(1)" messages are absent from your latest attempt,
that particular problem appears to have been fixed.

Same outcome in that gdal did not compile with grass. But, new errors
in the make process:

GISGEN: src/raster/r.in.gdal - Tue Nov 18 18:35:14 CST 2003

#################################################################
/Users/kirkw/tmp/grass-5.0.3/src/raster/r.in.gdal
   make -f OBJ.powerpc-apple-darwin7.0.0/make.rules

gcc
-L/Users/kirkw/tmp/grass-5.0.3/src/libes/LIB.powerpc-apple-darwin7.0.0
-L/s\
w/lib -o
/Users/kirkw/tmp/grass-5.0.3/dist.powerpc-apple-darwin7.0.0/etc/bin/cm\
d/r.in.gdal OBJ.powerpc-apple-darwin7.0.0/main.o
OBJ.powerpc-apple-darwin7.0.0/\
gbgetsymbol.o OBJ.powerpc-apple-darwin7.0.0/gdalbridge.o
OBJ.powerpc-apple-darw\
in7.0.0/make_loc.o \
         /usr/local/lib/gdal.a /usr/local/lib/ogr.a
/usr/local/lib/gdal.a /usr/l\
ocal/lib/cpl.a -lm -ldl -lm -lproj -lgis -lintl -lI -lz
ld: Undefined symbols:
___gxx_personality_v0
operator delete(void*)
operator new(unsigned long)
vtable for __cxxabiv1::__class_type_info
vtable for __cxxabiv1::__si_class_type_info
___cxa_pure_virtual
operator delete(void*)
operator new(unsigned long)

OK. I believe that this is because you need some additional switches
when linking against C++ code (most of GDAL is C++).

It may suffice to replace "gcc" with "g++" in the link command. Either
by running the above command manually, but substituting "g++" for
"gcc", or by editing src/raster/r.in.gdal/Gmakefile, changing $(CC) to
"g++".

Typically, there would be a standard library (or even a simple object
file) which defines the above symbols, and using g++ as the linker
will use that library (or object file) automatically.

E.g. on Linux, C++ programs use libstdc++. Linking with "g++"
automatically implies "-lstdc++"; if you link with "gcc", you have to
explicitly add "-lstdc++" to the link command.

Note: this issue doesn't normally arise for shared libraries, as they
typically include dependency information, so the linker will add any
dependent libraries automatically.

I suppose that the gdal-config script should really deal with this.

--
Glynn Clements <glynn.clements@virgin.net>

On Nov 19, 2003, at 2:19 AM, Glynn Clements wrote:

OK. I believe that this is because you need some additional switches
when linking against C++ code (most of GDAL is C++).

It may suffice to replace "gcc" with "g++" in the link command. Either
by running the above command manually, but substituting "g++" for
"gcc", or by editing src/raster/r.in.gdal/Gmakefile, changing $(CC) to
"g++".

Typically, there would be a standard library (or even a simple object
file) which defines the above symbols, and using g++ as the linker
will use that library (or object file) automatically.

E.g. on Linux, C++ programs use libstdc++. Linking with "g++"
automatically implies "-lstdc++"; if you link with "gcc", you have to
explicitly add "-lstdc++" to the link command.

Note: this issue doesn't normally arise for shared libraries, as they
typically include dependency information, so the linker will add any
dependent libraries automatically.

I'll be damned... that did it Glynn. I have not used it yet but the compile finished without any errors. Just for the sake of the continued pursuit of knowledge, why was this an issue on my machine and not for others (who appeared... superficially at least, to be building on the same/similar hardware and os (OSX 10.3.1, gcc 3.3 from xtools)?

Thank you

I suppose that the gdal-config script should really deal with this.

--
Glynn Clements <glynn.clements@virgin.net>

------------------------------------------------------------------------
Kirk R. Wythers tel: 612.625.2261
Dept. of Forest Resources fax: 612.625.5212
University of Minnesota email: kwythers@umn.edu
------------------------------------------------------------------------

Kirk R. Wythers wrote:

> OK. I believe that this is because you need some additional switches
> when linking against C++ code (most of GDAL is C++).
>
> It may suffice to replace "gcc" with "g++" in the link command. Either
> by running the above command manually, but substituting "g++" for
> "gcc", or by editing src/raster/r.in.gdal/Gmakefile, changing $(CC) to
> "g++".
>
> Typically, there would be a standard library (or even a simple object
> file) which defines the above symbols, and using g++ as the linker
> will use that library (or object file) automatically.
>
> E.g. on Linux, C++ programs use libstdc++. Linking with "g++"
> automatically implies "-lstdc++"; if you link with "gcc", you have to
> explicitly add "-lstdc++" to the link command.
>
> Note: this issue doesn't normally arise for shared libraries, as they
> typically include dependency information, so the linker will add any
> dependent libraries automatically.

I'll be damned... that did it Glynn. I have not used it yet but the
compile finished without any errors. Just for the sake of the continued
pursuit of knowledge, why was this an issue on my machine and not for
others (who appeared... superficially at least, to be building on the
same/similar hardware and os (OSX 10.3.1, gcc 3.3 from xtools)?

I don't know, for sure; people who don't have any problems don't
generally post "make" output for me to see, so I don't know exactly
what was happening on such systems.

It may be that the others had a shared GDAL library; shared libraries
include dependency information, so the linker will automatically add
the necessary libraries. Or it may be that their gdal-config script
includes the additional switches in the "gdal-config --libs" output.

--
Glynn Clements <glynn.clements@virgin.net>