[STATSGRASS] Re: gmeta6() returns empty string
Roger Bivand
Roger.Bivand at nhh.no
Wed Feb 28 06:47:54 EST 2007
On Wed, 28 Feb 2007, Tilmann Steinmetz wrote:
> Thanks Roger and Hamish,
>
> I tried g.gisenv (good) and made an attempt with debug(gmeta6())
> (unsuccessful)- output below. I am not aware of FreeBSD doing anything weird
> in exporting paths or environment variables in general. My shell is sh but I
> tried using bash too (same thing)
>
> However, these 2 things came to my mind:
>
> 1.) using g.region -d from within Grass (be it grass62 -text or the tcl-gui)
> I get an empty string- this is wrong if I understand right? should (and can)
> that be remediated? is this the cause of all this trouble?
Why g.region -d anyway? This just resets the current region to the
default, nothing more.
>
> 2.) if LD_LIBRARY_PATH (or the lack thereof) is to be blamed, then is there
> a way to force the R environment to "inherit" from its parent environment
> using something like > system("source .bashrc") within R? but then that
> again could probably only get the "grass g.region -d" empty string.
>
No. GRASS has its own, that is set up when GRASS initiates. That was the
one that was generating the:
/libexec/ld-elf.so.1: v.info: Undefined symbol "G_gettext"
type of messages before. The correct one was being used in the GRASS
shell, but something was going wrong later on.
Please start grass -text, say:
echo $LD_LIBRARY_PATH
echo $GISRC
g.gisenv
then start R from that prompt and say:
Sys.getenv("LD_LIBRARY_PATH")
Sys.getenv("GISRC")
system("g.gisenv")
Once we find out why your GRASS and R and shell and environment
variables installations are broken when working together on FreeBSD, the
rest will follow. system() inside R is simply not seeing the same
environment that the shell outside is seeing. My guess is that your R
installation is *overwriting* LD_LIBRARY_PATH rather than pre-pending the
R-specific libraries.
Roger
> (why is g.region -d used in the first place, if g.region -g could be used? -
> that was my first try: replace gmeta6() with a function thats identical to
> it, but calls "g.region -g3", which failed because somewhere in the process
> some function call goes to g.region -d again..)
>
> g.gisenv seems Ok:
> **********************************************************************
> Welcome to GRASS 6.2.1 (2006)
> GRASS homepage: http://grass.itc.it/
> This version running thru: Bourne Shell (/bin/sh)
> Help is available with the command: g.manual -i
> See the licence terms with: g.version -c
> Start the graphical user interface with: gis.m &
> When ready to quit enter: exit
>
> Mapset <user1> in Location <spearfish60>
> GRASS-GRID > g.gisenv
> LOCATION_NAME=spearfish60
> MAPSET=user1
> DIGITIZER=none
> GISDBASE=/usr/home/tilmann/GIS_data
> MONITOR=x0
> GRASS_GUI=text
>
> Mapset <user1> in Location <spearfish60>
> GRASS-GRID > eval `g.gisenv`
>
> Mapset <user1> in Location <spearfish60>
> GRASS-GRID > cat "$GISDBASE/$LOCATION_NAME"/PERMANENT/DEFAULT_WIND
> proj: 1
> zone: 13
> north: 4928010
> south: 4913700
> east: 609000
> west: 589980
> cols: 634
> rows: 477
> e-w resol: 30
> n-s resol: 30
> top: 1
> bottom: 0
> cols3: 634
> rows3: 477
> depths: 1
> e-w resol3: 30
> n-s resol3: 30
> t-b resol: 1
>
> Mapset <user1> in Location <spearfish60>
> GRASS-GRID >
>
> **********************************************************************
> whereas debugging shows that gmeta6() stops right away at the first
> evaluation of the "g.region -g3" expression:
> **********************************************************************
>
> > debug(gmeta6())
> debugging in: gmeta6()
> debug: {
> tull <- ifelse(.Platform$OS.type == "windows", tx <-
> system("g.region -g3",
> intern = TRUE), tx <- system("g.region -g3", intern = TRUE,
> ignore.stderr = ignore.stderr))
> tx <- gsub("=", ":", tx)
> con <- textConnection(tx)
> res <- read.dcf(con)
> close(con)
> lres <- as.list(res)
> names(lres) <- colnames(res)
> lres$n <- as.double(lres$n)
> lres$s <- as.double(lres$s)
> lres$w <- as.double(lres$w)
> lres$e <- as.double(lres$e)
> lres$t <- as.double(lres$t)
> lres$b <- as.double(lres$b)
> lres$nsres <- as.double(lres$nsres)
> lres$nsres3 <- as.double(lres$nsres3)
> lres$ewres <- as.double(lres$ewres)
> lres$ewres3 <- as.double(lres$ewres3)
> lres$tbres <- as.double(lres$tbres)
> if (length(lres$rows) == 0)
> lres$rows <- abs(as.integer((lres$n - lres$s)/lres$nsres))
> else lres$rows <- as.integer(lres$rows)
> if (length(lres$rows3) == 0)
> lres$rows3 <- lres$rows
> else lres$rows3 <- as.integer(lres$rows3)
> if (length(lres$cols) == 0)
> lres$cols <- abs(as.integer((lres$e - lres$w)/lres$ewres))
> else lres$cols <- as.integer(lres$cols)
> if (length(lres$cols3) == 0)
> lres$cols3 <- lres$cols
> else lres$cols3 <- as.integer(lres$cols3)
> if (length(lres$depths) == 0)
> lres$depths <- abs(as.integer((lres$t - lres$b)/lres$tbres))
> else lres$depths <- as.integer(lres$depths)
> lres$proj4 <- getLocationProj()
> tull <- ifelse(.Platform$OS.type == "windows", gisenv <-
> system("g.gisenv",
> intern = TRUE), gisenv <- system("g.gisenv", intern = TRUE,
> ignore.stderr = ignore.stderr))
> gisenv <- gsub("[';]", "", gisenv)
> gisenv <- strsplit(gisenv, "=")
> glist <- as.list(sapply(gisenv, function(x) x[2]))
> names(glist) <- sapply(gisenv, function(x) x[1])
> lres <- c(glist, lres)
> class(lres) <- "gmeta6"
> lres
> }
> Browse[1]>
> debug: tull <- ifelse(.Platform$OS.type == "windows", tx <-
> system("g.region -g3",
> intern = TRUE), tx <- system("g.region -g3", intern = TRUE,
> ignore.stderr = ignore.stderr))
> Browse[1]>
> ERROR: default region is invalid
> line 11: <top: 1>
> debug: tx <- gsub("=", ":", tx)
> Browse[1]>
> debug: con <- textConnection(tx)
> Browse[1]>
> debug: res <- read.dcf(con)
> Browse[1]>
> debug: close(con)
> Browse[1]>
> debug: lres <- as.list(res)
> Browse[1]>
> debug: names(lres) <- colnames(res)
> Browse[1]>
> debug: lres$n <- as.double(lres$n)
> Browse[1]>
> debug: lres$s <- as.double(lres$s)
> Browse[1]>
> debug: lres$w <- as.double(lres$w)
> Browse[1]>
> debug: lres$e <- as.double(lres$e)
> Browse[1]>
> debug: lres$t <- as.double(lres$t)
> Browse[1]>
> debug: lres$b <- as.double(lres$b)
> Browse[1]>
> debug: lres$nsres <- as.double(lres$nsres)
> Browse[1]>
> debug: lres$nsres3 <- as.double(lres$nsres3)
> Browse[1]>
> debug: lres$ewres <- as.double(lres$ewres)
> Browse[1]>
> debug: lres$ewres3 <- as.double(lres$ewres3)
> Browse[1]>
> debug: lres$tbres <- as.double(lres$tbres)
> Browse[1]>
> debug: if (length(lres$rows) == 0) lres$rows <- abs(as.integer((lres$n -
> lres$s)/lres$nsres)) else lres$rows <- as.integer(lres$rows)
> Browse[1]>
> debug: if (length(lres$rows3) == 0) lres$rows3 <- lres$rows else lres$rows3
> <- as.integer(lres$rows3)
> Browse[1]>
> debug: if (length(lres$cols) == 0) lres$cols <- abs(as.integer((lres$e -
> lres$w)/lres$ewres)) else lres$cols <- as.integer(lres$cols)
> Browse[1]>
> debug: if (length(lres$cols3) == 0) lres$cols3 <- lres$cols else lres$cols3
> <- as.integer(lres$cols3)
> Browse[1]>
> debug: if (length(lres$depths) == 0) lres$depths <- abs(as.integer((lres$t -
> lres$b)/lres$tbres)) else lres$depths <- as.integer(lres$depths)
> Browse[1]>
> debug: lres$proj4 <- getLocationProj()
> Browse[1]>
> /libexec/ld-elf.so.1: g.proj: Undefined symbol "G_gettext"
> Error in if (is.na(projstr)) uprojargs <- projstr else uprojargs <-
> paste(unique(unlist(strsplit(projstr, :
> argument is of length zero
> >
> **********************************************************************
> I'm at a loss here. As I said I could live with "manually" assigning the
> correct projection and/or environment from within R- just don't get it done.
> I faintly remember seeing something like it being used at a time before
> gmeta() was there- or am I wrong?
>
> Thanks,
> Tilmann
>
> **************************************************************************
>
> Am Dienstag 27 Februar 2007 22:26 schrieb Roger Bivand:
> > Yesterday 22:26:14
> >
> >
> > On Tue, 27 Feb 2007, Tilmann Steinmetz wrote:
> > > Am Dienstag 27 Februar 2007 21:07 schrieb Roger Bivand:
> > > > On Tue, 27 Feb 2007, Tilmann Steinmetz wrote:
> > > > > Hi,
> > > > >
> > > > > I am having difficulties getting the region environment settings
> from
> > > > > grass into R using gmeta6() (see output below).
> > > >
> > > > If your LOCATION is spearfish*, the examples should work. I am not
> > > > aware of any reason why FreeBSD should not work normally. Do you
> > > > actually need gmeta6(), it is pretty deprecated now? Do readVECT6() or
> > > > readRAST6() work?
> > >
> > > oh, I see!
> > >
> > > > It looks like a PATH/GRASSRC issue of some kind, where debugging at a
> > > > distance is not an option. What does:
> > > >
> > > > Sys.getenv("GISRC")
> > > >
> > > > say?
> > >
> > > it's just the same with those:
> > > > system("v.info bugsites")
> > >
> > > /libexec/ld-elf.so.1: v.info: Undefined symbol "G_gettext"
> >
> > This is saying that when you try to run v.info, the underlying GRASS
> > module is failing. There is *no* compiled code in spgrass6, so anything
> > passed through system() should just work. Yours doesn't, you have a pretty
> > non-standard system, so you have to work out why the GRASS shared
> > libraries are not being seen by GRASS compiled modules when run from with
> > R, but can apparently be seen when you leave R in the same shell.
> >
> > So:
> >
> > you open a terminal; you start GRASS -text in the terminal in your
> > location; g.region -g works; you start R at the GRASS shell prompt
> > in that terminal; system("g.region -g") does not work; q(); and g.region
> > -g works again. This is FreeBSD shell layering of some kind, or
> > LD_LIBRARY_* not being exported across shell instances. Are you running
> > bash or sh or csh?
> >
> > To understand debug, ?debug
> >
> > Roger
>
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no
More information about the grass-stats
mailing list