[GRASS-dev] g.region print flags combination

Hi,

I rewrote the previous patch for g.region -- see [1], this patch
allows to combine several print flags. The flag '-g' can be used in
combination with all print flags. E.g.

GRASS 6.3.cvs (spearfish60):~ > g.region -pmce
projection : 1 (UTM)
zone : 13
datum : nad27
ellipsoid : clark66
north : 4928010
south : 4913700
west : 589980
east : 609000
nsres : 30
ewres : 30
rows : 477
cols : 634
cells : 302418
north-south extent : 14310.000000
east-west extent : 19020.000000
north-south center : 4920855.000000
east-west center : 599490.000000

or

GRASS 6.3.cvs (spearfish60):~ > g.region -plg
projection=1
zone=13
datum=nad27
ellipsoid=clark66
n=4928010
s=4913700
w=589980
e=609000
nsres=30
ewres=30
rows=477
cols=634
cells=302418
nw_long=-103.86814463
nw_lat=44.50175140
ne_long=-103.62895492
ne_lat=44.49913014
se_long=-103.63196347
se_lat=44.37033545
sw_long=-103.87062861
sw_lat=44.37294503
center_long=-103.74992291
center_lat=44.43604050

I waiting for you comments, then I will commit it to CVS (now it can
be a little bit buggy).

Best regards, Martin

[1] http://grass.itc.it/pipermail/grass-dev/2006-September/026002.html

--
Martin Landa <landa.martin@gmail.com> * http://gama.fsv.cvut.cz/~landa *

(attachments)

g_region_print_flags.diff.gz (5.99 KB)

On Fri, 2006-12-22 at 22:56 +0100, Martin Landa wrote:

Hi,

I rewrote the previous patch for g.region -- see [1], this patch
allows to combine several print flags. The flag '-g' can be used in
combination with all print flags. E.g.

GRASS 6.3.cvs (spearfish60):~ > g.region -pmce
projection : 1 (UTM)
zone : 13
datum : nad27
ellipsoid : clark66
north : 4928010
south : 4913700
west : 589980
east : 609000
nsres : 30
ewres : 30
rows : 477
cols : 634
cells : 302418
north-south extent : 14310.000000
east-west extent : 19020.000000
north-south center : 4920855.000000
east-west center : 599490.000000

or

GRASS 6.3.cvs (spearfish60):~ > g.region -plg
projection=1
zone=13
datum=nad27
ellipsoid=clark66
n=4928010
s=4913700
w=589980
e=609000
nsres=30
ewres=30
rows=477
cols=634
cells=302418
nw_long=-103.86814463
nw_lat=44.50175140
ne_long=-103.62895492
ne_lat=44.49913014
se_long=-103.63196347
se_lat=44.37033545
sw_long=-103.87062861
sw_lat=44.37294503
center_long=-103.74992291
center_lat=44.43604050

I waiting for you comments, then I will commit it to CVS (now it can
be a little bit buggy).

Best regards, Martin

[1] http://grass.itc.it/pipermail/grass-dev/2006-September/026002.html

A quick review looks good to me. Great work.

--
Brad Douglas <rez touchofmadness com> KB8UYR/6
Address: 37.493,-121.924 / WGS84 National Map Corps #TNMC-3785

On Dec 22, 2006, at 4:56 PM, Martin Landa wrote:

Hi,

I rewrote the previous patch for g.region -- see [1], this patch
allows to combine several print flags. The flag '-g' can be used in
combination with all print flags. E.g.

GRASS 6.3.cvs (spearfish60):~ > g.region -pmce
projection : 1 (UTM)
zone : 13
datum : nad27
ellipsoid : clark66
north : 4928010
south : 4913700
west : 589980
east : 609000
nsres : 30
ewres : 30
rows : 477
cols : 634
cells : 302418
north-south extent : 14310.000000
east-west extent : 19020.000000

the below sounds a little confusing - maybe using the same as you have for
long, lat would be better:

center_northing
center_easting

rather than

north-south center : 4920855.000000
east-west center : 599490.000000

Helena

or

GRASS 6.3.cvs (spearfish60):~ > g.region -plg
projection=1
zone=13
datum=nad27
ellipsoid=clark66
n=4928010
s=4913700
w=589980
e=609000
nsres=30
ewres=30
rows=477
cols=634
cells=302418
nw_long=-103.86814463
nw_lat=44.50175140
ne_long=-103.62895492
ne_lat=44.49913014
se_long=-103.63196347
se_lat=44.37033545
sw_long=-103.87062861
sw_lat=44.37294503
center_long=-103.74992291
center_lat=44.43604050

I waiting for you comments, then I will commit it to CVS (now it can
be a little bit buggy).

Best regards, Martin

[1] http://grass.itc.it/pipermail/grass-dev/2006-September/026002.html

--
Martin Landa <landa.martin@gmail.com> * http://gama.fsv.cvut.cz/~landa *
<g_region_print_flags.diff.gz>
_______________________________________________
grass-dev mailing list
grass-dev@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass-dev

Hi,

2006/12/23, Helena Mitasova <hmitaso@unity.ncsu.edu>:

[snip]

> north-south extent : 14310.000000
> east-west extent : 19020.000000

the below sounds a little confusing - maybe using the same as you
have for
long, lat would be better:

center_northing
center_easting

rather than

> north-south center : 4920855.000000
> east-west center : 599490.000000

thanks for your comments, I also forgot to mention that in LL
locations -p flag formats values into D:M:S and -g into D.ms.

Martin

Helena

>
> or
>
> GRASS 6.3.cvs (spearfish60):~ > g.region -plg
> projection=1
> zone=13
> datum=nad27
> ellipsoid=clark66
> n=4928010
> s=4913700
> w=589980
> e=609000
> nsres=30
> ewres=30
> rows=477
> cols=634
> cells=302418
> nw_long=-103.86814463
> nw_lat=44.50175140
> ne_long=-103.62895492
> ne_lat=44.49913014
> se_long=-103.63196347
> se_lat=44.37033545
> sw_long=-103.87062861
> sw_lat=44.37294503
> center_long=-103.74992291
> center_lat=44.43604050
>
> I waiting for you comments, then I will commit it to CVS (now it can
> be a little bit buggy).
>
> Best regards, Martin
>
> [1] http://grass.itc.it/pipermail/grass-dev/2006-September/026002.html
>
> --
> Martin Landa <landa.martin@gmail.com> * http://gama.fsv.cvut.cz/
> ~landa *
> <g_region_print_flags.diff.gz>
> _______________________________________________
> grass-dev mailing list
> grass-dev@grass.itc.it
> http://grass.itc.it/mailman/listinfo/grass-dev

--
Martin Landa <landa.martin@gmail.com> * http://gama.fsv.cvut.cz/~landa *

Hi,

thanks for contribution, committed to CVS.

Best regards, Martin

2006/12/23, Martin Landa <landa.martin@gmail.com>:

Hi,

2006/12/23, Helena Mitasova <hmitaso@unity.ncsu.edu>:

[snip]

> > north-south extent : 14310.000000
> > east-west extent : 19020.000000
>
> the below sounds a little confusing - maybe using the same as you
> have for
> long, lat would be better:
>
> center_northing
> center_easting
>
> rather than
>
> > north-south center : 4920855.000000
> > east-west center : 599490.000000

thanks for your comments, I also forgot to mention that in LL
locations -p flag formats values into D:M:S and -g into D.ms.

Martin

> Helena
>
> >
> > or
> >
> > GRASS 6.3.cvs (spearfish60):~ > g.region -plg
> > projection=1
> > zone=13
> > datum=nad27
> > ellipsoid=clark66
> > n=4928010
> > s=4913700
> > w=589980
> > e=609000
> > nsres=30
> > ewres=30
> > rows=477
> > cols=634
> > cells=302418
> > nw_long=-103.86814463
> > nw_lat=44.50175140
> > ne_long=-103.62895492
> > ne_lat=44.49913014
> > se_long=-103.63196347
> > se_lat=44.37033545
> > sw_long=-103.87062861
> > sw_lat=44.37294503
> > center_long=-103.74992291
> > center_lat=44.43604050
> >
> > I waiting for you comments, then I will commit it to CVS (now it can
> > be a little bit buggy).
> >
> > Best regards, Martin
> >
> > [1] http://grass.itc.it/pipermail/grass-dev/2006-September/026002.html
> >
> > --
> > Martin Landa <landa.martin@gmail.com> * http://gama.fsv.cvut.cz/
> > ~landa *
> > <g_region_print_flags.diff.gz>
> > _______________________________________________
> > grass-dev mailing list
> > grass-dev@grass.itc.it
> > http://grass.itc.it/mailman/listinfo/grass-dev
>

--
Martin Landa <landa.martin@gmail.com> * http://gama.fsv.cvut.cz/~landa *

--
Martin Landa <landa.martin@gmail.com> * http://gama.fsv.cvut.cz/~landa *

Hi Martin!

Thanks for cleaning up g.region. Unfortunately, it seems that in the
process you have accidently removed a feature - it is now impossible to
use "g.region -g" alone anymore - one has to call it in combination
with other flags now.

Although your approach is good, currently it breaks some GRASS scripts
using "g.region -g", eg. d.out.gpsdrive, r.plane, r.shaded.relief,
r.tileset and unknown number of user scripts. I suggest to revert this
change and leave it for GRASS 7.

Regards and thanks.

Maciek

Hi Maciek,

sorry, you are right. I will fix it as soon as possible.

Regards, Martin

2007/1/1, Maciej Sieczka <tutey@o2.pl>:

Hi Martin!

Thanks for cleaning up g.region. Unfortunately, it seems that in the
process you have accidently removed a feature - it is now impossible to
use "g.region -g" alone anymore - one has to call it in combination
with other flags now.

Although your approach is good, currently it breaks some GRASS scripts
using "g.region -g", eg. d.out.gpsdrive, r.plane, r.shaded.relief,
r.tileset and unknown number of user scripts. I suggest to revert this
change and leave it for GRASS 7.

Regards and thanks.

Maciek

--
Martin Landa <landa.martin@gmail.com> * http://gama.fsv.cvut.cz/~landa *

Hi,

I hope, now it is fixed in CVS.

Martin

2007/1/1, Martin Landa <landa.martin@gmail.com>:

