[QGIS-Developer] How to Create a WMS-Time layer via PyQGIS?

Richard Duivenvoorde rdmailings at duif.net
Mon May 10 01:33:16 PDT 2021


Hi,

I've been able to create a vector with Temporal Properties and use it in 
the Temporal Controller [0]

Now I try to do the same for a WMS-Time layer...

The layer "precip-blue-transparent/nearest" (epsg:3857 or 28992)
from this service:
https://geoservices.knmi.nl/adagucserver?dataset=RADAR&VERSION=1.1.1&request=getcapabilities
(our national Weather institute) loads fine and is usable in the 
Temporal Controller (PM5 = 5 min data, nice!)

Copying the uri from that layer properties and using it in pyqgis just 
works:

uri = 
'allowTemporalUpdates=true&contextualWMSLegend=0&crs=EPSG:3857&dpiMode=7&featureCount=10&format=image/png&layers=RAD_NL25_PCP_CM&styles=precip-blue-transparent/nearest&temporalSource=provider&timeDimensionExtent=2021-03-31T09:25:00Z/2021-05-03T12:20:00Z/PT5M&type=wmst&url=https://geoservices.knmi.nl/adagucserver?dataset%3DRADAR%26VERSION%3D1.1.1%26request%3Dgetcapabilities'

layer = QgsRasterLayer(uri, 'KNMI', "wms")

QgsProject.instance().addMapLayer(layer, True)


If I try to use a 'cleaner' raster layer uri (thinking I could set some 
temporal properties on the layer later), I fail to get it 'registered' 
on the Temporal Controller OR even severe QGIS crashes (when you only 
leave out the 
"timeDimensionExtent=2021-03-31T09:25:00Z/2021-05-03T12:20:00Z/PT5M" 
part... see [1])

I thought to use the provider defaults (from WMS capabilities), to be 
able to for example change/set the temporal extent later:
layer_temporal_props = layer.temporalProperties( capabilities )
but... I cannot get to the WMS capabilities... (@Matthias: THAT is was 
searching in the api :-) )

This for example:

uri = 
'allowTemporalUpdates=true&temporalSource=provider&crs=EPSG:28992&layers=RAD_NL25_PCP_CM&styles=precip-blue-transparent/nearest&format=image/png&url=https://geoservices.knmi.nl/adagucserver?dataset=RADAR&VERSION=1.1.1'
layer = QgsRasterLayer(uri, 'KNMI', "wms")
QgsProject.instance().addMapLayer(layer, True)

results in a valid WMS, but not Temporal aware layer.
And untill now I fail to 'make it temporal' via QGIS.

Anybody a hint (or tell me 'NYI' :-( ...)?

Regards,

Richard Duivenvoorde

[0] 
https://github.com/qgis/QGIS-Documentation/blob/1263b663d5160c2a2c0984c16ca7a5ce4bdd182f/docs/pyqgis_developer_cookbook/temporal_data.rst

[1] uri = 
'allowTemporalUpdates=true&temporalSource=provider&type=wmst&layers=RAD_NL25_PCP_CM&styles=precip-blue-transparent/nearest&crs=EPSG:3857&format=image/png&url=https://geoservices.knmi.nl/adagucserver?dataset%3DRADAR%26VERSION%3D1.1.1%26request%3Dgetcapabilities'


More information about the QGIS-Developer mailing list