[Qgis-developer] qgis+python bindings: failed to load vector
layer
Luca Mandolesi
mandoluca at gmail.com
Mon Aug 6 15:07:47 EDT 2007
Hi,
and thanks a lot for reply. I'm sorry for my many questions but I'm
little "disperate"!
My first problem is how to set under UNIX the LD_LIBRARY_PATH (exist
it, under Mac OS X?!!!).
The code is the same of your 2nd tutorial: 2_basic_main_window, and
I've modified the python path and the qgis_prefix variable.
# Original sources Copyright (c) 2006 by Tim Sutton
#
# ported to Python by Martin Dobias
#
# licensed under the terms of GNU GPL 2
import sys
sys.path.append('/Users/heywoodstock/apps/Contents/MacOS/share/qgis/python/')
from PyQt4 import QtCore, QtGui
from mainwindow_ui import Ui_MainWindow
from qgis.core import *
from qgis.gui import *
import sys
qgis_prefix = "/Users/heywoodstock/apps/Contents/MacOS/"
class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
# required by Qt4 to initialize the UI
self.setupUi(self)
# create map canvas
self.canvas = QgsMapCanvas()
self.canvas.setCanvasColor(QtGui.QColor(255,255,255))
self.canvas.enableAntiAliasing(True)
self.canvas.useQImageToRender(False)
self.canvas.show()
# lay our widgets out in the main window
self.layout = QtGui.QVBoxLayout(self.frameMap)
self.layout.addWidget(self.canvas)
# create the actions behaviours
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)
# create a little toolbar
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);
# create the map tools
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 = "../data/test.shp"
layerName = "test"
layerProvider = "ogr"
# create layer
layer = QgsVectorLayer(layerPath, layerName, layerProvider)
if not layer.isValid():
return
# add layer to the registry
QgsMapLayerRegistry.instance().addMapLayer(layer);
# set extent to the extent of our layer
self.canvas.setExtent(layer.extent())
# set the map canvas layer set
cl = QgsMapCanvasLayer(layer)
layers = [cl]
self.canvas.setLayerSet(layers)
def main(argv):
# create Qt application
app = QtGui.QApplication(argv)
# initialize qgis libraries
QgsApplication.setPrefixPath(qgis_prefix, True)
QgsApplication.initQgis()
# create main window
wnd = MainWindow()
wnd.show()
# run!
retval = app.exec_()
# exit
QgsApplication.exitQgis()
sys.exit(retval)
if __name__ == "__main__":
main(sys.argv)
Also, during the installation I've recived these warning about ld
lybrary and GDAL:
[ 81%] Building CXX object
src/plugins/grid_maker/CMakeFiles/gridmakerplugin.dir/qrc_gridmaker_plugin.o
Linking CXX shared module libgridmakerplugin.so
/usr/bin/ld: warning multiple definitions of symbol _DBFCreate
CMakeFiles/gridmakerplugin.dir/dbfopen.o definition of _DBFCreate in
section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _DBFCreate
/usr/bin/ld: warning multiple definitions of symbol _DBFWriteStringAttribute
CMakeFiles/gridmakerplugin.dir/dbfopen.o definition of
_DBFWriteStringAttribute in section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _DBFWriteStringAttribute
/usr/bin/ld: warning multiple definitions of symbol _DBFWriteNULLAttribute
CMakeFiles/gridmakerplugin.dir/dbfopen.o definition of
_DBFWriteNULLAttribute in section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _DBFWriteNULLAttribute
/usr/bin/ld: warning multiple definitions of symbol _DBFWriteLogicalAttribute
CMakeFiles/gridmakerplugin.dir/dbfopen.o definition of
_DBFWriteLogicalAttribute in section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _DBFWriteLogicalAttribute
/usr/bin/ld: warning multiple definitions of symbol _DBFWriteIntegerAttribute
CMakeFiles/gridmakerplugin.dir/dbfopen.o definition of
_DBFWriteIntegerAttribute in section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _DBFWriteIntegerAttribute
/usr/bin/ld: warning multiple definitions of symbol _DBFClose
CMakeFiles/gridmakerplugin.dir/dbfopen.o definition of _DBFClose in
section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _DBFClose
/usr/bin/ld: warning multiple definitions of symbol _DBFWriteDoubleAttribute
CMakeFiles/gridmakerplugin.dir/dbfopen.o definition of
_DBFWriteDoubleAttribute in section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _DBFWriteDoubleAttribute
/usr/bin/ld: warning multiple definitions of symbol _DBFWriteAttributeDirectly
CMakeFiles/gridmakerplugin.dir/dbfopen.o definition of
_DBFWriteAttributeDirectly in section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _DBFWriteAttributeDirectly
/usr/bin/ld: warning multiple definitions of symbol _DBFUpdateHeader
CMakeFiles/gridmakerplugin.dir/dbfopen.o definition of
_DBFUpdateHeader in section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _DBFUpdateHeader
/usr/bin/ld: warning multiple definitions of symbol _DBFReadTuple
CMakeFiles/gridmakerplugin.dir/dbfopen.o definition of _DBFReadTuple
in section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _DBFReadTuple
/usr/bin/ld: warning multiple definitions of symbol _DBFReadStringAttribute
CMakeFiles/gridmakerplugin.dir/dbfopen.o definition of
_DBFReadStringAttribute in section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _DBFReadStringAttribute
/usr/bin/ld: warning multiple definitions of symbol _DBFReadLogicalAttribute
CMakeFiles/gridmakerplugin.dir/dbfopen.o definition of
_DBFReadLogicalAttribute in section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _DBFReadLogicalAttribute
/usr/bin/ld: warning multiple definitions of symbol _DBFReadIntegerAttribute
CMakeFiles/gridmakerplugin.dir/dbfopen.o definition of
_DBFReadIntegerAttribute in section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _DBFReadIntegerAttribute
/usr/bin/ld: warning multiple definitions of symbol _DBFReadDoubleAttribute
CMakeFiles/gridmakerplugin.dir/dbfopen.o definition of
_DBFReadDoubleAttribute in section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _DBFReadDoubleAttribute
/usr/bin/ld: warning multiple definitions of symbol _DBFOpen
CMakeFiles/gridmakerplugin.dir/dbfopen.o definition of _DBFOpen in
section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _DBFOpen
/usr/bin/ld: warning multiple definitions of symbol _DBFMarkRecordDeleted
CMakeFiles/gridmakerplugin.dir/dbfopen.o definition of
_DBFMarkRecordDeleted in section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _DBFMarkRecordDeleted
/usr/bin/ld: warning multiple definitions of symbol _DBFCloneEmpty
CMakeFiles/gridmakerplugin.dir/dbfopen.o definition of _DBFCloneEmpty
in section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _DBFCloneEmpty
/usr/bin/ld: warning multiple definitions of symbol _DBFAddNativeFieldType
CMakeFiles/gridmakerplugin.dir/dbfopen.o definition of
_DBFAddNativeFieldType in section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _DBFAddNativeFieldType
/usr/bin/ld: warning multiple definitions of symbol _DBFAddField
CMakeFiles/gridmakerplugin.dir/dbfopen.o definition of _DBFAddField in
section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _DBFAddField
/usr/bin/ld: warning multiple definitions of symbol _DBFIsRecordDeleted
CMakeFiles/gridmakerplugin.dir/dbfopen.o definition of
_DBFIsRecordDeleted in section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _DBFIsRecordDeleted
/usr/bin/ld: warning multiple definitions of symbol _DBFIsAttributeNULL
CMakeFiles/gridmakerplugin.dir/dbfopen.o definition of
_DBFIsAttributeNULL in section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _DBFIsAttributeNULL
/usr/bin/ld: warning multiple definitions of symbol _DBFGetRecordCount
CMakeFiles/gridmakerplugin.dir/dbfopen.o definition of
_DBFGetRecordCount in section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _DBFGetRecordCount
/usr/bin/ld: warning multiple definitions of symbol _DBFGetNativeFieldType
CMakeFiles/gridmakerplugin.dir/dbfopen.o definition of
_DBFGetNativeFieldType in section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _DBFGetNativeFieldType
/usr/bin/ld: warning multiple definitions of symbol _DBFGetFieldInfo
CMakeFiles/gridmakerplugin.dir/dbfopen.o definition of
_DBFGetFieldInfo in section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _DBFGetFieldInfo
/usr/bin/ld: warning multiple definitions of symbol _DBFGetFieldIndex
CMakeFiles/gridmakerplugin.dir/dbfopen.o definition of
_DBFGetFieldIndex in section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _DBFGetFieldIndex
/usr/bin/ld: warning multiple definitions of symbol _DBFGetFieldCount
CMakeFiles/gridmakerplugin.dir/dbfopen.o definition of
_DBFGetFieldCount in section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _DBFGetFieldCount
/usr/bin/ld: warning multiple definitions of symbol _DBFWriteTuple
CMakeFiles/gridmakerplugin.dir/dbfopen.o definition of _DBFWriteTuple
in section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _DBFWriteTuple
/usr/bin/ld: warning multiple definitions of symbol _SHPTypeName
CMakeFiles/gridmakerplugin.dir/shpopen.o definition of _SHPTypeName in
section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _SHPTypeName
/usr/bin/ld: warning multiple definitions of symbol _SHPRewindObject
CMakeFiles/gridmakerplugin.dir/shpopen.o definition of
_SHPRewindObject in section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _SHPRewindObject
/usr/bin/ld: warning multiple definitions of symbol _SHPCreateSimpleObject
CMakeFiles/gridmakerplugin.dir/shpopen.o definition of
_SHPCreateSimpleObject in section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _SHPCreateSimpleObject
/usr/bin/ld: warning multiple definitions of symbol _SHPOpen
CMakeFiles/gridmakerplugin.dir/shpopen.o definition of _SHPOpen in
section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _SHPOpen
/usr/bin/ld: warning multiple definitions of symbol _SHPClose
CMakeFiles/gridmakerplugin.dir/shpopen.o definition of _SHPClose in
section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _SHPClose
/usr/bin/ld: warning multiple definitions of symbol _SHPCreateObject
CMakeFiles/gridmakerplugin.dir/shpopen.o definition of
_SHPCreateObject in section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _SHPCreateObject
/usr/bin/ld: warning multiple definitions of symbol _SHPDestroyObject
CMakeFiles/gridmakerplugin.dir/shpopen.o definition of
_SHPDestroyObject in section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _SHPDestroyObject
/usr/bin/ld: warning multiple definitions of symbol _SHPGetInfo
CMakeFiles/gridmakerplugin.dir/shpopen.o definition of _SHPGetInfo in
section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _SHPGetInfo
/usr/bin/ld: warning multiple definitions of symbol _SHPReadObject
CMakeFiles/gridmakerplugin.dir/shpopen.o definition of _SHPReadObject
in section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _SHPReadObject
/usr/bin/ld: warning multiple definitions of symbol _SHPCreate
CMakeFiles/gridmakerplugin.dir/shpopen.o definition of _SHPCreate in
section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _SHPCreate
/usr/bin/ld: warning multiple definitions of symbol _SHPWriteHeader
CMakeFiles/gridmakerplugin.dir/shpopen.o definition of _SHPWriteHeader
in section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _SHPWriteHeader
/usr/bin/ld: warning multiple definitions of symbol _SHPWriteObject
CMakeFiles/gridmakerplugin.dir/shpopen.o definition of _SHPWriteObject
in section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _SHPWriteObject
/usr/bin/ld: warning multiple definitions of symbol _SHPComputeExtents
CMakeFiles/gridmakerplugin.dir/shpopen.o definition of
_SHPComputeExtents in section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _SHPComputeExtents
/usr/bin/ld: warning multiple definitions of symbol _SHPPartTypeName
CMakeFiles/gridmakerplugin.dir/shpopen.o definition of
_SHPPartTypeName in section (__TEXT,__text)
/Library/Frameworks/GDAL.framework/unix/lib/libgdal.dylib(single
module) definition of _SHPPartTypeName
I guess that it's here my problem!
Thank you very very much and compliments for your good job with qgis
and python bindings!!! I'm enthusiastic for this!!!
bye bye
More information about the Qgis-developer
mailing list