Hi Maciek,

sorry, you are right. I will fix it as soon as possible.

Regards, Martin

2007/1/1, Maciej Sieczka <tutey@o2.pl>:
> Hi Martin!
>
> Thanks for cleaning up g.region. Unfortunately, it seems that in the
> process you have accidently removed a feature - it is now impossible to
> use "g.region -g" alone anymore - one has to call it in combination
> with other flags now.
>
> Although your approach is good, currently it breaks some GRASS scripts
> using "g.region -g", eg. d.out.gpsdrive, r.plane, r.shaded.relief,
> r.tileset and unknown number of user scripts. I suggest to revert this
> change and leave it for GRASS 7.
>
> Regards and thanks.
>
> Maciek
>

--
Martin Landa <landa.martin@gmail.com> * http://gama.fsv.cvut.cz/~landa *

--
Martin Landa <landa.martin@gmail.com> * http://gama.fsv.cvut.cz/~landa *

Martin Landa wrote:

Hi,

I hope, now it is fixed in CVS.

Martin,

"g.region -g" works OK now, but it prints a WARNING message on the top.
It also prints few extra lines, compared to before, namely:

projection=1
zone=34
datum=wgs84
ellipsoid=wgs84

Your WARNING message is correct and desired, as well as the extra info
is usefull, but those several additional lines might brake some user's
scripts.

Unless the script parses the "g.region -g" output something like "eval
`g.region -g`", it might fail to parse it as intended. And although
using eval in scripts is the best option, we shouldn't assume the user
doesn't do it some other way.

E.g my r.surf.nnbathy parses "g.region -g" with awk instead of eval,
because I din't know eval when I was writing the script. I only knew
how to do it with awk, and it worked fine (anyway, a fixed version
using eval should be online tonight).

See also
http://www.nabble.com/r.sum---parsable-for-shell-scripts-tf2707790.html#a7549849

I'd like to ask GRASS folks what you think about it - should the
"g.region -g" output change during the GRASS 6.3? I guess these changes
should wait for 7.

Cheers,
Maciek

Hi,

2007/1/2, Maciej Sieczka <tutey@o2.pl>:

"g.region -g" works OK now, but it prints a WARNING message on the top.
It also prints few extra lines, compared to before, namely:

projection=1
zone=34
datum=wgs84
ellipsoid=wgs84

Your WARNING message is correct and desired, as well as the extra info
is usefull, but those several additional lines might brake some user's
scripts.

So should I disable this warning, right?

I think the additional lines would not break any scripts, which parse
`g.region -g` output in a reasonable way (eval, awk) (?).

Regards, Martin

Unless the script parses the "g.region -g" output something like "eval
`g.region -g`", it might fail to parse it as intended. And although
using eval in scripts is the best option, we shouldn't assume the user
doesn't do it some other way.

E.g my r.surf.nnbathy parses "g.region -g" with awk instead of eval,
because I din't know eval when I was writing the script. I only knew
how to do it with awk, and it worked fine (anyway, a fixed version
using eval should be online tonight).

See also
http://www.nabble.com/r.sum---parsable-for-shell-scripts-tf2707790.html#a7549849

I'd like to ask GRASS folks what you think about it - should the
"g.region -g" output change during the GRASS 6.3? I guess these changes
should wait for 7.

Cheers,
Maciek

--
Martin Landa <landa.martin@gmail.com> * http://gama.fsv.cvut.cz/~landa *

Martin Landa wrote:

2007/1/2, Maciej Sieczka <tutey@o2.pl>:

"g.region -g" works OK now, but it prints a WARNING message on the top.
It also prints few extra lines, compared to before, namely:

projection=1
zone=34
datum=wgs84
ellipsoid=wgs84

Your WARNING message is correct and desired, as well as the extra info
is usefull, but those several additional lines might brake some user's
scripts.

So should I disable this warning, right?

I guess so. But somebody more knowledgable should decide.

I think the additional lines would not break any scripts, which parse
`g.region -g` output in a reasonable way (eval, awk) (?).

Those extra lines might brake all scripts that don't use eval, I
suppose. Eg. parsing with awk by line number will fail now:

# grab the current region settings
g.region -g > $TMP.${PROG}.region

# extract variables from the grabbed region
north=`awk 'BEGIN {FS="="} (NR==1) {print $2}' $TMP.${PROG}.region`
south=`awk 'BEGIN {FS="="} (NR==2) {print $2}' $TMP.${PROG}.region`
west=`awk 'BEGIN {FS="="} (NR==3) {print $2}' $TMP.${PROG}.region`
east=`awk 'BEGIN {FS="="} (NR==4) {print $2}' $TMP.${PROG}.region`
nsres=`awk 'BEGIN {FS="="} (NR==5) {print $2}' $TMP.${PROG}.region`
ewres=`awk 'BEGIN {FS="="} (NR==6) {print $2}' $TMP.${PROG}.region`
rows=`awk 'BEGIN {FS="="} (NR==7) {print $2}' $TMP.${PROG}.region`
cols=`awk 'BEGIN {FS="="} (NR==8) {print $2}' $TMP.${PROG}.region`

Is that "reasonable" I don't know, but it used to work with g.region -g
before your recent changes, and now it fails, because top 4 lines of
g.region -g output are different now.

