Thank you for your response Alessandro,
This looks good to me! Can you please tell me if this will require a QGIS build 
with GDAL 3+ or will it work with the 2.4 that is still being distributed for 
MacOS? This is true of both the LTR and Latest.
The other issue that I have is that I have been using A Coruña because of 
problems with PostGIS rasters in Bucharesti. So far PostGIS rasters in 
Bucharesti are all mirrored along the bottom of the raster. The raster is 
upside down and does not even overlap the correct bounding box. I have not 
found a bug report for this on Github. I am not sure if this is peculiar to my 
system?
-Thayer


======================================================
Message: 4
Date: Thu, 30 Apr 2020 09:58:00 +0200
From: Alessandro Pasotti <[email protected]>
To: Yann Voté <[email protected]>
Cc: qgis-user <[email protected]>
Subject: Re: [Qgis-user] PyQGIS to add PostGIS raster layer?
Message-ID:
    <cal5q672kn0mvg9esk3etpfw8yxpxdhmb9ykpay-zfm_q11f...@mail.gmail.com>
Content-Type: text/plain; charset="UTF-8"

On Thu, Apr 30, 2020 at 9:46 AM Yann Voté <[email protected]> wrote:
>
> Hi,
>
> Something like this should do.
>
> pg_layer = QgsVectorLayer(
>      "host=db.priv.example.org port=5432 authcfg=expauth srid=4326 "
>      "dbname=exampledb table='schema'.'table_name' (geometry) "
>      "type=MULTIPOLYGON sql=",
>      baseName='table_name',
>      providerLib='postgres',
> )
> QgsProject.instance().addMapLayer(pg_layer)
>
> Of course, adapt with your values. In particular, authcfg is the 7-chars
> identifier of the auth configuration that contains your login and
> password (or cert) to authenticate to PostgreSQL.
>
> See https://qgis.org/pyqgis/master/core/QgsVectorLayer.html

This won't work with rasters, you need to create a QgsRasterLayer, not
a vector one.

Coming to PG rasters, in QGIS 3.12 there are two providers that
support PG rasters:
- GDAL data provider
- native "postgresraster" data provider

GDAL data source uri uses the well known good old syntax to connect to
the raster (you can also test the connection from the command line
with "gdalinfo ....").

The "postgresraster" provider is totally new in 3.12 and you can have
a look to the tests for PyQGIS use cases:
https://github.com/qgis/QGIS/blob/master/tests/src/python/test_provider_postgresraster.py#L82

Hope this helps.
_______________________________________________
Qgis-user mailing list
[email protected]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user

Reply via email to