OSGeo / grass

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

[Feat] Add JSON output to v.colors.out #4660

Open NishantBansal2003 opened 2 weeks ago

NishantBansal2003 commented 2 weeks ago

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

Describe the solution you'd like Add an option for format, such as format=plain for the current output format and format=json for the JSON output. Additionally, include the color_format option to specify the color format to be printed in JSON. The available options for color_format include rgb, hex, hsv, and triplet.

A possible JSON layout could be:

[
    {
        "value": 1,
        "hex": "#00BFBF"
    },
    {
        "value": 286.4,
        "hex": "#00FF00"
    },
    {
        "value": 571.8,
        "hex": "#FFFF00"
    },
    {
        "value": 857.2,
        "hex": "#FF7F00"
    },
    {
        "value": 1142.6,
        "hex": "#BF7F3F"
    },
    {
        "value": 1428,
        "hex": "#C8C8C8"
    },
    {
        "value": "nv",
        "hex": "#FFFFFF"
    },
    {
        "value": "default",
        "hex": "#FFFFFF"
    }
]
petrasovaa commented 2 weeks ago

We should consider moving some of the common functionality with r.colors.out to library to avoid duplication.

NishantBansal2003 commented 2 weeks ago

Sure, I will create a PR since both r.colors.out and v.colors.out print colors in plain text using Rast_print_colors.

https://github.com/OSGeo/grass/blob/69b20cfed18dbc19cc9d0860f5d364d300c5953c/raster/r.colors.out/raster_main.c#L108-L109

https://github.com/OSGeo/grass/blob/69b20cfed18dbc19cc9d0860f5d364d300c5953c/vector/v.colors.out/main.c#L109-L110

NishantBansal2003 commented 2 weeks ago

We should consider moving some of the common functionality with r.colors.out to library to avoid duplication.

Hey @petrasovaa, should I move the common functionality to a library and add JSON output to v.colors.out in a single PR or separate PRs?

echoix commented 2 weeks ago

We should consider moving some of the common functionality with r.colors.out to library to avoid duplication.

Hey @petrasovaa, should I move the common functionality to a library and add JSON output to v.colors.out in a single PR or separate PRs?

To answer this, you can think about if there would be a problem with the PR and it would need to be reverted, would it also remove some other new functionality? If so, it's probably because it would have been better to be in separate PRs.