如何在pyqgis单机应用程序中加载和显示s57文件

2024-10-01 22:28:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要使用pyqgis 3显示一个s57文件到目前为止我所做的是,我已经创建了一个QT窗口,我正在尝试用下面的代码加载一个s57文件

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显示在不同的软件正确的罚款。你知道吗


Tags: 文件theto代码selfaddlayermap

热门问题