<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p dir="auto">Further testing, I discovered that I can open my
postgrest geojson service using Python :</p>
<pre><code>myLayer= QgsVectorLayer('<a class="moz-txt-link-freetext" href="http://mydomain:3000/rpc/wod_geojson">http://mydomain:3000/rpc/wod_geojson</a>, 'myLayer', 'ogr')
QgsProject.instance().addMapLayers([myLayer])
</code></pre>
<br>
Also, testing with ogrinfo on command line, it fails with 404 error
, but adding <code>Accept: application/json</code> header makes it
work.<br>
(using --config GDAL_HTTP_HEADER_FILE)<br>
<br>
<pre class="moz-signature" cols="72">--
Christophe Damour
</pre>
<div class="moz-cite-prefix">Le 11/02/2022 à 14:27, SIGéal a écrit :<br>
</div>
<blockquote type="cite"
cite="mid:f12cdae8-d3c6-c5a6-8bb6-f93bd0d3cb75@sigeal.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
Hi,<br>
<br>
I have a PostgreSql stored procedure which returns a geojson
feature collection created with json_build_object function.<br>
This web service opens fine in OpenLayers, however, when I try to
open it in QGIS, with data source manager -> vector ->
protocol -> geojson :<br>
<br>
<br>
<br>
I get the following error :<br>
<blockquote type="cite">Invalid data source:
[myurl]/rpc/wod_geojson is not a valid or recognized data
source.</blockquote>
This is the query wrapped in a plpgsql function called my_geojson
:<br>
<blockquote type="cite"><code>SELECT json_build_object(<br>
'type', 'FeatureCollection', 'features',<br>
json_agg(<br>
json_build_object(<br>
'type', 'Feature', 'id', id, 'geometry',<br>
ST_AsGeoJSON(ST_Transform(geometry, 4326))::json,<br>
'properties', json_build_object(<br>
'lib', lib<br>
)<br>
)<br>
)<br>
)::json my_geojson FROM (SELECT ROW_NUMBER() OVER() id, * FROM
mytable) tmp</code></blockquote>
This is the url I use to call the service:<br>
<blockquote type="cite"><code><a class="moz-txt-link-freetext"
href="http://mydomain:3000/rpc/my_geojson"
moz-do-not-send="true">http://mydomain:3000/rpc/my_geojson</a></code></blockquote>
I tested a similar geojson REST service served with
pg_featureserv, and it works fine...<br>
<br>
Environment :<br>
<blockquote type="cite">
<p dir="auto">Server Environment :<br>
PostgreSQL version: 10.19<br>
PostgREST version: 9.0.0<br>
Operating system: Ubuntu 16.04</p>
<p dir="auto">Client Environment :<br>
QGIS version: 3.16.16<br>
Operating system: Windows 10</p>
</blockquote>
<br>
Thanks for any int<br>
<br>
<pre class="moz-signature" cols="72">--
Christophe Damour
</pre>
</blockquote>
<br>
</body>
</html>