我需要使用pyqgis 3显示一个S 57文件。到目前为止,我已经创建了一个QT窗口,并尝试使用下面的代码在其中加载S 57文件
QMainWindow.__init__(self)
# Required by Qt4 to initialize the UI
self.setupUi(self)
# Set the title for the app
self.setWindowTitle("ShapeViewer")
# Create the map canvas
self.canvas = QgsMapCanvas()
# self.canvas.useImageToRender(False)
self.canvas.show()
# Lay our widgets out in the main window using a
# vertical box layout
self.layout = QVBoxLayout(self.frame)
self.layout.addWidget(self.canvas)
# layout is set – open a layer
# Add an OGR layer to the map
file = QFileDialog.getOpenFileName(self, "Open S57file", ".", "S57files (*.000)")
fileInfo = QFileInfo(file[0])
# Add the layer
layer = QgsVectorLayer(file[0], fileInfo.fileName(), "ogr")
if not layer.isValid():
print("Invalid Layer File")
return
QgsProject.instance().addMapLayer(layer);
self.canvas.setExtent(layer.extent())
图层是有效的,但是窗口显示空白帧,并且相同的S-57在不同的软件中可以正常显示。