1

I have a PostgreSql stored procedure which returns a geojson feature collection created with json_build_object function. This web service opens fine in OpenLayers, however, when I try to open it in QGIS, with data source manager -> vector -> protocol -> geojson, I get the following error :

Invalid data source: [myurl]/rpc/wod_geojson is not a valid or recognized data source.

Returned geojson looks like this :

{
"type": "FeatureCollection",
"features": [{
        "type": "Feature",
        "id": 1,
        "geometry": {
            "type": "Point",
            "coordinates": [0.0, 0.0]
        },
        "properties": {
            "num": 1,
            "lib": "bla"
        }
    }, {
        "type": "Feature",
        "id": 2,
        "geometry": {
            "type": "Point",
            "coordinates": [1.0, 1.0]
        },
        "properties": {
            "num": 2,
            "lib": "blabla"
        }
    }, {
        "type": "Feature",
        "id": 3,
        "geometry": {
            "type": "Point",
            "coordinates": [2.0, 2.0]
        },
        "properties": {
            "num": 3,
            "lib": "blablabla"
        }
    }
]

}

What am I missing ?

PostGrest response headers :

Content-Range   0-0/*
Content-Type    application/geo+json
Date    Wed, 09 Feb 2022 11:02:26 GMT
Server  postgrest/9.0.0
Transfer-Encoding   chunked
Vary    Accept-Encoding

EDITED : Curiously, I can open the web service in QGIS using Python :

myLayer= QgsVectorLayer('[myurl]/rpc/wod_geojson', 'myLayer', 'ogr')
QgsProject.instance().addMapLayers([myLayer])
sigeal
  • 111
  • 5
  • 1
    Will a different URL work such as https://raw.githubusercontent.com/ebrelsford/geojson-examples/master/brooklyn.geojson ? – Timothy Dalton Feb 09 '22 at 05:57
  • Yes it does, and if I save my web service as a geojson file, it does too. So it doesn't seem to be a problem with geojson format, but rather with REST web service. May be wrong headers ? I added the postgrest response headers in the question. – sigeal Feb 09 '22 at 11:09
  • 1
    Interesting. Could you have a look at this? https://github.com/PostgREST/postgrest/pull/986 . It would be interesting to see if Qgis can load a geojson served by some other server such as nginx or apache. – Timothy Dalton Feb 09 '22 at 20:38
  • I don't know for nginx and apache, but I tested with another RESTful server [pg_featureserv](https://github.com/CrunchyData/pg_featureserv) and it works fine. – sigeal Feb 11 '22 at 14:19

1 Answers1

0

I had this same issue, but I'm using a NodeJS server in between PostgREST and end-clients. I watched the traffic and noticed that QGIS Data Source Manager includes Accepts: 'text/plain, application/json' in the request headers. Well, turns out that PostgRest responds differently to text/plain requests. So in my proxy server, I am now overriding this request header to force the type to be application/json.

bramb84
  • 355
  • 4
  • 14