I personally don't care too much, I have fixed my script to use eval,
but what with other users?

I absolutely agree you are doing a Good Thing fixing g.region -g as you
do, but I'm affraid it should wait till GRASS 7, for legacy reasons.

Maciek

Hi all,

I would like to summarize all complication with the new behaviour of
g.region. I would like also to ask you some question, to fix and close
this issue finally;-)

1) The -g flag can be used in combination with all print flags, e.g.

g.region -cg

I think it is without problem. There was idea to add a new flag for
shell script style. I hope it is possible to use the -g flag for this
work as well.

2) It is possible to mix print flags, e.g.

g.region -pc

or for parsable output

g.region -pcg

There should not be any problem.

3) The -p flag was changed.

projection: 99 (Krovak)
zone: 0
datum: towgs84=570.8,85.7,462.8,4.998,1.587,5.261,3.56

->

projection : 99 (Krovak)
zone : 0
datum : towgs84=570.8,85.7,462.8,4.998,1.587,5.261,3.56

Not sure what formatting is more appropriate.

4) g.region -g X g.region -pg --- I wanted to make -g flag more
universal, e.g. to distinguish

g.region -pcl
g.region -cl

and

g.region -pclg instead of g.region -gcl <-- problem
g.region -gcl <-- problem

The question of the warning in `g.region -g` -- it can be printed at
the end of the output or removed.

5) New lines in shell script style output, I think this modification
can be done in 6.x branch.

These lines can be added to the end of the output for backward
compability -- OK?

Thanks for feedback!

Regards, Martin

2007/1/2, Maciej Sieczka <tutey@o2.pl>:

Martin Landa wrote:

> 2007/1/2, Maciej Sieczka <tutey@o2.pl>:
>
>> "g.region -g" works OK now, but it prints a WARNING message on the top.
>> It also prints few extra lines, compared to before, namely:
>>
>> projection=1
>> zone=34
>> datum=wgs84
>> ellipsoid=wgs84
>>
>> Your WARNING message is correct and desired, as well as the extra info
>> is usefull, but those several additional lines might brake some user's
>> scripts.
>
> So should I disable this warning, right?

I guess so. But somebody more knowledgable should decide.

> I think the additional lines would not break any scripts, which parse
> `g.region -g` output in a reasonable way (eval, awk) (?).

Those extra lines might brake all scripts that don't use eval, I
suppose. Eg. parsing with awk by line number will fail now:

# grab the current region settings
g.region -g > $TMP.${PROG}.region

# extract variables from the grabbed region
north=`awk 'BEGIN {FS="="} (NR==1) {print $2}' $TMP.${PROG}.region`
south=`awk 'BEGIN {FS="="} (NR==2) {print $2}' $TMP.${PROG}.region`
west=`awk 'BEGIN {FS="="} (NR==3) {print $2}' $TMP.${PROG}.region`
east=`awk 'BEGIN {FS="="} (NR==4) {print $2}' $TMP.${PROG}.region`
nsres=`awk 'BEGIN {FS="="} (NR==5) {print $2}' $TMP.${PROG}.region`
ewres=`awk 'BEGIN {FS="="} (NR==6) {print $2}' $TMP.${PROG}.region`
rows=`awk 'BEGIN {FS="="} (NR==7) {print $2}' $TMP.${PROG}.region`
cols=`awk 'BEGIN {FS="="} (NR==8) {print $2}' $TMP.${PROG}.region`

Is that "reasonable" I don't know, but it used to work with g.region -g
before your recent changes, and now it fails, because top 4 lines of
g.region -g output are different now.

I personally don't care too much, I have fixed my script to use eval,
but what with other users?

I absolutely agree you are doing a Good Thing fixing g.region -g as you
do, but I'm affraid it should wait till GRASS 7, for legacy reasons.

Maciek

--
Martin Landa <landa.martin@gmail.com> * http://gama.fsv.cvut.cz/~landa *

Martin,

I support your goals in making the output from g.region more consistent and
more informative. Now that everyone is communicating, I think we can all
sync things. We'll have to go through scripts to make sure that they are not
broken. Keeping the -g flag working by itself in the old way might make this
less of an issue.

If I understand this correctly, all g.region output will default to the new
-p style, unless modified by the -g flag. If modified by the -g flag, it
will be output in 'script' style.

Here are some general principles to make 'script' style more parsable by
scripts. Hopefully these can serve as guidelines for cleanup of other
commands like you did with g.region.

1. All output should be in the form of [key][separator][value]

2. The [key] should be the same for a given command in 'script' format,
regardless of what other modifier is used or the environment in which it is
used. That is, for 'script' style, [key] should not be "e" in one setting
and "east" in another. The same [key] should be formatted the same
regardless of the location setting (i.e., UTM vs latlon vs XY)

3. The [separator] should be the same in ALL commands using a 'script' style
output. Currently, the "=" is most widely used. It should be used in ALL
commands with 'script' style output.

4. The [value] should be in the same format regardless the location
environment or any other context. A script may not know a priori whether the
user is in a UTM or latlon environment. In fact, it may be trying to get
this information from the GRASS command. It would certainly be nice if ALL
commands that accepted coordinate input could read both decimal degrees and
DD:MM:SS formats.

