Skip to content

Comments

r.coin: Add JSON output support#7108

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

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

Conversation

@sumitchintanwar
Copy link
Contributor

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

Comprehensive unit tests are added to verify:

  • JSON structure and field types
  • Cross-unit consistency and area conversions
  • Percent totals and known reference values

This improves machine-readability and prevents regressions in JSON output behavior.

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

{
    "module": "r.coin",
    "map1": "landuse",
    "map2": "elevation",
    "unit": {
        "code": "c",
        "name": "cells"
    },
    "coincidence": [
        {
            "cat1": 11,
            "cat2": 1,
            "count": 1,
            "area": 900,
            "value": 1
        },
        {
            "cat1": 11,
            "cat2": 2,
            "count": 4,
            "area": 3600,
            "value": 4
        }
    ]
}


Results: All 12 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.

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