Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot import GeoJSON with NaN measurements #1293

Closed
petebankhead opened this issue Aug 23, 2023 · 0 comments · Fixed by #1296
Closed

Cannot import GeoJSON with NaN measurements #1293

petebankhead opened this issue Aug 23, 2023 · 0 comments · Fixed by #1296
Labels

Comments

@petebankhead
Copy link
Member

Bug report

Describe the bug
QuPath can (attempt to) export GeoJSON containing NaNs, but can't then read the GeoJSON it has written itself.

See https://forum.image.sc/t/qupath-object-import-via-geojson-file-error/85384 for the initial bug report.

To Reproduce
Run the following script:

def json = """
{
  "type": "Feature",
  "id": "d0852662-6941-4506-bc90-cbda1c2fa7b0",
  "geometry": {
    "type": "Polygon",
    "coordinates": [
      [
        [44196, 21480],
        [44420, 21480],
        [44420, 21687],
        [44196, 21687],
        [44196, 21480]
      ]
    ]
  },
  "properties": {
    "objectType": "annotation",
    "measurements": {
      "Anything": NaN,
      "Anything else": 2.0
    }
  }
}
"""

def po = GsonTools.getInstance().fromJson(json, PathObject)

The result is an exception

class java.lang.String cannot be cast to class java.lang.Number (java.lang.String and java.lang.Number are in module java.base of loader 'bootstrap') in QuPathScript at line number 27

ERROR: qupath.lib.measurements.MeasurementList.putAll(MeasurementList.java:234)
    qupath.lib.io.QuPathTypeAdapters$MeasurementListTypeAdapter.read(QuPathTypeAdapters.java:679)
    qupath.lib.io.QuPathTypeAdapters$MeasurementListTypeAdapter.read(QuPathTypeAdapters.java:634)
    com.google.gson.TypeAdapter.fromJsonTree(TypeAdapter.java:296)
    qupath.lib.io.QuPathTypeAdapters$PathObjectTypeAdapter.parseObject(QuPathTypeAdapters.java:535)
    qupath.lib.io.QuPathTypeAdapters$PathObjectTypeAdapter.read(QuPathTypeAdapters.java:464)
    qupath.lib.io.QuPathTypeAdapters$PathObjectTypeAdapter.read(QuPathTypeAdapters.java:280)
    com.google.gson.Gson.fromJson(Gson.java:1214)

Expected behavior
NaNs import properly... and export is also handled properly (whatever way that is).

Desktop (please complete the following information):

  • OS: All
  • QuPath Version: 0.4.3 (but likely before)
petebankhead added a commit to petebankhead/qupath that referenced this issue Aug 23, 2023
Fixes qupath#1293

Also serialize non-finite measurements as strings `"NaN", "Infinity", "-Infinity" since these are not valid json numbers.

See discussion at https://stackoverflow.com/questions/1423081/json-left-out-infinity-and-nan-json-status-in-ecmascript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant