[Qgis-user] Help reading mesh layer from Postgresql
Jorge Gustavo Rocha
jgr at geomaster.pt
Tue May 21 14:57:36 PDT 2024
Hi,
I would love to store netCDF files in Postgresql/PostGIS and read them
as mesh layers.
I'm able to store netCDF in PostGIS and add it as a rasters in QGIS.
To store it on PostGIS:
raster2pgsql -s 4326 -d -I -C -M AZ1_HS_2023101200.nc -F
public.az1_hs_2023101200 | psql service=atlantico
Check if it is ok:
gdalinfo "PG:service=atlantico schema='public' table=az1_hs_2023101200"
Load it in QGIS (as raster):
uri_config = {
'service':'atlantico',
'schema':'public',
'table':'az1_hs_2023101200',
'geometrycolumn':'rast'
}
md = QgsProviderRegistry.instance().providerMetadata('postgresraster')
uri = QgsDataSourceUri(md.encodeUri(uri_config))
rlayer = iface.addRasterLayer(uri.uri(False), "az1_hs_2023101200",
"postgresraster")
I would like to load it as a mesh layer.
Loading a mesh from file works as expected.
mesh_layer_path: str = "/tmp/AZ1_HS_2023101200.nc"
mesh_layer = QgsMeshLayer(mesh_layer_path, "layer_name", "mdal")
if not mesh_layer.isValid():
print("Layer failed to load!")
else:
QgsProject.instance().addMapLayer(mesh_layer)
Is it possible to load it from PostGIS as a mesh? Should it be stored in
another format?
I've tried this:
uri_config = {
'service':'atlantico',
'schema':'public',
'table':'az1_hs_2023101200',
'geometrycolumn':'rast'
}
md = QgsProviderRegistry.instance().providerMetadata('postgresraster')
uri = QgsDataSourceUri(md.encodeUri(uri_config))
mesh_layer = QgsMeshLayer(uri.uri(False), "layer_name", "mdal")
if not mesh_layer.isValid():
print("Layer failed to load!")
else:
QgsProject.instance().addMapLayer(mesh_layer)
Regards,
Jorge Gustavo
More information about the QGIS-User
mailing list