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

Samweli Twesa Mwakisambwe smwltwesa6 at gmail.com
Mon May 10 02:59:06 PDT 2021


Hi Richard,



On Mon, May 10, 2021 at 11:33 AM Richard Duivenvoorde <rdmailings at duif.net>
wrote:

> 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])
>
To add a WMST layer via PyQGIS you will need to pass "type" parameter with
value "wmst", "temporalSource" parameter and  "timeDimensionExtent"
parameter with the temporal extent value  in the layer URI,
when QGIS find "type=wmst"  in URI, it looks for the  "timeDimensionExtent"
parameter value to create the provider temporal capabilities. For your case
 it fails to find the parameter and while parsing the extent it crashes,
this is a bug, we need to open an issue and address it.

>
> 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 :-) )
>
You can achieve that by using  layer_temporal_props =
layer.temporalProperties( ).setDefaultsFromDataProviderTemporalCapabilities
(capabilities)

> 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' :-( ...)?
>
Here the "type" parameter with value "wmst" and "timeDimensionExtent"
parameter are missing, if you add those the layer will be added and it'll
be Temporal aware.

>
> 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
> '
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>


-- 


All the Best,

Samweli
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20210510/8de11679/attachment-0001.html>


More information about the QGIS-Developer mailing list