Skip to content

Conversation

@petrasovaa
Copy link
Contributor

This adds support for multiple points to make it more convenient and much faster than when rerunning r.horizon for each point (no need to read in data repetitively). To keep backwards compatibility, the CSV output looks like:

azimuth,horizon_height
0.000000,0.093339
20.000000,0.061608
40.000000,0.006298
...
azimuth,horizon_height
0.000000,0.004273
20.000000,0.000000
40.000000,0.000000
...
azimuth,horizon_height
0.000000,0.002732
20.000000,0.000000
40.000000,0.000000
...

The JSON format repeats azimuths for each point:

[
    {
        "x": 633760.504202,
        "y": 223703.781513,
        "azimuth": [
            0.000000,
            100.000000,
            200.000000
        ],
        "horizon_height": [
            0.093339,
            0.010001,
            0.074268
        ]
    },
    {
        "x": 634306.722689,
        "y": 222296.218487,
        "azimuth": [
            0.000000,
            100.000000,
            200.000000
        ],
        "horizon_height": [
            0.004273,
            0.003309,
            0.027359
        ]
    },
    {
        "x": 636323.529412,
        "y": 221834.033613,
        "azimuth": [
            0.000000,
            100.000000,
            200.000000
        ],
        "horizon_height": [
            0.002732,
            0.004609,
            0.032626
        ]
    }
]

I am not sure if that's the best solution, but for loading into pandas this works:

df = pd.json_normalize(json.loads(data))
df.explode(["azimuth", "horizon_height"])
               x              y azimuth horizon_height
0  633760.504202  223703.781513     0.0       0.093339
0  633760.504202  223703.781513   100.0       0.010001
0  633760.504202  223703.781513   200.0       0.074268
1  634306.722689  222296.218487     0.0       0.004273
1  634306.722689  222296.218487   100.0       0.003309
1  634306.722689  222296.218487   200.0       0.027359
2  636323.529412  221834.033613     0.0       0.002732
2  636323.529412  221834.033613   100.0       0.004609
2  636323.529412  221834.033613   200.0       0.032626

@github-actions github-actions bot added raster Related to raster data processing Python Related code is in Python C Related code is in C HTML Related code is in HTML module docs tests Related to Test Suite labels Mar 29, 2024
Copy link
Member

@echoix echoix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see what would be wrong with this, but I'm not confident enough to know if there is something missing. I'm positive with this PR.

@echoix
Copy link
Member

echoix commented Apr 4, 2024

Is anyone else able to review it, see if there's something missing? I didn't find anything, but find it ok and ready

Copy link
Contributor

@nilason nilason left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@echoix echoix merged commit afce9ea into OSGeo:main Apr 9, 2024
@neteler neteler added this to the 8.4.0 milestone Apr 21, 2024
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 docs HTML Related code is in HTML 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.

4 participants