2

I'm trying to change the data source of a QgsRasterLayer to point to a different URI.

I can change the dataProvider's datasource with wmsLayer.dataProvider().setDataSourceUri(uri) and the change is correctly shown.

But as it's just changing the dataProvider the change is not saved and will default back on reloading the project. wmslayer.source() also still returns the old source.

There is a QgsRasterLayer::setDataSource() function, but it doesn't appear to have a python binding.

How would one go about changing it correctly?

1

I found the answer. Or rather QgsRasterLayer was updated to support QgsRasterLayer::setDataSource() so this works now:

rasterlayer.setDataSource(uri, "LAYERNAME", "wms", QgsDataProvider.ProviderOptions())

Which is great.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.