Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I hope to create a plugin to do multiple buffers in QGIS. This is my script:

"""/***************************************************************************
 izisse_test
                                 A QGIS plugin
 test of plugin
                              -------------------
        begin                : 2014-06-11
        copyright            : (C) 2014 by Hakima ELCHAHLAFI
        email                : hakima.elchahlafi@gmail.com
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/"""

# Import the PyQt and QGIS libraries
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
# Initialize Qt resources from file resources.py
import resources_rc
# Import the code for the dialog
from izisse_testdialog import izisse_testDialog
import os.path

class izisse_test:

    def __init__(self, iface):
        # Save reference to the QGIS interface
        self.iface = iface
        # initialize plugin directory
        self.plugin_dir = QFileInfo(QgsApplication.qgisUserDbFilePath()).path() + "/python/plugins/izisse_test"
        # initialize locale
        localePath = ""
        locale = QSettings().value("locale/userLocale").toString()[0:2]

        if QFileInfo(self.plugin_dir).exists():
            localePath = self.plugin_dir + "/i18n/izisse_test_" + locale + ".qm"

        if QFileInfo(localePath).exists():
            self.translator = QTranslator()
            self.translator.load(localePath)

            if qVersion() > '4.3.3':
                QCoreApplication.installTranslator(self.translator)

        # Create the dialog (after translation) and keep reference
        self.dlg = izisse_testDialog()

    def initGui(self):
        # Create action that will start plugin configuration
        self.action = QAction(
            QIcon(":/plugins/izisse_test/icon.png"),
            u"...........", self.iface.mainWindow())
        # connect the action to the run method
        QObject.connect(self.action, SIGNAL("triggered()"), self.run)

        # Add toolbar button and menu item
        self.iface.addToolBarIcon(self.action)
        self.iface.addPluginToMenu(u"&izisse", self.action)

    def unload(self):
        # Remove the plugin menu item and icon
        self.iface.removePluginMenu(u"&izisse", self.action)
        self.iface.removeToolBarIcon(self.action)

    # run method that performs all the real work
    def run(self):
        # show the dialog
        self.dlg.show()
        # Run the dialog event loop
        result = self.dlg.exec_()
        # See if OK was pressed
        if result == 1:
            # do something useful (delete the line containing pass and
            # substitute with your code)
            self.one = self.dlg.one.value()
            self.two = self.dlg.two.value()
            self.layer = self.iface.mapCanvas().currentLayer()
            self.selected = self.layer.selectedFeatures()
            self.crs = self.layer.crs()

            ladistance = self.two

            for houba in range(0, self.one):

                # Create a memory layer for storing the results
                resultl = QgsVectorLayer("Polygon?crs=epsg:4326", "result" + str(ladistance), "memory")
            resultl.setCrs(self.crs) 
                resultpr = resultl.dataProvider()

            featuresScaled = []

                for coin in self.selected:
                coin.setGeometry(coin.geometry().buffer(self.distance,5))
                    featuresScaled.append(coin)

                ladistance = ladistance + self.distance

                self.iface.mainWindow().statusBar().showMessage("Adding features to results layer")
                resultpr.addFeatures(featuresScaled)
                QgsMapLayerRegistry.instance().addMapLayer(resultl)

#            self.message = self.nbbufstr + " buffers requested with distance " + self.distancestr + " on the layer " + self.layer.name() + " for " + nbselect + " selected features"


#       QMessageBox.information(self.iface.mainWindow(), QCoreApplication.translate('title', "Info"), QCoreApplication.translate('themessage', self.message))

When I try to in QQGIS like a new plugin i have this message error in line 83

self.one = self.dlg.one.value()
AttributeError: 'izisse_testDialog' object has no attribute 'one'

I'd be thankful if any one can tell what is the problem and how I can solve it. and its my izisse_testdialog script

from PyQt4 import QtCore, QtGui
from ui_izisse_test import Ui_izisse_test
# create the dialog for zoom to point


class izisse_testDialog(QtGui.QDialog):
    def __init__(self):
        QtGui.QDialog.__init__(self)
        # Set up the user interface from Designer.
        self.ui = Ui_izisse_test()
        self.ui.setupUi(self)
share|improve this question

1 Answer 1

If you look at the error you will notice that it occured in your izisse_testDialog file which you did not post.
My guess is that is ether a typo or a missing reference to self.one. By any means this is rather a programming question and not about GIS.

share|improve this answer
    
its my code of izisse_testdialog : from PyQt4 import QtCore, QtGui from ui_izisse_test import Ui_izisse_test # create the dialog for zoom to point class izisse_testDialog(QtGui.QDialog): def __init__(self): QtGui.QDialog.__init__(self) # Set up the user interface from Designer. self.ui = Ui_izisse_test() self.ui.setupUi(self) –  izisse Jun 14 at 12:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.