Skip to content

r.coin: Add JSON output support#7108

Open
sumitchintanwar wants to merge 3 commits intoOSGeo:mainfrom
sumitchintanwar:feat/r-coin-json-output-clean
Open

r.coin: Add JSON output support#7108
sumitchintanwar wants to merge 3 commits intoOSGeo:mainfrom
sumitchintanwar:feat/r-coin-json-output-clean

Conversation

@sumitchintanwar
Copy link
Contributor

@sumitchintanwar sumitchintanwar commented Feb 19, 2026

This PR adds JSON output support for r.coin module.

Below is an example of JSON Output for r.coin:

{
  "project": "nc_spm_full_v2beta1",
  "created": "2026-03-17T16:38:11Z",
  "region": {
    "north": 228500,
    "south": 215000,
    "east": 645000,
    "west": 630000,
    "ewres": 30,
    "nsres": 30
  },
  "mask": null,
  "maps": [
    {"name": "geology", "title": "Geology", "type": "raster"},
    {"name": "soils",   "title": "Soils",   "type": "raster"}
  ],
  "unit": "square_miles",
  "row_cats": [18683, 19401, 19447],
  "col_cats": [217, 262, 270],
  "matrix": [
    [0.503168, 0.000000, 0.000000],
    [0.000000, 0.023977, 0.000000],
    [0.326990, 0.099730, 0.000000]
  ],
  "row_totals": [0.503168, 0.023977, 0.426720],
  "row_totals_without_zero": [0.503168, 0.023977, 0.426720],
  "col_totals": [0.830158, 0.123707, 0.000000],
  "col_totals_without_zero": [0.830158, 0.123707, 0.000000],
  "totals": {
    "value": 0.953865,
    "value_without_zero": 0.953865
  }
}

Results: All tests pass with no issues on the nc_spm_full_v2beta1 dataset

@sumitchintanwar sumitchintanwar changed the title Feat/r coin json output clean r.coin: Add JSON output support Feb 19, 2026
@github-actions github-actions bot added raster Related to raster data processing Python Related code is in Python C Related code is in C module tests Related to Test Suite labels Feb 19, 2026
@petrasovaa
Copy link
Contributor

Let's first discuss the JSON structure... Here is a suggestions that mimicks the plain ascii:

  {
      "project": "spearfish",
      "created": "2025-06-01T...",
      "region": {
          "north": 4928000.00,
          "south": 4914000.00,
          "east": 609000.00,
          "west": 590000.00,
          "ewres": 30,
          "nsres": 30
      },
      "mask": null,
      "maps": [
          {"name": "owner", "title": "Ownership", "type": "raster"},
          {"name": "roads", "title": "Roads", "type": "raster"}
      ],
      "unit": "square miles",
      "row_cats": [0, 1, 2, 3, 4, 5],
      "col_cats": [1, 2],
      "matrix": [
          [50.63, 37.49],
          [ 1.53,  0.68],
          [ 2.92,  0.72],
          [ 3.97,  2.57],
          [ 0.65,  1.36],
          [ 0.19,  0.00]
      ],
      "row_totals": [88.12, 2.21, 3.64, 6.54, 2.00, 0.19],
      "row_totals_without_zero": [88.12, 2.21, 3.64, 6.54, 2.00, 0.19],
      "col_totals": [59.90, 42.80],
      "col_totals_without_zero": [9.27, 5.32],
      "totals": {"value": 102.70, "value_without_zero": 14.58}
  }

Note there are very similar tools - r.kappa and r.report, r.report has nested schema while r.kappa provide a value matrix. It seems r.coin is more similar to r.kappa in this regard, so hence I suggest the JSON above.

@sumitchintanwar
Copy link
Contributor Author

Noted on the JSON format. Will come up with a fix soon.

@sumitchintanwar
Copy link
Contributor Author

@petrasovaa I have changed the json output format and added some tests for the values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C Related code is in C module Python Related code is in Python raster Related to raster data processing tests Related to Test Suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants