尝试使插件在QGIS Dufour中读取shapefile时出错

时间:2013-12-10 17:01:24

标签: python qgis

我尝试使用shapefile中的插件构建器制作插件以阅读QGIS,并尝试在插件中导入pyshp以读取shapefiles但我收到此错误消息< / p>

Traceback (most recent call last):
  File "C:\Users\Mr.Pakde/.qgis2/python/plugins\shpread\shpreaddialog.py", line 42, in baca
    shapefile.Reader("shapefiles/blockgroups")
  File "C:\Users\Mr.Pakde/.qgis2/python/plugins\shpread\shapefile.py", line 220, in __init__
    self.load(args[0])
  File "C:\Users\Mr.Pakde/.qgis2/python/plugins\shpread\shapefile.py", line 253, in load
    raise ShapefileException("Unable to open %s.shp" % shapeName)
ShapefileException: Unable to open shapefiles/blockgroups.shp

Python版本: 2.7.4(默认,2013年4月6日,19:54:46)[MSC v.1500 32位(英特尔)]

这是我使用的代码(我把它放在dialog.py中)

# insert every signal connection here!
        cariButton = self.ui.btnShp
        QtCore.QObject.connect(cariButton, QtCore.SIGNAL('clicked()'),self.baca)

    def baca(self):
        sf = QtGui.QFileDialog.getOpenFileName(self, 'Open File', '*.shp')
        shapefile.Reader("shapefiles/blockgroups")
        shapes = sf.shapes()
        # Read the bounding box from the 4th shape
        shapes[3].bbox
        [-122.485792, 37.786931000000003, -122.446285, 37.811019000000002]
        #  Read the 8th point in the 4th shape
        shapes[3].points[7]
        [-122.471063, 37.787402999999998]

        #panggil isi data
        self.isiDataFile(sf)

    def isiDataFile(self, nmfile):
        #buka dengan open mode baca
        teksFile = open(nmfile, 'r').read()

        self.ui.textShp.setText(teksFile)

有人可以帮助我吗?

0 个答案:

没有答案