diff --git a/general/g.region/printwindow.c b/general/g.region/printwindow.c index 8765c34cc67..ac2800478d8 100644 --- a/general/g.region/printwindow.c +++ b/general/g.region/printwindow.c @@ -559,16 +559,36 @@ void print_window(struct Cell_head *window, int print_flag, int flat_flag, } /* flag.gmt_style */ - if ((print_flag & PRINT_GMT) && format != JSON) - fprintf(stdout, "%s/%s/%s/%s\n", west, east, south, north); + if (print_flag & PRINT_GMT) { + char gmt[120]; + switch (format) { + case JSON: + snprintf(gmt, 120, "%s/%s/%s/%s", west, east, south, north); + json_object_set_string(root_object, "GMT", gmt); + break; + default: + fprintf(stdout, "%s/%s/%s/%s\n", west, east, south, north); + break; + } + } /* flag.wms_style */ - if ((print_flag & PRINT_WMS) && format != JSON) { - G_format_northing(window->north, north, -1); - G_format_northing(window->south, south, -1); - G_format_easting(window->east, east, -1); - G_format_easting(window->west, west, -1); - fprintf(stdout, "bbox=%s,%s,%s,%s%s", west, south, east, north, sep); + if (print_flag & PRINT_WMS) { + char wms[150]; + switch (format) { + case JSON: + snprintf(wms, 150, "bbox=%s,%s,%s,%s", west, south, east, north); + json_object_set_string(root_object, "WMS", wms); + break; + default: + G_format_northing(window->north, north, -1); + G_format_northing(window->south, south, -1); + G_format_easting(window->east, east, -1); + G_format_easting(window->west, west, -1); + fprintf(stdout, "bbox=%s,%s,%s,%s%s", west, south, east, north, + sep); + break; + } } /* flag.nangle */ diff --git a/general/g.region/testsuite/test_g_region.py b/general/g.region/testsuite/test_g_region.py index 280116f81a8..4a72b8e05ce 100644 --- a/general/g.region/testsuite/test_g_region.py +++ b/general/g.region/testsuite/test_g_region.py @@ -75,9 +75,11 @@ def test_format_json(self): "depths": 10, "cells": 1010600, "cells3": 2526500, + "GMT": "120000/935000/10000/320000", + "WMS": "bbox=120000,10000,935000,320000", } - output = call_module("g.region", flags="p", format="json") + output = call_module("g.region", flags="ptw", format="json") output_json = json.loads(output) expected_ellps = expected.pop("ellipsoid").split(" ")