0

In my buffer plugin, i tried the following code

# Get buffer distance and selected city 
dist = float( myLineEdit.text() )
city = myComboBo.currentText()

# Get the feature corresponding to the selected city
expr = QgsExpression('"Cities" = \'' + city + '\'' )
it = myLayer.getFeatures( QgsFeatureRequest( expr ) )
feature = it.next()

# Perform a buffer on the feature geometry
myBufferPolygon = feature.geometry().buffer(dist, 50)

And i had also attached my code which may helps in debugging the error

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

    # Declare instance attributes
    self.actions = []
    self.menu = self.tr(u'&City_searcher_plugin')
    # TODO: We are going to let the user set this up in a future iteration
    self.toolbar = self.iface.addToolBar(u'city_searcher_class')
    self.toolbar.setObjectName(u'city_searcher_class')
    QObject.connect(self.dlg.Statecombo, SIGNAL("currentIndexChanged(int)"), self.findTheCityNames)
    QObject.connect(self.dlg.Citycombo, SIGNAL("currentIndexChanged(int)"), self.calcDistance)
    QObject.connect(self.button_box, QtCore.SIGNAL(_fromUtf8("accepted()")), self.buffer)
    #QObject.connect(self.dlg.browsepushButton, SIGNAL("clicked()"), self.saveTheFile)

 result = self.dlg.exec_()
    # See if OK was pressed
    #if result:
    if result:
        QObject.connect(self.button_box, QtCore.SIGNAL(_fromUtf8("accepted()")), self.buffer)

And my buffer function is

 def buffer(self):
    distance = float( self.dlg.DistancelineEdit.text() )
    #new_distance = distance
    #number = self.dlg.number_buf.value()
    #QgsGeometry.buffer(new_distance , 2)
    city = Citycombo.currentText()
    # Get the feature corresponding to the selected city
    expr = QgsExpression('"name_1" = \'' + city + '\'' )
    it = myLayer.getFeatures( QgsFeatureRequest( expr ) )
    feature = it.next()

    # Perform a buffer on the feature geometry
    myBufferPolygon = feature.geometry().buffer(dist, 50)`

And the error i am getting is attached below enter image description here

And FYI button_box is the name of the OK button in QT Designer.Sorry for the lengthy post.

enter image description here

  • Please, put the complete error message – gene Feb 19 '15 at 17:21
  • Try replacing self.button_box by self.dlg.button_box – Germán Carrillo Feb 20 '15 at 2:34
  • where should I import fromUtf8? it is from qtcore or qtgui? – User123 Feb 20 '15 at 6:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.