grass
grass copied to clipboard
g.region: revision of output formats
There are print flags that add information (
-l, -e, -c, -n, -3, -b
). I don't think all of them are printed in flat format on 1 line with this PR yet.I think that falls into the general revision of all output formats below.
I agree the
-f
flag should stand on its own in the same way you don't have to use-g
flag together with-p
flag.I also expect that.
-g
usually means "key=value" line by line in other tools and there are no modifications to the format.Ultimately we could introduce some kind of format method to include json format and get rid of all these flags?
That would be ideal.
Originally posted by @wenzeslaus in https://github.com/OSGeo/grass/pull/3216#issuecomment-1798690010
See #3020 for tracking modules that need JSON/YAML output.
Random ideas
- Adding a new standard option (e.g.,
G_OPT_M_FORMAT
) - Implementing a new library function for format translations (e.g.,
G_translate_format()
) - Maybe, some more utility functions to generate JSON objects (would this format be the most complex and expressible format for GRASS?)
- Individual modules only generate JSON outputs (the superset of all formats) and use
G_translate_format()
to produce other formats
A lot of tools need key value format, so some universal translating function would work. Another group might be table data. Some tools would have to keep their own formats at least if we want to stay compatible. The human readable output is also important. YAML can sometimes count like that.
What is funny is that GRASS GIS is using basically YAML files since 80s to store things internally. Internal WIND file looks like this:
proj: 99
zone: 0
north: 221230
south: 219580
east: 639530
west: 637740
cols: 179
rows: 165
e-w resol: 10
n-s resol: 10
top: 1
bottom: 0
cols3: 179
rows3: 165
depths: 1
e-w resol3: 10
n-s resol3: 10
t-b resol: 1
But for machine readable output, it gets translated to:
projection=99
zone=0
n=221230
s=219580
w=637740
e=639530
nsres=10
ewres=10
rows=165
cols=179
cells=29535
which was designed for Bash eval and similar usage, but these days most people would likely choose JSON or YAML as sort of the default machine readable format for this data. Same for raster cellhd and vector head files and what r.info and v.info produce.
__________________
/ GRASS GIS \
\ is yamly! /
-------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
_\|/__\|/__\|/_ || || _\|/__\|/_