OSGeo / grass

GRASS GIS - free and open-source geospatial processing engine
https://grass.osgeo.org
Other
849 stars 308 forks source link

[Feat] Add JSON output to r.colors.out #3537

Closed petrasovaa closed 3 days ago

petrasovaa commented 7 months ago

Add JSON output for easy parsing of r.colors.out output.

Describe the solution you'd like Adding option format, it would be something like format=plain for the current output format and format=json for the JSON output. There is a newly added parson library to GRASS (https://github.com/OSGeo/grass/pull/3028), so it should be used here.

See also discussion in https://github.com/OSGeo/grass/discussions/3019.

A test should be included. A possible JSON layout could be:

[
  {
    "value": 0,
    "red": 255,
    "green": 0,
    "blue": 0
  },
  {
    "value": 1,
    "red": 0,
    "green": 255,
    "blue": 0
  },
  {
    "value": 2,
    "red": 0,
    "green": 0,
    "blue": 255
  }
]
cwhite911 commented 7 months ago

It might be nice to have the output in a usable formats.

[
 {
    "value": 0,
    "hex": "#FF0000",
    "rgb": "rgb(255, 0, 0)",
    "rgb": "rgb(255, 0, 0, 0)",
    "hsl":  "hsl(0, 100, 50)"
  }
]
NishantBansal2003 commented 3 weeks ago

Hey, I was trying to look up this issue. Can you help me out a little? I want to know how I can test any changes I make to check their output.

[
 {
    "value": 0,
    "hex": "#FF0000",
    "rgb": "rgb(255, 0, 0)",
    "rgb": "rgb(255, 0, 0, 0)",
    "hsl":  "hsl(0, 100, 50)"
  }
]

Also, if you could provide a specific test that generates this output, I can use it to test my changes. Additionally, can you tell me how to test the changes overall, including some commands for integration tests?

petrasovaa commented 3 weeks ago

Thanks for looking into this! I suggest to review r.colors.out documentation. You can try to write a simple test with pytest, see notes and look up some existing examples, e.g. in r.mask.status or v.dissolve. Similarly to r.mask.status example, you would create a small temporary raster and run r.colors.out on that one.

For the JSON support, look at some examples a GSoC student did this year to keep it consistent.