5. There should be no spaces or other extraneous characters between
[key][separator][value], or at the end or beginning of this string.

6. There should be no warnings or other extraneous text printed with
'script' format. The assumption is that script format is not designed for
humans to read (although they certainly can, of course). If it fails for
some reason, it should get the standard error message. for that command. I
would strongly suggest getting rid of the warnings in script format for
g.region.

7. The lines of output should be the same regardless of the location
environment or any other context factor. R.describe is particularly
problematic in this regard, making it useless for scripting.

8. I would love to have -g work the same in all information producing
commands. It would making parsing r.info and v.info SO much easier.

I hope this can be helpful in the future. Others who work with scripts might
want to add to this also.

Michael

On 1/4/07 1:28 AM, "Martin Landa" <landa.martin@gmail.com> wrote:

Hi all,

I would like to summarize all complication with the new behaviour of
g.region. I would like also to ask you some question, to fix and close
this issue finally;-)

1) The -g flag can be used in combination with all print flags, e.g.

g.region -cg

I think it is without problem. There was idea to add a new flag for
shell script style. I hope it is possible to use the -g flag for this
work as well.

2) It is possible to mix print flags, e.g.

g.region -pc

or for parsable output

g.region -pcg

There should not be any problem.

3) The -p flag was changed.

projection: 99 (Krovak)
zone: 0
datum: towgs84=570.8,85.7,462.8,4.998,1.587,5.261,3.56

->

projection : 99 (Krovak)
zone : 0
datum : towgs84=570.8,85.7,462.8,4.998,1.587,5.261,3.56

Not sure what formatting is more appropriate.

4) g.region -g X g.region -pg --- I wanted to make -g flag more
universal, e.g. to distinguish

g.region -pcl
g.region -cl

and

g.region -pclg instead of g.region -gcl <-- problem
g.region -gcl <-- problem

The question of the warning in `g.region -g` -- it can be printed at
the end of the output or removed.

5) New lines in shell script style output, I think this modification
can be done in 6.x branch.

These lines can be added to the end of the output for backward
compability -- OK?

Thanks for feedback!

Regards, Martin

2007/1/2, Maciej Sieczka <tutey@o2.pl>:

Martin Landa wrote:

2007/1/2, Maciej Sieczka <tutey@o2.pl>:

"g.region -g" works OK now, but it prints a WARNING message on the top.
It also prints few extra lines, compared to before, namely:

projection=1
zone=34
datum=wgs84
ellipsoid=wgs84

Your WARNING message is correct and desired, as well as the extra info
is usefull, but those several additional lines might brake some user's
scripts.

So should I disable this warning, right?

I guess so. But somebody more knowledgable should decide.

I think the additional lines would not break any scripts, which parse
`g.region -g` output in a reasonable way (eval, awk) (?).

Those extra lines might brake all scripts that don't use eval, I
suppose. Eg. parsing with awk by line number will fail now:

# grab the current region settings
g.region -g > $TMP.${PROG}.region

# extract variables from the grabbed region
north=`awk 'BEGIN {FS="="} (NR==1) {print $2}' $TMP.${PROG}.region`
south=`awk 'BEGIN {FS="="} (NR==2) {print $2}' $TMP.${PROG}.region`
west=`awk 'BEGIN {FS="="} (NR==3) {print $2}' $TMP.${PROG}.region`
east=`awk 'BEGIN {FS="="} (NR==4) {print $2}' $TMP.${PROG}.region`
nsres=`awk 'BEGIN {FS="="} (NR==5) {print $2}' $TMP.${PROG}.region`
ewres=`awk 'BEGIN {FS="="} (NR==6) {print $2}' $TMP.${PROG}.region`
rows=`awk 'BEGIN {FS="="} (NR==7) {print $2}' $TMP.${PROG}.region`
cols=`awk 'BEGIN {FS="="} (NR==8) {print $2}' $TMP.${PROG}.region`

Is that "reasonable" I don't know, but it used to work with g.region -g
before your recent changes, and now it fails, because top 4 lines of
g.region -g output are different now.

I personally don't care too much, I have fixed my script to use eval,
but what with other users?

I absolutely agree you are doing a Good Thing fixing g.region -g as you
do, but I'm affraid it should wait till GRASS 7, for legacy reasons.

Maciek

__________________________________________
Michael Barton, Professor of Anthropology
School of Human Evolution & Social Change
Center for Social Dynamics & Complexity
Arizona State University

phone: 480-965-6213
fax: 480-965-7671
www: http://www.public.asu.edu/~cmbarton

Martin Landa wrote:

Hi all,

I would like to summarize all complication with the new behaviour of
g.region. I would like also to ask you some question, to fix and close
this issue finally;-)

1) The -g flag can be used in combination with all print flags, e.g.

g.region -cg

I think it is without problem. There was idea to add a new flag for
shell script style. I hope it is possible to use the -g flag for this
work as well.

2) It is possible to mix print flags, e.g.

g.region -pc

or for parsable output

g.region -pcg

There should not be any problem.

3) The -p flag was changed.

projection: 99 (Krovak)
zone: 0
datum: towgs84=570.8,85.7,462.8,4.998,1.587,5.261,3.56

