<div>Hi, <br><br>I am a newbie in this environment (python, QGIS). For last few days &nbsp;i have <br>been trying hard to compile and execute the tutorial of TIM written in <br>python. But i am getting some error or other. <br>
<br>The code is as follows </div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div><br>import sys <br>import os <br><br><br>from PyQt4.QtCore import * <br>from PyQt4.QtGui import * <br>from qgis.core import * <br>from qgis.gui import * <br>#from F:\Python25\Lib\site-packages\qgis import core as QgsCore <br>
#from F:\Python25\Lib\site-packages\qgis import gui as QgsGui <br><br># Import our GUI <br>from mainwindow_ui import Ui_MainWindow <br># Import our resources (icons) <br>import resources <br># Environment variable QGISHOME must be set to the install directory <br>
# before running this application <br>qgis_prefix = os.getenv(&quot;QGISHOME&quot;) <br>class MainWindow(QMainWindow, Ui_MainWindow): <br><br>&nbsp; def __init__(self):QMainWindow.__init__(self) <br><br># Required by Qt4 to initialize the UI <br>
self.setupUi(self) <br><br># Set the title for the app <br>self.setWindowTitle(&quot;BTC C-DAC v 1.0&quot;) <br># Create the map canvas <br>self.canvas = QgsMapCanvas() <br># Set the background color to light blue something <br>
self.canvas.setCanvasColor(QColor(200,200,255)) <br>self.canvas.enableAntiAliasing(True) <br>self.canvas.useQImageToRender(False) <br>self.canvas.show() <br><br># Lay our widgets out in the main window using a <br># vertical box layout <br>
self.layout = QVBoxLayout(self.frame) <br>self.layout.addWidget(self.canvas) <br><br># Create the actions for our tools and connect each to the appropriate <br># method <br>self.actionAddLayer = QAction(QIcon(&quot;:/foss4g2007/mActionAddLayer.png&quot;), <br>
&quot;Add Layer&quot;, self.frame) <br><br>self.connect(self.actionAddLayer, SIGNAL(&quot;activated()&quot;), self.addLayer) <br>self.actionZoomIn = QAction(QIcon(&quot;:/foss4g2007/mActionZoomIn.png&quot;), &nbsp;&quot;Zoom <br>
In&quot;, self.frame) <br>self.connect(self.actionZoomIn, SIGNAL(&quot;activated()&quot;), self.zoomIn) <br>self.actionZoomOut = QAction(QIcon(&quot;:/foss4g2007/mActionZoomOut.png&quot;), <br>&quot;Zoom Out&quot;, self.frame) <br>
self.connect(self.actionZoomOut, SIGNAL(&quot;activated()&quot;), self.zoomOut) <br>self.actionPan = QAction(QIcon(&quot;:/foss4g2007/mActionPan.png&quot;), &quot;Pan&quot;, <br>self.frame) <br>self.connect(self.actionPan, SIGNAL(&quot;activated()&quot;), self.pan) <br>
self.actionZoomFull = <br>QAction(QIcon(&quot;:/foss4g2007/mActionZoomFullExtent.png&quot;), &quot;Zoom Full Extent&quot;, <br>self.frame) <br>self.connect(self.actionZoomFull, SIGNAL(&quot;activated()&quot;), <br>self.zoomFull) <br>
<br># Create a toolbar <br>self.toolbar = self.addToolBar(&quot;Map&quot;) <br># Add the actions to the toolbar <br>self.toolbar.addAction(self.actionAddLayer) <br>self.toolbar.addAction(self.actionZoomIn) <br>self.toolbar.addAction(self.actionZoomOut); <br>
self.toolbar.addAction(self.actionPan); <br>self.toolbar.addAction(self.actionZoomFull); <br><br># Create the map tools <br>self.toolPan = QgsMapToolPan(self.canvas) <br>self.toolZoomIn = QgsMapToolZoom(self.canvas, False) # false = in <br>
self.toolZoomOut = QgsMapToolZoom(self.canvas, True) # true = out <br># Set the map tool to zoom in <br>def zoomIn(self): <br>&nbsp; self.canvas.setMapTool(self.toolZoomIn) <br><br># Set the map tool to zoom out <br>def zoomOut(self): <br>
&nbsp; self.canvas.setMapTool(self.toolZoomOut) <br><br># Set the map tool to <br>def pan(self): <br>&nbsp; self.canvas.setMapTool(self.toolPan) <br><br># Zoom to full extent of layer <br>def zoomFull(self): <br>&nbsp; self.canvas.zoomFullExtent() <br>
# Add an OGR layer to the map <br>def addLayer(self): <br>&nbsp; file = QFileDialog.getOpenFileName(self, &quot;Open Shapefile&quot;, &quot;.&quot;, <br>&quot;Shapefiles(*.shp)&quot;) <br><br>fileInfo = QFileInfo(file) <br><br>
# Add the layer <br>layer = QgsVectorLayer(file, fileInfo.fileName(), &quot;ogr&quot;) <br><br>#if not layer.isValid(): <br>&nbsp; #return <br><br># Change the color of the layer to gray <br>symbols = layer.renderer().symbols() <br>
symbol = symbols[0] <br>symbol.setFillColor(QColor.fromRgb(192,192,192)) <br><br># Add layer to the registry <br>QgsMapLayerRegistry.instance().addMapLayer(layer); <br><br># Set extent to the extent of our layer <br>self.canvas.setExtent(layer.extent()) <br>
<br># Set up the map canvas layer set <br>cl = QgsMapCanvasLayer(layer) <br>layers = [cl] <br>self.canvas.setLayerSet(layers) <br><br>def main(argv): <br># create Qt application <br>&nbsp; app = QApplication(argv) <br><br># Initialize qgis libraries <br>
QgsApplication.setPrefixPath(qgis_prefix, True) <br>QgsApplication.initQgis() <br><br># create main window <br>wnd = MainWindow() <br><br># Move the app window to upper left <br>wnd.move(100,100) <br>wnd.show() <br><br># run! <br>
retval = app.exec_() <br><br># exit <br>QgsApplication.exitQgis() <br>sys.exit(retval) <br><br><br>if __name__ == &quot;__main__&quot;: <br>&nbsp; main(sys.argv) <br><br><br><br>Previously i was getting the error <br><br>No module named PyQt4.QtCore and PyQt4.QtGui <br>
<br>But after installing the PyQt inside the site package it is not <br>showing any error now. <br><br><br>Now i have started getting the error, <br>qgis. core module not found. <br>qgis.gui module not found. <br><br>I have done whatever way possible from my side. <br>
<br>My system environment is as follows: <br><br>OS -- Windows 2000 <br>Python 2.5 <br>PyQt <a href="http://4.4.3.1">4.4.3.1</a> <br>QGIS <a href="http://0.11.0.2">0.11.0.2</a> <br><br>I dont know in which step i should be installing these one after other. <br>
and also where to install and how to compile <br><br>It will be very kind of you if you can help me out. <br><br>Bye <br>Sonai </div>