[Qgis-user] Problems running the python tutorial on osx
Massimo Di Stefano
massimodisasha at yahoo.it
Sat Aug 30 09:02:07 PDT 2008
Hi, i'm tring the python's tutorial
but i can't get it working :-/
i'm on osx (10.5.4 ),
QMake version 2.01a
Using Qt version 4.4.0 in /Library/Frameworks
- qgis builded from svn (revision : 9210)
i downloaded the svn code in :
/GIS/QGIS/qgis_unstable
and configured cmake to build qgis in :
CMAKE_INSTALL_PREFIX /GIS/QGIS/qgis_unstable
these the python QT code i used
(add vector layer example token from the tutorial :
http://mapserver.sk/~wonder/qgis/tutorials.tar.gz )
#####################################################
import sys, os
qgis_prefix = '/GIS/QGIS/QGRASS/qgis1.0.0.app/Contents/MacOS/'
os.environ['QGIS_DEBUG'] = '-1'
sys.path.insert(0, qgis_prefix + '/share/qgis/python')
sys.path.insert(0, 'ui')
from PyQt4 import QtCore, QtGui
from mainwindow_ui import Ui_MainWindow
from qgis.core import *
from qgis.gui import *
class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.setupUi(self)
self.canvas = QgsMapCanvas()
self.canvas.setCanvasColor(QtGui.QColor(255,255,255))
self.canvas.enableAntiAliasing(True)
self.canvas.useQImageToRender(False)
self.canvas.show()
self.layout = QtGui.QVBoxLayout(self.frameMap)
self.layout.addWidget(self.canvas)
self.connect(self.mpActionAddLayer, QtCore.SIGNAL("triggered()"),
self.addLayer)
self.connect(self.mpActionZoomIn, QtCore.SIGNAL("triggered()"),
self.zoomIn)
self.connect(self.mpActionZoomOut, QtCore.SIGNAL("triggered()"),
self.zoomOut)
self.connect(self.mpActionPan, QtCore.SIGNAL("triggered()"),
self.pan)
self.toolbar = self.addToolBar("File");
self.toolbar.addAction(self.mpActionAddLayer);
self.toolbar.addAction(self.mpActionZoomIn);
self.toolbar.addAction(self.mpActionZoomOut);
self.toolbar.addAction(self.mpActionPan);
self.toolPan = QgsMapToolPan(self.canvas)
self.toolPan.setAction(self.mpActionPan)
self.toolZoomIn = QgsMapToolZoom(self.canvas, False) # false = in
self.toolZoomIn.setAction(self.mpActionZoomIn)
self.toolZoomOut = QgsMapToolZoom(self.canvas, True) # true = out
self.toolZoomOut.setAction(self.mpActionZoomOut)
def zoomIn(self):
self.canvas.setMapTool(self.toolZoomIn)
def zoomOut(self):
self.canvas.setMapTool(self.toolZoomOut)
def pan(self):
self.canvas.setMapTool(self.toolPan)
def addLayer(self):
"""add a (hardcoded) layer and zoom to its extent"""
layerPath = "/Users/sasha/Desktop/from-HD/tutorials/data/test.shp"
layerName = "test"
layerProvider = "ogr"
layer = QgsVectorLayer(layerPath, layerName, layerProvider)
print layer
if not layer.isValid():
return
QgsMapLayerRegistry.instance().addMapLayer(layer);
self.canvas.setExtent(layer.extent())
cl = QgsMapCanvasLayer(layer)
layers = [cl]
self.canvas.setLayerSet(layers)
def main(argv):
app = QtGui.QApplication(argv)
QgsApplication.setPrefixPath(qgis_prefix, True)
QgsApplication.initQgis()
wnd = MainWindow()
wnd.show()
retval = app.exec_()
QgsApplication.exitQgis()
sys.exit(retval)
if __name__ == "__main__":
main(sys.argv)
##########################################
tring to run it, i have that the qt application start,
but at its sturtup it put up a log like :
QgsCoordinateReferenceSystem::findMatchingProj will only work if prj
acr ellipsoid acr and proj4string are set!...
tring to add the layer pressing the apposite button, i have :
Failed to load
No valid projection. Unable to set map units.
Failed to load
<qgis.core.QgsVectorLayer object at 0x4786a8>
Failed to load
the line :
<qgis.core.QgsVectorLayer object at 0x4786a8>
is printed out beacouse i added "print layer" at the layer definition :
Please can you help me to see what i'm wrong ?
thanks to all for any suggestion!
regards,
Massimo Di Stefano
(epifanio on irc.freenode.net)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20080830/763f0db6/attachment.html>
More information about the Qgis-user
mailing list