[GRASS-dev] Re: [GRASS-SVN] r49205 - in grass/trunk: lib/python raster/r.info

Martin Landa landa.martin at gmail.com
Mon Nov 14 03:37:27 EST 2011


I highly *disagree* with this revert! Merging very specific options
which just prints one information to generic `-g` is a good idea (from
my POV). Please don't revert the commits which are just against your
*personal* taste! What's the opinion of other developers?

Martin

2011/11/14  <svn_grass at osgeo.org>:
> Author: hamish
> Date: 2011-11-13 22:55:13 -0800 (Sun, 13 Nov 2011)
> New Revision: 49205
>
> Modified:
>   grass/trunk/lib/python/raster.py
>   grass/trunk/raster/r.info/main.c
> Log:
> undo r49166: units, vdatum, and title can not be eval'd so needed to be split out. on doing that it was apparent that -g needs to act the same as g.region and v.info modules -- basic region info only. -s is debatable to belong to -g or not, but -gs is very easy if needed.
>
> Modified: grass/trunk/lib/python/raster.py
> ===================================================================
> --- grass/trunk/lib/python/raster.py    2011-11-14 06:49:25 UTC (rev 49204)
> +++ grass/trunk/lib/python/raster.py    2011-11-14 06:55:13 UTC (rev 49205)
> @@ -73,7 +73,7 @@
>         else:
>             return float(s)
>
> -    s = read_command('r.info', flags = 'g', map = map)
> +    s = read_command('r.info', flags = 'rgstmpud', map = map)
>     kv = parse_key_val(s)
>     for k in ['min', 'max']:
>        kv[k] = float_or_null(kv[k])
>
> Modified: grass/trunk/raster/r.info/main.c
> ===================================================================
> --- grass/trunk/raster/r.info/main.c    2011-11-14 06:49:25 UTC (rev 49204)
> +++ grass/trunk/raster/r.info/main.c    2011-11-14 06:55:13 UTC (rev 49205)
> @@ -60,8 +60,9 @@
>     struct Reclass reclass;
>     struct GModule *module;
>     struct Option *opt1;
> -    struct Flag *gflag, *hflag;
> -
> +    struct Flag *rflag, *sflag, *tflag, *gflag, *hflag, *mflag;
> +    struct Flag *uflag, *dflag, *timestampflag;
> +
>     /* Initialize GIS Engine */
>     G_gisinit(argv[0]);
>
> @@ -74,14 +75,44 @@
>
>     opt1 = G_define_standard_option(G_OPT_R_MAP);
>
> +    rflag = G_define_flag();
> +    rflag->key = 'r';
> +    rflag->description = _("Print range only");
> +
> +    sflag = G_define_flag();
> +    sflag->key = 's';
> +    sflag->description =
> +       _("Print raster map resolution (NS-res, EW-res) only");
> +
> +    tflag = G_define_flag();
> +    tflag->key = 't';
> +    tflag->description = _("Print raster map type only");
> +
>     gflag = G_define_flag();
>     gflag->key = 'g';
> -    gflag->description = _("Print basic info in shell script style");
> +    gflag->description = _("Print map region only");
>
>     hflag = G_define_flag();
>     hflag->key = 'h';
>     hflag->description = _("Print raster history instead of info");
>
> +    uflag = G_define_flag();
> +    uflag->key = 'u';
> +    uflag->description = _("Print raster map data units only");
> +
> +    dflag = G_define_flag();
> +    dflag->key = 'd';
> +    dflag->description = _("Print raster map vertical datum only");
> +
> +    mflag = G_define_flag();
> +    mflag->key = 'm';
> +    mflag->description = _("Print map title only");
> +
> +    timestampflag = G_define_flag();
> +    timestampflag->key = 'p';
> +    timestampflag->description =
> +       _("Print raster map timestamp (day.month.year hour:minute:seconds) only");
> +
>     if (G_parser(argc, argv))
>        exit(EXIT_FAILURE);
>
> @@ -115,8 +146,9 @@
>
>     out = stdout;
>
> -    /* no flags */
> -    if (!gflag->answer && !hflag->answer) {
> +    if (!rflag->answer && !sflag->answer && !tflag->answer &&
> +       !gflag->answer && !hflag->answer && !timestampflag->answer &&
> +       !mflag->answer && !uflag->answer && !dflag->answer) {
>        divider('+');
>
>        compose_line(out, "Layer:    %-29.29s  Date: %s", name,
> @@ -289,10 +321,9 @@
>
>        fprintf(out, "\n");
>     }
> -    else {     /* g,h flag */
> +    else {     /* r,s,t,g,h, or m flag */
>
> -       if (gflag->answer) {
> -           /* old rflag */
> +       if (rflag->answer) {
>            if (data_type == CELL_TYPE) {
>                if (2 == Rast_read_range(name, "", &crange)) {
>                    fprintf(out, "min=NULL\n");
> @@ -311,7 +342,10 @@
>                fprintf(out, "min=%.15g\n", zmin);
>                fprintf(out, "max=%.15g\n", zmax);
>            }
> -
> +
> +       }
> +
> +       if (gflag->answer) {
>            G_format_northing(cellhd.north, tmp1, -1);
>            G_format_northing(cellhd.south, tmp2, -1);
>            fprintf(out, "north=%s\n", tmp1);
> @@ -321,46 +355,47 @@
>            G_format_easting(cellhd.west, tmp2, -1);
>            fprintf(out, "east=%s\n", tmp1);
>            fprintf(out, "west=%s\n", tmp2);
> -
> -           /* old sflag */
> +       }
> +
> +       if (sflag->answer) {
>            G_format_resolution(cellhd.ns_res, tmp3, cellhd.proj);
>            fprintf(out, "nsres=%s\n", tmp3);
>
>            G_format_resolution(cellhd.ew_res, tmp3, cellhd.proj);
>            fprintf(out, "ewres=%s\n", tmp3);
> -
> -           /* new rows and columns parameters */
> -           fprintf(out, "rows=%d\n", cellhd.rows);
> -           fprintf(out, "cols=%d\n", cellhd.cols);
> -
> -           /* old tflag */
> +       }
> +
> +       if (tflag->answer) {
>            fprintf(out, "datatype=%s\n",
>                    (data_type == CELL_TYPE ? "CELL" :
>                     (data_type == DCELL_TYPE ? "DCELL" :
>                      (data_type == FCELL_TYPE ? "FCELL" : "??"))));
> -
> -           /* old mflag */
> +       }
> +
> +       if (mflag->answer) {
>            fprintf(out, "title=%s (%s)\n", cats_ok ? cats.title :
>                    "??", hist_ok ? Rast_get_history(&hist, HIST_TITLE) : "??");
> -
> -           /* old timestampflag */
> +       }
> +
> +       if (timestampflag->answer) {
>            if (time_ok && (first_time_ok || second_time_ok)) {
>
>                G_format_timestamp(&ts, timebuff);
>
>                /*Create the r.info timestamp string */
>                fprintf(out, "timestamp=\"%s\"\n", timebuff);
> +
>            }
>            else {
>                fprintf(out, "timestamp=\"none\"\n");
> -           }
> -
> -           /* old uflag */
> -           fprintf(out, "units=%s\n", units ? units : "(none)");
> -           /* old dflag */
> -           fprintf(out, "vertical_datum=%s\n", vdatum ? vdatum : "(none)");
> +           }
>        }
>
> +       if (uflag->answer)
> +           fprintf(out, "units=%s\n", units ? units : "(none)");
> +       if (dflag->answer)
> +           fprintf(out, "vertical_datum=%s\n", vdatum ? vdatum : "(none)");
> +
>        if (hflag->answer) {
>            if (hist_ok) {
>                fprintf(out, "Data Source:\n");
> @@ -375,7 +410,8 @@
>                }
>            }
>        }
> -    }
> +    }                          /* else rflag or sflag or tflag or gflag or hflag or mflag */
> +
>     return EXIT_SUCCESS;
>  }
>
>
> _______________________________________________
> grass-commit mailing list
> grass-commit at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/grass-commit
>



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


More information about the grass-dev mailing list