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

Add option to 'compact' GeoJSON result into single feature #100

Closed
frankinspace opened this issue Mar 5, 2024 · 4 comments · Fixed by #177
Closed

Add option to 'compact' GeoJSON result into single feature #100

frankinspace opened this issue Mar 5, 2024 · 4 comments · Fixed by #177
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@frankinspace
Copy link
Member

Currently when a time series is requested as GeoJSON output, the result is structured as a FeatureCollection where each feature in the collection is the same feature at different time steps. Each feature also includes it's own distinct geometry.

I propose that we have an option that would allow the user to instead get back only a single Feature where the properties of that feature contain all the fields requested by the user but as a list instead of a single value.

This would save a lot on the size of the returned GeoJSON object for long time series results which would help with both egress cost and individual request latency.

Example:

{
    "status": "200 OK",
    "time": 458.179,
    "hits": 3,
    "results": {
        "csv": "",
        "geojson": {
            "type": "FeatureCollection",
            "features": [
                {
                    "id": "0",
                    "type": "Feature",
                    "properties": {
                        "reach_id": "73282400171",
                        "time_str": "2023-07-28T22:10:37Z",
                        "wse": "211.178",
                        "slope": "-0.0007516914999999999"
                    },
                    "geometry": {
                        "type": "LineString",
                        "coordinates": [...]
                    }
                },
                {
                    "id": "1",
                    "type": "Feature",
                    "properties": {
                        "reach_id": "73282400171",
                        "time_str": "2023-09-08T15:40:49Z",
                        "wse": "82.082",
                        "slope": "-1.0184e-06"
                    },
                    "geometry": {
                        "type": "LineString",
                        "coordinates": [...]
                    }
                },
                {
                    "id": "2",
                    "type": "Feature",
                    "properties": {
                        "reach_id": "73282400171",
                        "time_str": "2023-09-29T12:25:52Z",
                        "wse": "206.49349999999998",
                        "slope": "-0.0007833485000000001"
                    },
                    "geometry": {
                        "type": "LineString",
                        "coordinates": [...]
                    }
                }
            ]
        }
    }
}

Would instead become:

{
    "status": "200 OK",
    "time": 458.179,
    "hits": 3,
    "results": {
        "csv": "",
        "geojson": {
            "type": "FeatureCollection",
            "features": [
                {
                    "id": "0",
                    "type": "Feature",
                    "properties": {
                        "reach_id": ["73282400171", "73282400171", "73282400171"],
                        "time_str": ["2023-07-28T22:10:37Z", "2023-09-08T15:40:49Z", "2023-09-29T12:25:52Z"],
                        "wse": ["211.178", "82.082", "206.49349999999998"],
                        "slope": ["-0.0007516914999999999", "-1.0184e-06",  "-0.0007833485000000001"]
                    },
                    "geometry": {
                        "type": "LineString",
                        "coordinates": [...]
                    }
                }
            ]
        }
    }
}

In practice we would have to use the geometry from one of the entries in the database but I don't think it is too important which one is chosen.

@torimcd @cassienickles interested in your thoughts on this.

@frankinspace frankinspace added enhancement New feature or request help wanted Extra attention is needed labels Mar 5, 2024
@frankinspace
Copy link
Member Author

General consensus is yes, this feature is useful. Users want to retain ability to choose which return format is returned

@frankinspace
Copy link
Member Author

Consider 'compact' instead of 'compress' as the name of the variable because compress is generally associated with compression algorithms like zip or bz.

Also, need to add documentation section describing how we handle the 'properties' object for features returned from hydrocron. The GeoJSON RFC specifies that 'properties' can be any valid JSON object (https://datatracker.ietf.org/doc/html/rfc7946#section-3.2). So, it is up to us to describe to end users how that object is structured.

@frankinspace frankinspace changed the title Add option to 'compress' GeoJSON result into single feature Add option to 'compact' GeoJSON result into single feature May 2, 2024
@frankinspace frankinspace moved this to 🔖 Ready in SOTO PI 24.2 May 6, 2024
@nikki-t
Copy link
Collaborator

nikki-t commented May 8, 2024

@frankinspace - Do you think we should return a compact response for cases where the Accept header is application/geo+json? Reading the RFC it seems like this might still be valid GeoJSON? If so it might be nice to allow the user to return the compact version of GeoJSON.

@frankinspace
Copy link
Member Author

Good idea, yes agreed. I was thinking we would wait to make compact the default when we update to v2 of the API because it's technically a breaking change to the API (changing the format/schema of the returned object would break clients).

But, since the application/geo+json is a new feature I think we can start with compact being the default, then transition the json response to default to compact with the V2 upgrade

@nikki-t nikki-t moved this from 🔖 Ready to 👀 In review in SOTO PI 24.2 May 10, 2024
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in SOTO PI 24.2 May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
No open projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

2 participants