EnMAP-Box / enmap-box

EnMAP-Box source code repository. See https://enmap-box.readthedocs.io for documentation
GNU General Public License v3.0
34 stars 16 forks source link

[SpectralView] GeoJSON library with NaN values not correctly plotted #887

Closed janzandr closed 1 month ago

janzandr commented 1 month ago

When using this library, which contains a NaN value, the profile is not correctly plotted:

{
    "type": "FeatureCollection",
    "name": "My Library",
    "description": "",
    "features": [
        {
            "type": "Feature", 
            "properties": {
                "name": "profile 1", 
                "profiles": {
                    "x": [1, 2, 3], 
                    "xUnit": "Nanometers", 
                    "y": [10, NaN, 30], 
                    "bbl": [1, 1, 1]}
                    }, 
            "geometry": null}
    ]
}

image

janzandr commented 1 month ago

Note that the library was written with json.dump, which will write Python nan values as "NaN".

jakimowb commented 1 month ago

It's not valid JSON (see #731) In general, QGIS requires valid JSON files according to https://datatracker.ietf.org/doc/html/rfc7946.

janzandr commented 1 month ago

Solution: "NaN" needs to be replaced by "null"

jakimowb commented 1 month ago

from https://docs.python.org/3/library/json.html

If allow_nan is false (default: True), then it will be a ValueError to serialize out of range float values (nan, inf, -inf) in strict compliance of the JSON specification. If allow_nan is true, their JavaScript equivalents (NaN, Infinity, -Infinity) will be used.

Of course we could somehow handle such kind of none-struct JSON. But other QGIS widgets or even GDAL may have a problem with that. Therefore it is better to rely and use valid JSON only.

janzandr commented 1 month ago

Not sure what you want to say? Can/Shall we support NaN values inside the SpectralView?

janzandr commented 1 month ago

Currently, using "null" is the correct way of doing it, right?