->

projection : 99 (Krovak)
zone : 0
datum : towgs84=570.8,85.7,462.8,4.998,1.587,5.261,3.56

Not sure what formatting is more appropriate.

4) g.region -g X g.region -pg --- I wanted to make -g flag more
universal, e.g. to distinguish

g.region -pcl
g.region -cl

and

g.region -pclg instead of g.region -gcl <-- problem
g.region -gcl <-- problem

The question of the warning in `g.region -g` -- it can be printed at
the end of the output or removed.

5) New lines in shell script style output, I think this modification
can be done in 6.x branch.

These lines can be added to the end of the output for backward
compability -- OK?

Really cannot it wait for GRASS 7? I'm just kind of uneasy about it.
What if somebody eg. counts the number of lines in g.region -g output
for his mysterious, unknow to us, purpose, and he gets extra 4 lines?
This might sound funny ;), but it won't be funny anymore if it is real.
You never know. Better to stick to the safe side I think.

Wait, another thought - WHY should g.region print the projection info,
either in -p or -pg mode, *anyway*? Isn't ther g.proj -p for that?
Doubled functionality per se (if we also consider r.info which prints
the projection info too - a trippled fuctionality). So shouldn't this
wait for GRASS 7, where printing the projection info will be left for
g.proj [1] alone, and removed from g.region and r.info for good? And
for now, in GRASS 6, leave it as it was before - not perfect, but 100%
backwards compatible at least. Let's leave cleaning it all up together
for GRASS 7. Am I thinking any good? Paul?

[1]
propably the g.proj -j output should be extended to include all the
information output by g.proj -p, or a new "-g" flag should be
introduced, to be used in conjunction with "-p" for parseable output.

Maciek

Hello Maciek

On Thu, 4 Jan 2007, Maciej Sieczka wrote:

Wait, another thought - WHY should g.region print the projection info,
either in -p or -pg mode, *anyway*? Isn't ther g.proj -p for that?
Doubled functionality per se (if we also consider r.info which prints
the projection info too - a trippled fuctionality). So shouldn't this
wait for GRASS 7, where printing the projection info will be left for
g.proj [1] alone, and removed from g.region and r.info for good? And
for now, in GRASS 6, leave it as it was before - not perfect, but 100%
backwards compatible at least. Let's leave cleaning it all up together
for GRASS 7. Am I thinking any good? Paul?

I think:
g.region should print only information it gets from the WIND file
r.info should print only information it gets from the raster header file
g.proj -p should only print information it gets from the PROJ_INFO and PROJ_UNITS files.

Yes the WIND and yes the raster header include some projection information - that is an historical thing. We shouldn't try to hide it though, because there are bits of the code that check it and it is still useful in a few circumstances. But I don't think extra stuff like the projection name from PROJ_INFO in brackets, ellps or datum should be there. It is confusing as these are being taken from a different source. The projection name reported should be one of the 5 original ones defined: XY, UTM, State Plane, Latitude-Longitude or Other, corresponding to codes 0,1,2,3 or 99 in the WIND file.

r.info should continue to report the projection information that is in the raster header - it causes problems if it is not the same as the location so it is important to report it just in case. But again (I don't know if it does) it should not report anything from the PROJ_INFO file.

[1]
propably the g.proj -j output should be extended to include all the
information output by g.proj -p, or a new "-g" flag should be
introduced, to be used in conjunction with "-p" for parseable output.

Hmm, if you think it might be useful. I'm not sure. The function of
g.proj -j is to produce a PROJ.4-compatible output. This is slightly different from that you see with g.proj -p with colons replaced by = signs. I'm not sure how useful g.proj -pg would be as AFAIK only proj, unit, units and meters are the only fields *guaranteed* to be present. There are many different ways to specify a PROJ_INFO file, unlike a WIND file where all the parameters have to be there and have to have a value. The two aren't really analogous IMHO.

So that's what I think :slight_smile:

Paul

Paul Kelly wrote:

Hello Maciek

On Thu, 4 Jan 2007, Maciej Sieczka wrote:

Wait, another thought - WHY should g.region print the projection info,
either in -p or -pg mode, *anyway*? Isn't ther g.proj -p for that?
Doubled functionality per se (if we also consider r.info which prints
the projection info too - a trippled fuctionality). So shouldn't this
wait for GRASS 7, where printing the projection info will be left for
g.proj [1] alone, and removed from g.region and r.info for good? And
for now, in GRASS 6, leave it as it was before - not perfect, but 100%
backwards compatible at least. Let's leave cleaning it all up together
for GRASS 7. Am I thinking any good? Paul?

I think:
g.region should print only information it gets from the WIND file
r.info should print only information it gets from the raster header file
g.proj -p should only print information it gets from the PROJ_INFO and
PROJ_UNITS files.

And I think :):

- g.region: should print region extent, *only*
- r.info: print only the given raster layer info, *exluding* projection
ifno - you can't have (normally) a raster inside a given GRASS
location, that has a projection different from the location's
projection it is in, can you?
- g.proj: print all the info relevant to the projection of the current
working location

Yes the WIND and yes the raster header include some projection
information - that is an historical thing. We shouldn't try to hide it
though, because there are bits of the code that check it and it is still
useful in a few circumstances.

What circumstances, ecxactly (sorry, I really don't know).

But I don't think extra stuff like the
projection name from PROJ_INFO in brackets, ellps or datum should be
there. It is confusing as these are being taken from a different source.
The projection name reported should be one of the 5 original ones
defined: XY, UTM, State Plane, Latitude-Longitude or Other,
corresponding to codes 0,1,2,3 or 99 in the WIND file.

Hmm, I think g.proj -p should report the projection name as good as it
can, given the available data. 'Other' doesn't mean much (there are
dozens of projections other than UTM and State Plane).

Maciek

r.info should continue to report the projection information that is in
the raster header - it causes problems if it is not the same as the
location so it is important to report it just in case.

How can a raster's projection inside a location be different than the
location's projection?

But again (I don't know if it does) it should not report anything from the PROJ_INFO
file.

[1]
propably the g.proj -j output should be extended to include all the
information output by g.proj -p, or a new "-g" flag should be
introduced, to be used in conjunction with "-p" for parseable output.

Hmm, if you think it might be useful. I'm not sure. The function of
g.proj -j is to produce a PROJ.4-compatible output.

Right. But it doesn't print the units information, which is present in
PROJ.4-compatible output of eg. "epsg_tr.py -proj4 <code>". Shouldn't
then g.proj -j include the units info too?

This is slightly
different from that you see with g.proj -p with colons replaced by =
signs. I'm not sure how useful g.proj -pg would be as AFAIK only proj,
unit, units and meters are the only fields *guaranteed* to be present.

There are many different ways to specify a PROJ_INFO file, unlike a WIND
file where all the parameters have to be there and have to have a value.
The two aren't really analogous IMHO.

So that's what I think :slight_smile:

Thanks! I hope together we can know a bit more :).

Maciek

Hi,

I have modified g.region:

1) the warning (g.region -g) is disabled
2) g.region -g (or g.region -pg) prints the same lines as before

In the result there still small minor consistency

g.region -g -> g.region -pg
g.region -gcl is not the same as g.region -pgcl

So -g[3] == -pg[3] only without other print flags.

add 2) I am still thinking that these kind of changes (i.e. different
number of lines in g.region -g) can be done in 6.x. In G7.x should be
cleaned the connection between g.region + g.proj + [r|v].info as Paul
suggested.

Best regards, Martin

2007/1/2, Maciej Sieczka <tutey@o2.pl>:

Martin Landa wrote:

> 2007/1/2, Maciej Sieczka <tutey@o2.pl>:
>
>> "g.region -g" works OK now, but it prints a WARNING message on the top.
>> It also prints few extra lines, compared to before, namely:
>>
>> projection=1
>> zone=34
>> datum=wgs84
>> ellipsoid=wgs84
>>
>> Your WARNING message is correct and desired, as well as the extra info
>> is usefull, but those several additional lines might brake some user's
>> scripts.
>
> So should I disable this warning, right?

I guess so. But somebody more knowledgable should decide.

> I think the additional lines would not break any scripts, which parse
> `g.region -g` output in a reasonable way (eval, awk) (?).

Those extra lines might brake all scripts that don't use eval, I
suppose. Eg. parsing with awk by line number will fail now:

# grab the current region settings
g.region -g > $TMP.${PROG}.region

# extract variables from the grabbed region
north=`awk 'BEGIN {FS="="} (NR==1) {print $2}' $TMP.${PROG}.region`
south=`awk 'BEGIN {FS="="} (NR==2) {print $2}' $TMP.${PROG}.region`
west=`awk 'BEGIN {FS="="} (NR==3) {print $2}' $TMP.${PROG}.region`
east=`awk 'BEGIN {FS="="} (NR==4) {print $2}' $TMP.${PROG}.region`
nsres=`awk 'BEGIN {FS="="} (NR==5) {print $2}' $TMP.${PROG}.region`
ewres=`awk 'BEGIN {FS="="} (NR==6) {print $2}' $TMP.${PROG}.region`
rows=`awk 'BEGIN {FS="="} (NR==7) {print $2}' $TMP.${PROG}.region`
cols=`awk 'BEGIN {FS="="} (NR==8) {print $2}' $TMP.${PROG}.region`

Is that "reasonable" I don't know, but it used to work with g.region -g
before your recent changes, and now it fails, because top 4 lines of
g.region -g output are different now.

I personally don't care too much, I have fixed my script to use eval,
but what with other users?

I absolutely agree you are doing a Good Thing fixing g.region -g as you
do, but I'm affraid it should wait till GRASS 7, for legacy reasons.

Maciek

--
Martin Landa <landa.martin@gmail.com> * http://gama.fsv.cvut.cz/~landa *

On Thu, 4 Jan 2007, Maciej Sieczka wrote:

Paul Kelly wrote:

Yes the WIND and yes the raster header include some projection
information - that is an historical thing. We shouldn't try to hide it
though, because there are bits of the code that check it and it is still
useful in a few circumstances.

