CrunchyData / pg_featureserv

Lightweight RESTful Geospatial Feature Server for PostGIS in Go
Apache License 2.0
462 stars 91 forks source link

Support unnesting of JSONB fields #165

Closed JakobMiksch closed 2 weeks ago

JakobMiksch commented 7 months ago

Minor fix to unnest values from JSONB fields in GeoJSON output.

Output before:

{
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            8.9000685,
                            53.1099145
                        ],
                        [
                            8.9001737,
                            53.109878
                        ],
                        [
                            8.9002618,
                            53.1099697
                        ],
                        [
                            8.9001565,
                            53.1100061
                        ],
                        [
                            8.9000685,
                            53.1099145
                        ]
                    ]
                ]
            },
            "properties": {
                "osm_id": 249727578,
                "osm_type": "W",
                "tags": "{\"club\": \"sport\", \"name\": \"BTC - Borgfelder Tennisclub\", \"building\": \"yes\"}" <-- HERE
            }
        }
    ],
    "numberReturned": 1,
    "timeStamp": "2024-03-31T19:25:21+02:00",
    "links": [
        {
            "href": "http://localhost:9000/collections/postgisftw.osm_feature_info/items",
            "rel": "self",
            "type": "application/json",
            "title": "This document as JSON"
        },
        {
            "href": "http://localhost:9000/collections/postgisftw.osm_feature_info/items.html",
            "rel": "alternate",
            "type": "text/html",
            "title": "This document as HTML"
        }
    ]
}

Output after:

{
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [
                        [
                            8.9000685,
                            53.1099145
                        ],
                        [
                            8.9001737,
                            53.109878
                        ],
                        [
                            8.9002618,
                            53.1099697
                        ],
                        [
                            8.9001565,
                            53.1100061
                        ],
                        [
                            8.9000685,
                            53.1099145
                        ]
                    ]
                ]
            },
            "properties": {
                "osm_id": 249727578,
                "osm_type": "W",
                "tags": {    <-- HERE
                    "building": "yes",
                    "club": "sport",
                    "name": "BTC - Borgfelder Tennisclub"
                }
            }
        }
    ],
    "numberReturned": 1,
    "timeStamp": "2024-03-31T19:22:09+02:00",
    "links": [
        {
            "href": "http://localhost:9000/collections/postgisftw.osm_feature_info/items",
            "rel": "self",
            "type": "application/json",
            "title": "This document as JSON"
        },
        {
            "href": "http://localhost:9000/collections/postgisftw.osm_feature_info/items.html",
            "rel": "alternate",
            "type": "text/html",
            "title": "This document as HTML"
        }
    ]
}
jmealo commented 4 months ago

@JakobMiksch Kudos on the PR! I think I'll need this before I can move forward evaluating pg_featureserv any chance we can get this merged?

JakobMiksch commented 4 months ago

I would be happy to merge it as well. We should ask @dr-jts for his opinion

dr-jts commented 2 weeks ago

Looks good to me. Merging it now.