I'm trying to write a mini QGIS plugin to test a few things. It has the bare minimum components such as the metadata file, definition of the class QGISPlugin, and a docket with a couple of tabs. It also loads a tiled map. However, what is not clicking is how to programmatically change the CRS. Everything works fine if done via the GUI (i.e. definition of the new CRS and manual selection of the CRS), but I cannot get the change of CRS to work from my code. The class defining the dock reads:
class TabulaDock(QDockWidget):
def __init__(self, iface: QgisInterface, dock_widget: QDockWidget) -> None:
super().__init__('TABULA')
tabs = QTabWidget()
tabs.setStyleSheet('''QTabBar::tab {font-size: 10pt; font-family: Verdana; font-weight: bold; color: #004F00; height: 40px; width: 140px;}''')
self.tab1 = QWidget()
tabs.addTab(self.tab1,"TAB 1")
self.tab2 = QWidget()
tabs.addTab(self.tab2,"TAB 2")
self.setWidget(tabs)
self.tabs = tabs
self.add_tiled_basemap()
self.crs = QgsCoordinateReferenceSystem()
self.crs.createFromProj4("+proj=lcc +lat_1=33.0 +lat_2=60.0 +lat_0=40.0 +lon_0=-90.0 +datum=WGS84 +no_defs")
self.crs.saveAsUserCrs("TABULA CRS")
QApplication.processEvents()
This creates the tabs and loads the tiled basemap, but it doesn't refresh the map canvas. [NOTE: the boolean associated with self.crs.createFromProj4 returns True). If I click on EPSG in the status bar and select TABULA_CRS, it does refresh the map canvas. However, the python script didn't complete this step for some reason that I cannot figure out.