What circumstances, ecxactly (sorry, I really don't know).

G_projection() checks in there. E.g. checking for a latitude-longitude projection in a module to see how distance measurements should be handled, results in WIND being checked. Also for XY locations, they won't have a PROJ_INFO file, but the projection entry in the WIND file gives the information that the location is XY (unprojected). There are also places in the code code that check if the location zone and projection (from the WIND file) match that in raster map headers.

It would be possible to have the projection and zone info in a raster map not matching the location if it had got corrupted or manually edited, or more likely directly copied from a different location. It is possible for two locations to have effectively the same projection number but different numbers in the cellhd projection value - e.g. both UTM and State Plane projections can equivalently be represented as transverse mercator or lambert conformal conic with appropriate parameters, in which case there should be 99 (other projection) in the cellhd. Not that likely but possible.

But I don't think extra stuff like the
projection name from PROJ_INFO in brackets, ellps or datum should be
there. It is confusing as these are being taken from a different source.
The projection name reported should be one of the 5 original ones
defined: XY, UTM, State Plane, Latitude-Longitude or Other,
corresponding to codes 0,1,2,3 or 99 in the WIND file.

Hmm, I think g.proj -p should report the projection name as good as it
can, given the available data. 'Other' doesn't mean much (there are
dozens of projections other than UTM and State Plane).

Yes - I wasn't saying it shouldn't - my comment above is related to what I thought g.region should report. Well ideally it should report any projection-related information but if it's there in the WIND file, then I think it should.
My main point is, that to keep things simple and avoid the possiblity of introducing easily avoidable bugs in the future, the structure of the commands should reflect as much as possible the underlying structure of GRASS. Thus if you are going to change e.g. g.region and r.info not to report the projection info contained in the WIND file and raster header,
then you should remove that information from those files, change the cellhd struct not to contain it, and change all the bits of GRASS code that assume that information is there and check for it. IOW a proper clean-up.

I don't think it is a good idea to just make cosmetic changes to commands that hide the mess that is in the GRASS structure underneath, like sweeping it under the carpet. IMHO, better to keep it visible it will be easier to see what's going on and diagnose problems when they occur. But TBH I don't feel all that strongly on this issue really!

[...]

[1]
propably the g.proj -j output should be extended to include all the
information output by g.proj -p, or a new "-g" flag should be
introduced, to be used in conjunction with "-p" for parseable output.

Hmm, if you think it might be useful. I'm not sure. The function of
g.proj -j is to produce a PROJ.4-compatible output.

Right. But it doesn't print the units information, which is present in
PROJ.4-compatible output of eg. "epsg_tr.py -proj4 <code>". Shouldn't
then g.proj -j include the units info too?

Maybe it should! Can you point me to some examples?

Paul

Martin Landa wrote:

> "g.region -g" works OK now, but it prints a WARNING message on the top.
> It also prints few extra lines, compared to before, namely:
>
> projection=1
> zone=34
> datum=wgs84
> ellipsoid=wgs84
>
> Your WARNING message is correct and desired, as well as the extra info
> is usefull, but those several additional lines might brake some user's
> scripts.

So should I disable this warning, right?

Maybe.

If the intention is that use of -g alone will cease to work at some
point, the warning should be kept.

If it is kept, gis.m should be modified to handle it; has that been
done already? Even if this specific warning is removed, gis.m should
always allow for warnings simply for robustness.

Personally, I don't see a problem with having -g alone remaining
equivalent to -pg permanently, i.e. if -g is used with no other
"print" switches, then -p is enabled automatically.

I think the additional lines would not break any scripts, which parse
`g.region -g` output in a reasonable way (eval, awk) (?).

Agreed, but that doesn't help scripts which parse the output in an
*unreasonable* way :wink:

Where the g.region documentation specifies the output produced by a
switch or combination of switches, it should explicitly state that the
output will include specific fields, but that the order is unspecified
and that other fields may also be present.

IOW, anything which parses the output of g.region should, regardless
of which output format is used:

1. identify fields by their "keys" rather than by their relative
position (i.e. line number) in the output, and

2. silently ignore any unrecognised fields.

IMHO, scripts which don't comply with the above should be considered
"already broken"; changes to g.region need not accomodate them.

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

Martin Landa wrote:

3) The -p flag was changed.

projection: 99 (Krovak)
zone: 0
datum: towgs84=570.8,85.7,462.8,4.998,1.587,5.261,3.56

->

projection : 99 (Krovak)
zone : 0
datum : towgs84=570.8,85.7,462.8,4.998,1.587,5.261,3.56

Not sure what formatting is more appropriate.

Personally, I would have added the padding after the colons, i.e.:

projection: 99 (Krovak)
zone: 0
datum: towgs84=570.8,85.7,462.8,4.998,1.587,5.261,3.56

The reason being that a regexp such as "^([^:]*): *(.*)$" would still
work as before.

4) g.region -g X g.region -pg

Should be equivalent, IMO.

--- I wanted to make -g flag more
universal, e.g. to distinguish

g.region -pcl
g.region -cl

and

g.region -pclg instead of g.region -gcl <-- problem
g.region -gcl <-- problem

What's the problem? That -g == -pg but -cg != -pcg?

That isn't a problem, IMHO. By making -g a synonym for -pg, you're
only affecting the behaviour of a case which would otherwise be
meaningless (the printing format doesn't matter if you don't print
anything). Several other modules have similar behaviour, and some of
it is significantly more irrational than this.

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