[GRASS5] set map title and metadata info using r.support

Hi,

I've added two options to r.support to let you change the map's title
and add a line of metadata info to the map's hist/ file (viewable with
r.info, r.info -h). They will both run non-interactively from the
command line.

Note that metadata comments are limited to 50 lines of 78 chars each. If
you feed it any more than that it will truncate the input to fit.
Don't count on "$? -ne 0" in the case of the line being too long!

Also represents a new challenge for the folks working on the GUI.. I
guess for now we can live with a terminal that flashes closed just after
launch if non-interactive.

I am looking for a simple bashism to add to the examples section of the
help page for feeding an input file one line at a time into the (looped)
module.

Hamish

Hamish wrote:

I've added two options to r.support to let you change the map's title
and add a line of metadata info to the map's hist/ file (viewable with
r.info, r.info -h). They will both run non-interactively from the
command line.

Given that r.support has historically been an interactive module, it
might be better to put this functionality into separate modules (which
was the approach I took with r.region).

I am looking for a simple bashism to add to the examples section of the
help page for feeding an input file one line at a time into the (looped)
module.

  while read line ; do
      r.support map="$map" history="$line"
  done < "$file"

--
Glynn Clements <glynn@gclements.plus.com>

> I've added two options to r.support to let you change the map's
> title and add a line of metadata info to the map's hist/ file
> (viewable with r.info, r.info -h). They will both run
> non-interactively from the command line.

Given that r.support has historically been an interactive module, it
might be better to put this functionality into separate modules (which
was the approach I took with r.region).

It didn't seem like it was worth the overhead for a couple lines of
code. If anything I considered merging r.timestamp into r.support. As
this wasn't a scriptable module the two new options shouldn't change any
historic use of r.support at all, just add something more and help us
on our way to getting rid of some more G_ask() calls. I agree that
r.region is best on its own.

> I am looking for a simple bashism to add to the examples section of
> the help page for feeding an input file one line at a time into the
> (looped) module.

  while read line ; do
      r.support map="$map" history="$line"
  done < "$file"

Yep, thanks. It occured to me this morning that I should use "read", it
works.

While on "read", another question: For a while I've wanted to have a
port of m.proj2 in GRASS 6, but as a script calling cs2cs. Especially
the -i and -o options to convert a list of coordinates from WGS84
lat/lon into the current projection and convert grid coords to WGS84 LL.

It's pretty easy:
IN_PROJ="+proj=longlat +towgs84=0.000,0.000,0.000"
OUT_PROJ="`g.proj -jf`"
cs2cs -f %.8f $IN_PROJ +to $OUT_PROJ < "${TMP}.in" > "${TMP}.out"

Right now I just do this by hand, but it would be great to be able to
reduce the above to "m.proj -i" plus redirection.

What I haven't been able to figure out is how to have a bash script
optionally accept input piped from stdin. My attempts using read have
been unsatisfactory. This should work the same way as both v.in.ascii
and v.out.ascii. Both input= and output= options are optional filenames or
if omitted assumed to be stdin, stdout.

e.g.
G> v.out.ascii $map | tr '|' ' ' | m.proj -o > map_LL.txt

m.proj [-iod] [input=name] [output=name] [inproj=string] [outproj=string]

Flags:
  -i Use WGS84 as input and current location as output projection
  -o Use current location as input and WGS84 as output projection
  -d Output lat/long in decimal degrees

Parameters:
    input Input coordinate file
   output Output coordinate file
   inproj input projection parameters
  outproj output projection parameters

The name of such a module is also open for suggestions.

thanks,
Hamish

Hamish wrote:

While on "read", another question: For a while I've wanted to have a
port of m.proj2 in GRASS 6, but as a script calling cs2cs. Especially
the -i and -o options to convert a list of coordinates from WGS84
lat/lon into the current projection and convert grid coords to WGS84 LL.

It's pretty easy:
IN_PROJ="+proj=longlat +towgs84=0.000,0.000,0.000"
OUT_PROJ="`g.proj -jf`"
cs2cs -f %.8f $IN_PROJ +to $OUT_PROJ < "${TMP}.in" > "${TMP}.out"

Right now I just do this by hand, but it would be great to be able to
reduce the above to "m.proj -i" plus redirection.

What I haven't been able to figure out is how to have a bash script
optionally accept input piped from stdin. My attempts using read have
been unsatisfactory. This should work the same way as both v.in.ascii
and v.out.ascii. Both input= and output= options are optional filenames or
if omitted assumed to be stdin, stdout.

Can you clarify? Are you asking about how to make redirection
conditional, or something else?

--
Glynn Clements <glynn@gclements.plus.com>

On Tue, Mar 28, 2006 at 06:30:59PM +1200, Hamish wrote:

> > I've added two options to r.support to let you change the map's
> > title and add a line of metadata info to the map's hist/ file
> > (viewable with r.info, r.info -h). They will both run
> > non-interactively from the command line.
>
> Given that r.support has historically been an interactive module, it
> might be better to put this functionality into separate modules (which
> was the approach I took with r.region).

It didn't seem like it was worth the overhead for a couple lines of
code. If anything I considered merging r.timestamp into r.support. As
this wasn't a scriptable module the two new options shouldn't change any
historic use of r.support at all, just add something more and help us
on our way to getting rid of some more G_ask() calls. I agree that
r.region is best on its own.

> > I am looking for a simple bashism to add to the examples section of
> > the help page for feeding an input file one line at a time into the
> > (looped) module.
>
> while read line ; do
> r.support map="$map" history="$line"
> done < "$file"

Yep, thanks. It occured to me this morning that I should use "read", it
works.

While on "read", another question: For a while I've wanted to have a
port of m.proj2 in GRASS 6, but as a script calling cs2cs. Especially
the -i and -o options to convert a list of coordinates from WGS84
lat/lon into the current projection and convert grid coords to WGS84 LL.

It's pretty easy:
IN_PROJ="+proj=longlat +towgs84=0.000,0.000,0.000"
OUT_PROJ="`g.proj -jf`"
cs2cs -f %.8f $IN_PROJ +to $OUT_PROJ < "${TMP}.in" > "${TMP}.out"

Right now I just do this by hand, but it would be great to be able to
reduce the above to "m.proj -i" plus redirection.

What I haven't been able to figure out is how to have a bash script
optionally accept input piped from stdin. My attempts using read have
been unsatisfactory. This should work the same way as both v.in.ascii
and v.out.ascii. Both input= and output= options are optional filenames or
if omitted assumed to be stdin, stdout.

You may want to try this:
---
#!/bin/sh
if [ "$1" != "" ]
then
  exec 0<"$1"
fi

while read line
do
  echo $line
done
---
The first parameter is an optional filename.

Huidae Cho

e.g.
G> v.out.ascii $map | tr '|' ' ' | m.proj -o > map_LL.txt

m.proj [-iod] [input=name] [output=name] [inproj=string] [outproj=string]

Flags:
  -i Use WGS84 as input and current location as output projection
  -o Use current location as input and WGS84 as output projection
  -d Output lat/long in decimal degrees

Parameters:
    input Input coordinate file
   output Output coordinate file
   inproj input projection parameters
  outproj output projection parameters

The name of such a module is also open for suggestions.

thanks,
Hamish

_______________________________________________
grass5 mailing list
grass5@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass5