[Qgis-user] Qgis-user Digest, Vol 170, Issue 60

Thayer Young thayeray at yahoo.com
Thu Apr 30 14:35:38 PDT 2020


 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 <apasotti at gmail.com>
To: Yann Voté <ygversil at lilo.org>
Cc: qgis-user <qgis-user at lists.osgeo.org>
Subject: Re: [Qgis-user] PyQGIS to add PostGIS raster layer?
Message-ID:
    <CAL5Q672kn0MVG9eSK3eTpFW8yXpXdhMb9ykPAy-Zfm_Q11fLiA at mail.gmail.com>
Content-Type: text/plain; charset="UTF-8"

On Thu, Apr 30, 2020 at 9:46 AM Yann Voté <ygversil at lilo.org> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20200430/caa47e73/attachment.html>


More information about the Qgis-user mailing list