Can't get my QGIS external map to display on Ubuntu trusty: QObject::connect: Cannot

المشرف العام

Administrator
طاقم الإدارة
I've been following along the examples from the book "Building Mapping Applications with QGIS and for the life of me I can't figure out why my shape files aren't loading and displaying in the app window.

I use a run.sh file to set up the environment: export PYTHONPATH="/usr/share/qgis/python" export LD_LIBRARY_path="/usr/share/qgis/lib" export QGIS_PREFIX="/usr/share/qgis" python externalApp.py

I have tested that I can import all qgis, qgis.core, qgis.gui etc files without errors in Python.

The script I'm using is pasted below. I have played around with the shape file name and location...any help would be appreciated. import sys import os from qgis.core import * from qgis.gui import * from PyQt4.QtGui import * from PyQt4.QtCore import Qt

# class MapViewer(QMainWindow): def init(self, shapefile): QMainWindow.init(self) self.setWindowTitle("Map Viewer")

canvas = QgsMapCanvas() canvas.useImageToRender(False) canvas.setCanvasColor(Qt.white) canvas.show() layer = QgsVectorLayer(shapefile, "layer1", "ogr") #if not layer.isValid(): # raise IOError("Invalid shapefile") QgsMapLayerRegistry.instance().addMapLayer(layer) canvas.setExtent(layer.extent()) canvas.setLayerSet([QgsMapCanvasLayer(layer)]) layout = QVBoxLayout() layout.addWidget(canvas) contents = QWidget() contents.setLayout(layout) self.setCentralWidget(contents) # def main(): """ Our main program. """ QgsApplication.setPrefixPath(os.environ['QGIS_PREFIX'], True) QgsApplication.initQgis()

app = QApplication(sys.argv) viewer = MapViewer("~/workspace/temp/ne_10m_populated_places.shp") viewer.show() app.exec_() QgsApplication.exitQgis() # if name == "main": main()



أكثر...
 
أعلى